mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 00:06:06 +08:00
feat(babel6): Fix spread operator
This commit is contained in:
parent
8f4e30329c
commit
e717a44581
|
@ -1,98 +1,101 @@
|
|||
import React from 'react';
|
||||
import {DraftStore, Actions, Utils} from 'nylas-exports';
|
||||
|
||||
export default ComposedComponent => class extends React.Component {
|
||||
static displayName = ComposedComponent.displayName;
|
||||
static propTypes = {
|
||||
draftClientId: React.PropTypes.string,
|
||||
onDraftReady: React.PropTypes.func,
|
||||
}
|
||||
static defaultProps = {
|
||||
onDraftReady: () => {},
|
||||
}
|
||||
static containerRequired = false;
|
||||
function InflateDraftClientId(ComposedComponent) {
|
||||
return class extends React.Component {
|
||||
static displayName = ComposedComponent.displayName;
|
||||
static propTypes = {
|
||||
draftClientId: React.PropTypes.string,
|
||||
onDraftReady: React.PropTypes.func,
|
||||
}
|
||||
static defaultProps = {
|
||||
onDraftReady: () => {},
|
||||
}
|
||||
static containerRequired = false;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
session: null,
|
||||
draft: null,
|
||||
};
|
||||
}
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
session: null,
|
||||
draft: null,
|
||||
};
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
this._unmounted = false;
|
||||
this._prepareForDraft(this.props.draftClientId);
|
||||
}
|
||||
componentWillMount() {
|
||||
this._unmounted = false;
|
||||
this._prepareForDraft(this.props.draftClientId);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this._unmounted = true;
|
||||
this._teardownForDraft();
|
||||
this._deleteDraftIfEmpty();
|
||||
}
|
||||
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.draftClientId !== this.props.draftClientId) {
|
||||
componentWillUnmount() {
|
||||
this._unmounted = true;
|
||||
this._teardownForDraft();
|
||||
this._prepareForDraft(newProps.draftClientId);
|
||||
this._deleteDraftIfEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
_prepareForDraft(draftClientId) {
|
||||
if (!draftClientId) {
|
||||
return;
|
||||
componentWillReceiveProps(newProps) {
|
||||
if (newProps.draftClientId !== this.props.draftClientId) {
|
||||
this._teardownForDraft();
|
||||
this._prepareForDraft(newProps.draftClientId);
|
||||
}
|
||||
}
|
||||
DraftStore.sessionForClientId(draftClientId).then((session) => {
|
||||
if (this._unmounted) {
|
||||
|
||||
_prepareForDraft(draftClientId) {
|
||||
if (!draftClientId) {
|
||||
return;
|
||||
}
|
||||
if (session.draftClientId !== this.props.draftClientId) {
|
||||
DraftStore.sessionForClientId(draftClientId).then((session) => {
|
||||
if (this._unmounted) {
|
||||
return;
|
||||
}
|
||||
if (session.draftClientId !== this.props.draftClientId) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._sessionUnlisten = session.listen(() => {
|
||||
this.setState({draft: session.draft()});
|
||||
});
|
||||
|
||||
this.setState({
|
||||
session: session,
|
||||
draft: session.draft(),
|
||||
});
|
||||
this.props.onDraftReady()
|
||||
});
|
||||
}
|
||||
|
||||
_teardownForDraft() {
|
||||
if (this.state.session) {
|
||||
this.state.session.changes.commit();
|
||||
}
|
||||
if (this._sessionUnlisten) {
|
||||
this._sessionUnlisten();
|
||||
}
|
||||
}
|
||||
|
||||
_deleteDraftIfEmpty() {
|
||||
if (!this.state.draft) {
|
||||
return;
|
||||
}
|
||||
if (this.state.draft.pristine) {
|
||||
Actions.destroyDraft(this.props.draftClientId);
|
||||
}
|
||||
}
|
||||
|
||||
this._sessionUnlisten = session.listen(() => {
|
||||
this.setState({draft: session.draft()});
|
||||
// Returns a promise for use in composer/main.es6, to show the window
|
||||
// once the composer is rendered and focused.
|
||||
focus() {
|
||||
return Utils.waitFor(() => this.refs.composed).then(() =>
|
||||
this.refs.composed.focus()
|
||||
).catch(() => {
|
||||
});
|
||||
|
||||
this.setState({
|
||||
session: session,
|
||||
draft: session.draft(),
|
||||
});
|
||||
this.props.onDraftReady()
|
||||
});
|
||||
}
|
||||
|
||||
_teardownForDraft() {
|
||||
if (this.state.session) {
|
||||
this.state.session.changes.commit();
|
||||
}
|
||||
if (this._sessionUnlisten) {
|
||||
this._sessionUnlisten();
|
||||
}
|
||||
}
|
||||
|
||||
_deleteDraftIfEmpty() {
|
||||
if (!this.state.draft) {
|
||||
return;
|
||||
render() {
|
||||
if (!this.state.draft) {
|
||||
return <span/>;
|
||||
}
|
||||
return <ComposedComponent ref="composed" {...this.props} {...this.state} />;
|
||||
}
|
||||
if (this.state.draft.pristine) {
|
||||
Actions.destroyDraft(this.props.draftClientId);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a promise for use in composer/main.es6, to show the window
|
||||
// once the composer is rendered and focused.
|
||||
focus() {
|
||||
return Utils.waitFor(() => this.refs.composed).then(() =>
|
||||
this.refs.composed.focus()
|
||||
).catch(() => {
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.state.draft) {
|
||||
return <span/>;
|
||||
}
|
||||
return <ComposedComponent ref="composed" {...this.props} {...this.state} />;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
export default InflateDraftClientId
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
import React, {Component} from 'react';
|
||||
|
||||
export default (ComposedComponent, {stores, getStateFromStores}) => class extends Component {
|
||||
static displayName = ComposedComponent.displayName;
|
||||
|
||||
static containerRequired = false;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this._unlisteners = [];
|
||||
this.state = getStateFromStores(props);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
stores.forEach((store) => {
|
||||
this._unlisteners.push(store.listen(() => {
|
||||
this.setState(getStateFromStores(this.props));
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.setState(getStateFromStores(nextProps));
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
for (const unlisten of this._unlisteners) {
|
||||
unlisten();
|
||||
}
|
||||
this._unlisteners = [];
|
||||
}
|
||||
|
||||
render() {
|
||||
return <ComposedComponent {...this.props} {...this.state} />;
|
||||
}
|
||||
};
|
40
src/components/decorators/listens-to-flux-store.jsx
Normal file
40
src/components/decorators/listens-to-flux-store.jsx
Normal file
|
@ -0,0 +1,40 @@
|
|||
import React, {Component} from 'react';
|
||||
|
||||
function ListensToFluxStore(ComposedComponent, {stores, getStateFromStores}) {
|
||||
return class extends Component {
|
||||
static displayName = ComposedComponent.displayName;
|
||||
|
||||
static containerRequired = false;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this._unlisteners = [];
|
||||
this.state = getStateFromStores(props);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
stores.forEach((store) => {
|
||||
this._unlisteners.push(store.listen(() => {
|
||||
this.setState(getStateFromStores(this.props));
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.setState(getStateFromStores(nextProps));
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
for (const unlisten of this._unlisteners) {
|
||||
unlisten();
|
||||
}
|
||||
this._unlisteners = [];
|
||||
}
|
||||
|
||||
render() {
|
||||
return <ComposedComponent {...this.props} {...this.state} />;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default ListensToFluxStore
|
|
@ -2,6 +2,7 @@ import RegExpUtils from '../regexp-utils';
|
|||
|
||||
export function getFunctionArgs(func) {
|
||||
const match = func.toString().match(RegExpUtils.functionArgs());
|
||||
if (!match) return null;
|
||||
return match[1].split(/\s*,\s*/);
|
||||
if (!match) return [[]];
|
||||
const matchStr = match[1] || match[2]
|
||||
return matchStr.split(/\s*,\s*/);
|
||||
}
|
||||
|
|
|
@ -158,8 +158,8 @@ RegExpUtils =
|
|||
looseStyleTag: -> /<style/gim
|
||||
|
||||
# Regular expression matching javasript function arguments:
|
||||
# https://regex101.com/r/pZ6zF0/1
|
||||
functionArgs: -> /\(\s*([^)]+?)\s*\)/
|
||||
# https://regex101.com/r/pZ6zF0/2
|
||||
functionArgs: -> /(?:\(\s*([^)]+?)\s*\)|(\w+)\s?=>)/
|
||||
|
||||
illegalPathCharactersRegexp: ->
|
||||
#https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
|
||||
|
|
Loading…
Reference in a new issue