diff --git a/internal_packages/composer/lib/decorators/inflate-draft-client-id.es6 b/internal_packages/composer/lib/decorators/inflate-draft-client-id.es6
index 22d23b8b3..f0342700f 100644
--- a/internal_packages/composer/lib/decorators/inflate-draft-client-id.es6
+++ b/internal_packages/composer/lib/decorators/inflate-draft-client-id.es6
@@ -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 ;
+ }
+ return ;
}
- 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 ;
- }
- return ;
- }
-};
+ };
+}
+export default InflateDraftClientId
diff --git a/src/components/decorators/listens-to-flux-store.es6 b/src/components/decorators/listens-to-flux-store.es6
deleted file mode 100644
index 59fc1af61..000000000
--- a/src/components/decorators/listens-to-flux-store.es6
+++ /dev/null
@@ -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 ;
- }
-};
diff --git a/src/components/decorators/listens-to-flux-store.jsx b/src/components/decorators/listens-to-flux-store.jsx
new file mode 100644
index 000000000..76c9d8b72
--- /dev/null
+++ b/src/components/decorators/listens-to-flux-store.jsx
@@ -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 ;
+ }
+ };
+}
+
+export default ListensToFluxStore
diff --git a/src/extensions/extension-utils.es6 b/src/extensions/extension-utils.es6
index 4c86292a7..3aebea869 100644
--- a/src/extensions/extension-utils.es6
+++ b/src/extensions/extension-utils.es6
@@ -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*/);
}
diff --git a/src/regexp-utils.coffee b/src/regexp-utils.coffee
index 3e0f7aba7..5d0c1a692 100644
--- a/src/regexp-utils.coffee
+++ b/src/regexp-utils.coffee
@@ -158,8 +158,8 @@ RegExpUtils =
looseStyleTag: -> /