Skip to content

Commit 50f8cfd

Browse files
authoredAug 15, 2017
Merge pull request #1 from lexiv0re/fix-react-deprectation-warning
Fixed react reprecation warning, added lib to the repo
2 parents e0bcb94 + b3ddb19 commit 50f8cfd

6 files changed

+185
-51
lines changed
 

‎.eslintrc

-3
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@
150150
"no-inline-comments": 2,
151151
"no-lonely-if": 2,
152152
"no-mixed-spaces-and-tabs": 2,
153-
"no-multiple-empty-lines": [1, {
154-
"max": 2
155-
}],
156153
"no-ternary": 0,
157154
"operator-assignment": 0,
158155
"quote-props": [2, "as-needed"],

‎.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ coverage
33
node_modules
44
npm-debug.log
55
test/browser/tests.js
6-
lib
76
utils/*
87
flux.js
98
flux-build.js
109
flux-build.min.js
10+
.idea

‎dist/connectToStores.js

+62-38
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,31 @@ return /******/ (function(modules) { // webpackBootstrap
5252
/************************************************************************/
5353
/******/ ([
5454
/* 0 */
55-
/***/ function(module, exports, __webpack_require__) {
55+
/***/ (function(module, exports, __webpack_require__) {
5656

5757
module.exports = __webpack_require__(1);
5858

5959

60-
/***/ },
60+
/***/ }),
6161
/* 1 */
62-
/***/ function(module, exports, __webpack_require__) {
62+
/***/ (function(module, exports, __webpack_require__) {
6363

6464
'use strict';
6565

6666
Object.defineProperty(exports, '__esModule', {
6767
value: true
6868
});
6969

70+
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
71+
72+
var _get = function get(_x2, _x3, _x4) { var _again = true; _function: while (_again) { var object = _x2, property = _x3, receiver = _x4; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x2 = parent; _x3 = property; _x4 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
73+
7074
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
7175

76+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
77+
78+
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
79+
7280
var _react = __webpack_require__(2);
7381

7482
var _react2 = _interopRequireDefault(_react);
@@ -106,43 +114,59 @@ return /******/ (function(modules) { // webpackBootstrap
106114
throw new Error('connectToStores() expects the wrapped component to have a static getPropsFromStores() method');
107115
}
108116

109-
var StoreConnection = _react2['default'].createClass({
110-
displayName: 'StoreConnection',
117+
var StoreConnection = (function (_React$Component) {
118+
function StoreConnection() {
119+
_classCallCheck(this, StoreConnection);
111120

112-
getInitialState: function getInitialState() {
113-
return Spec.getPropsFromStores(this.props, this.context);
114-
},
115-
116-
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
117-
this.setState(Spec.getPropsFromStores(nextProps, this.context));
118-
},
121+
_get(Object.getPrototypeOf(StoreConnection.prototype), 'constructor', this).apply(this, arguments);
122+
}
119123

120-
componentDidMount: function componentDidMount() {
121-
var _this = this;
124+
_inherits(StoreConnection, _React$Component);
122125

123-
var stores = Spec.getStores(this.props, this.context);
124-
this.storeListeners = stores.map(function (store) {
125-
return store.listen(_this.onChange);
126-
});
127-
if (Spec.componentDidConnect) {
128-
Spec.componentDidConnect(this.props, this.context);
126+
_createClass(StoreConnection, [{
127+
key: 'getInitialState',
128+
value: function getInitialState() {
129+
return Spec.getPropsFromStores(this.props, this.context);
129130
}
130-
},
131-
132-
componentWillUnmount: function componentWillUnmount() {
133-
this.storeListeners.forEach(function (unlisten) {
134-
return unlisten();
135-
});
136-
},
137-
138-
onChange: function onChange() {
139-
this.setState(Spec.getPropsFromStores(this.props, this.context));
140-
},
131+
}, {
132+
key: 'componentWillReceiveProps',
133+
value: function componentWillReceiveProps(nextProps) {
134+
this.setState(Spec.getPropsFromStores(nextProps, this.context));
135+
}
136+
}, {
137+
key: 'componentDidMount',
138+
value: function componentDidMount() {
139+
var _this = this;
140+
141+
var stores = Spec.getStores(this.props, this.context);
142+
this.storeListeners = stores.map(function (store) {
143+
return store.listen(_this.onChange);
144+
});
145+
if (Spec.componentDidConnect) {
146+
Spec.componentDidConnect(this.props, this.context);
147+
}
148+
}
149+
}, {
150+
key: 'componentWillUnmount',
151+
value: function componentWillUnmount() {
152+
this.storeListeners.forEach(function (unlisten) {
153+
return unlisten();
154+
});
155+
}
156+
}, {
157+
key: 'onChange',
158+
value: function onChange() {
159+
this.setState(Spec.getPropsFromStores(this.props, this.context));
160+
}
161+
}, {
162+
key: 'render',
163+
value: function render() {
164+
return _react2['default'].createElement(Component, assign({}, this.props, this.state));
165+
}
166+
}]);
141167

142-
render: function render() {
143-
return _react2['default'].createElement(Component, assign({}, this.props, this.state));
144-
}
145-
});
168+
return StoreConnection;
169+
})(_react2['default'].Component);
146170

147171
return StoreConnection;
148172
})();
@@ -151,13 +175,13 @@ return /******/ (function(modules) { // webpackBootstrap
151175
exports['default'] = connectToStores;
152176
module.exports = exports['default'];
153177

154-
/***/ },
178+
/***/ }),
155179
/* 2 */
156-
/***/ function(module, exports) {
180+
/***/ (function(module, exports) {
157181

158182
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
159183

160-
/***/ }
184+
/***/ })
161185
/******/ ])
162186
});
163187
;

‎dist/connectToStores.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/connectToStores.js

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, '__esModule', {
4+
value: true
5+
});
6+
7+
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
8+
9+
var _get = function get(_x2, _x3, _x4) { var _again = true; _function: while (_again) { var object = _x2, property = _x3, receiver = _x4; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x2 = parent; _x3 = property; _x4 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
10+
11+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
12+
13+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
14+
15+
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
16+
17+
var _react = require('react');
18+
19+
var _react2 = _interopRequireDefault(_react);
20+
21+
// @todo Where to get these from?
22+
var isFunction = function isFunction(x) {
23+
return typeof x === 'function';
24+
};
25+
var eachObject = function eachObject(f, o) {
26+
o.forEach(function (from) {
27+
Object.keys(Object(from)).forEach(function (key) {
28+
f(key, from[key]);
29+
});
30+
});
31+
};
32+
var assign = function assign(target) {
33+
for (var _len = arguments.length, source = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
34+
source[_key - 1] = arguments[_key];
35+
}
36+
37+
eachObject(function (key, value) {
38+
return target[key] = value;
39+
}, source);
40+
return target;
41+
};
42+
43+
function connectToStores(Spec) {
44+
var Component = arguments[1] === undefined ? Spec : arguments[1];
45+
return (function () {
46+
// Check for required static methods.
47+
if (!isFunction(Spec.getStores)) {
48+
throw new Error('connectToStores() expects the wrapped component to have a static getStores() method');
49+
}
50+
if (!isFunction(Spec.getPropsFromStores)) {
51+
throw new Error('connectToStores() expects the wrapped component to have a static getPropsFromStores() method');
52+
}
53+
54+
var StoreConnection = (function (_React$Component) {
55+
function StoreConnection() {
56+
_classCallCheck(this, StoreConnection);
57+
58+
_get(Object.getPrototypeOf(StoreConnection.prototype), 'constructor', this).apply(this, arguments);
59+
}
60+
61+
_inherits(StoreConnection, _React$Component);
62+
63+
_createClass(StoreConnection, [{
64+
key: 'getInitialState',
65+
value: function getInitialState() {
66+
return Spec.getPropsFromStores(this.props, this.context);
67+
}
68+
}, {
69+
key: 'componentWillReceiveProps',
70+
value: function componentWillReceiveProps(nextProps) {
71+
this.setState(Spec.getPropsFromStores(nextProps, this.context));
72+
}
73+
}, {
74+
key: 'componentDidMount',
75+
value: function componentDidMount() {
76+
var _this = this;
77+
78+
var stores = Spec.getStores(this.props, this.context);
79+
this.storeListeners = stores.map(function (store) {
80+
return store.listen(_this.onChange);
81+
});
82+
if (Spec.componentDidConnect) {
83+
Spec.componentDidConnect(this.props, this.context);
84+
}
85+
}
86+
}, {
87+
key: 'componentWillUnmount',
88+
value: function componentWillUnmount() {
89+
this.storeListeners.forEach(function (unlisten) {
90+
return unlisten();
91+
});
92+
}
93+
}, {
94+
key: 'onChange',
95+
value: function onChange() {
96+
this.setState(Spec.getPropsFromStores(this.props, this.context));
97+
}
98+
}, {
99+
key: 'render',
100+
value: function render() {
101+
return _react2['default'].createElement(Component, assign({}, this.props, this.state));
102+
}
103+
}]);
104+
105+
return StoreConnection;
106+
})(_react2['default'].Component);
107+
108+
return StoreConnection;
109+
})();
110+
}
111+
112+
exports['default'] = connectToStores;
113+
module.exports = exports['default'];

‎src/connectToStores.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ function connectToStores(Spec, Component = Spec) {
2323
throw new Error('connectToStores() expects the wrapped component to have a static getPropsFromStores() method')
2424
}
2525

26-
const StoreConnection = React.createClass({
26+
const StoreConnection = class StoreConnection extends React.Component {
2727
getInitialState() {
2828
return Spec.getPropsFromStores(this.props, this.context)
29-
},
29+
}
3030

3131
componentWillReceiveProps(nextProps) {
3232
this.setState(Spec.getPropsFromStores(nextProps, this.context))
33-
},
33+
}
3434

3535
componentDidMount() {
3636
const stores = Spec.getStores(this.props, this.context)
@@ -40,25 +40,25 @@ function connectToStores(Spec, Component = Spec) {
4040
if (Spec.componentDidConnect) {
4141
Spec.componentDidConnect(this.props, this.context)
4242
}
43-
},
43+
}
4444

4545
componentWillUnmount() {
4646
this.storeListeners.forEach(unlisten => unlisten())
47-
},
47+
}
4848

4949
onChange() {
5050
this.setState(Spec.getPropsFromStores(this.props, this.context))
51-
},
51+
}
5252

5353
render() {
5454
return React.createElement(
5555
Component,
5656
assign({}, this.props, this.state)
5757
)
5858
}
59-
})
59+
}
6060

61-
return StoreConnection
61+
return StoreConnection;
6262
}
6363

6464
export default connectToStores

0 commit comments

Comments
 (0)
Please sign in to comment.