From 7805cb6e919c73c3255f9bd72f5460349e54bb79 Mon Sep 17 00:00:00 2001 From: Miguel Espinoza Date: Fri, 16 Jun 2017 09:49:42 -0400 Subject: [PATCH 1/4] refactored React.createClass to createReactClass package --- package.json | 1 + src/connectToStores.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 230ecff..517b670 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "browserify": "^10.2.6", "chai": "^2.3.0", "coveralls": "^2.11.2", + "create-react-class": "^15.6.0", "envify": "^3.4.0", "es6-promise": "^2.1.1", "eslint": "^0.24.0", diff --git a/src/connectToStores.js b/src/connectToStores.js index 1564155..81f8364 100644 --- a/src/connectToStores.js +++ b/src/connectToStores.js @@ -1,4 +1,5 @@ import React from 'react' +import createReactClass from 'create-react-class'; // @todo Where to get these from? const isFunction = x => typeof x === 'function' @@ -23,7 +24,7 @@ function connectToStores(Spec, Component = Spec) { throw new Error('connectToStores() expects the wrapped component to have a static getPropsFromStores() method') } - const StoreConnection = React.createClass({ + const StoreConnection = createReactClass({ getInitialState() { return Spec.getPropsFromStores(this.props, this.context) }, From 46396c500673bdf00d76f091dfaca136c7a28a34 Mon Sep 17 00:00:00 2001 From: Miguel Espinoza Date: Fri, 16 Jun 2017 10:40:18 -0400 Subject: [PATCH 2/4] add lib directory for bypassing npm --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 37ec947..d68a540 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ coverage node_modules npm-debug.log test/browser/tests.js -lib utils/* flux.js flux-build.js From d66892549477bd68a0746da1408e51dfa12cad19 Mon Sep 17 00:00:00 2001 From: Miguel Espinoza Date: Fri, 16 Jun 2017 10:40:24 -0400 Subject: [PATCH 3/4] add lib directory for bypassing npm --- lib/connectToStores.js | 91 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 lib/connectToStores.js diff --git a/lib/connectToStores.js b/lib/connectToStores.js new file mode 100644 index 0000000..b95df71 --- /dev/null +++ b/lib/connectToStores.js @@ -0,0 +1,91 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var _createReactClass = require('create-react-class'); + +var _createReactClass2 = _interopRequireDefault(_createReactClass); + +// @todo Where to get these from? +var isFunction = function isFunction(x) { + return typeof x === 'function'; +}; +var eachObject = function eachObject(f, o) { + o.forEach(function (from) { + Object.keys(Object(from)).forEach(function (key) { + f(key, from[key]); + }); + }); +}; +var assign = function assign(target) { + for (var _len = arguments.length, source = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + source[_key - 1] = arguments[_key]; + } + + eachObject(function (key, value) { + return target[key] = value; + }, source); + return target; +}; + +function connectToStores(Spec) { + var Component = arguments[1] === undefined ? Spec : arguments[1]; + return (function () { + // Check for required static methods. + if (!isFunction(Spec.getStores)) { + throw new Error('connectToStores() expects the wrapped component to have a static getStores() method'); + } + if (!isFunction(Spec.getPropsFromStores)) { + throw new Error('connectToStores() expects the wrapped component to have a static getPropsFromStores() method'); + } + + var StoreConnection = (0, _createReactClass2['default'])({ + getInitialState: function getInitialState() { + return Spec.getPropsFromStores(this.props, this.context); + }, + + componentWillReceiveProps: function componentWillReceiveProps(nextProps) { + this.setState(Spec.getPropsFromStores(nextProps, this.context)); + }, + + componentDidMount: function componentDidMount() { + var _this = this; + + var stores = Spec.getStores(this.props, this.context); + this.storeListeners = stores.map(function (store) { + return store.listen(_this.onChange); + }); + if (Spec.componentDidConnect) { + Spec.componentDidConnect(this.props, this.context); + } + }, + + componentWillUnmount: function componentWillUnmount() { + this.storeListeners.forEach(function (unlisten) { + return unlisten(); + }); + }, + + onChange: function onChange() { + this.setState(Spec.getPropsFromStores(this.props, this.context)); + }, + + render: function render() { + return _react2['default'].createElement(Component, assign({}, this.props, this.state)); + } + }); + + return StoreConnection; + })(); +} + +exports['default'] = connectToStores; +module.exports = exports['default']; \ No newline at end of file From ab8d7025b4889adf5a06c6d2175e25d0500aa76b Mon Sep 17 00:00:00 2001 From: Miguel Espinoza Date: Fri, 16 Jun 2017 14:40:11 -0400 Subject: [PATCH 4/4] removed lib directory from git --- .gitignore | 1 + lib/connectToStores.js | 91 ------------------------------------------ 2 files changed, 1 insertion(+), 91 deletions(-) delete mode 100644 lib/connectToStores.js diff --git a/.gitignore b/.gitignore index d68a540..37ec947 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ coverage node_modules npm-debug.log test/browser/tests.js +lib utils/* flux.js flux-build.js diff --git a/lib/connectToStores.js b/lib/connectToStores.js deleted file mode 100644 index b95df71..0000000 --- a/lib/connectToStores.js +++ /dev/null @@ -1,91 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _react = require('react'); - -var _react2 = _interopRequireDefault(_react); - -var _createReactClass = require('create-react-class'); - -var _createReactClass2 = _interopRequireDefault(_createReactClass); - -// @todo Where to get these from? -var isFunction = function isFunction(x) { - return typeof x === 'function'; -}; -var eachObject = function eachObject(f, o) { - o.forEach(function (from) { - Object.keys(Object(from)).forEach(function (key) { - f(key, from[key]); - }); - }); -}; -var assign = function assign(target) { - for (var _len = arguments.length, source = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - source[_key - 1] = arguments[_key]; - } - - eachObject(function (key, value) { - return target[key] = value; - }, source); - return target; -}; - -function connectToStores(Spec) { - var Component = arguments[1] === undefined ? Spec : arguments[1]; - return (function () { - // Check for required static methods. - if (!isFunction(Spec.getStores)) { - throw new Error('connectToStores() expects the wrapped component to have a static getStores() method'); - } - if (!isFunction(Spec.getPropsFromStores)) { - throw new Error('connectToStores() expects the wrapped component to have a static getPropsFromStores() method'); - } - - var StoreConnection = (0, _createReactClass2['default'])({ - getInitialState: function getInitialState() { - return Spec.getPropsFromStores(this.props, this.context); - }, - - componentWillReceiveProps: function componentWillReceiveProps(nextProps) { - this.setState(Spec.getPropsFromStores(nextProps, this.context)); - }, - - componentDidMount: function componentDidMount() { - var _this = this; - - var stores = Spec.getStores(this.props, this.context); - this.storeListeners = stores.map(function (store) { - return store.listen(_this.onChange); - }); - if (Spec.componentDidConnect) { - Spec.componentDidConnect(this.props, this.context); - } - }, - - componentWillUnmount: function componentWillUnmount() { - this.storeListeners.forEach(function (unlisten) { - return unlisten(); - }); - }, - - onChange: function onChange() { - this.setState(Spec.getPropsFromStores(this.props, this.context)); - }, - - render: function render() { - return _react2['default'].createElement(Component, assign({}, this.props, this.state)); - } - }); - - return StoreConnection; - })(); -} - -exports['default'] = connectToStores; -module.exports = exports['default']; \ No newline at end of file