Skip to content

Commit

Permalink
Passing context into connectToStores methods
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Jun 7, 2015
1 parent 464bb26 commit 7cf737d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 38 deletions.
66 changes: 35 additions & 31 deletions dist/alt-with-addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module.exports = require('./components/AltContainer.js');

},{"./components/AltContainer.js":2}],2:[function(require,module,exports){
(function (global){
/**
* AltContainer.
*
Expand Down Expand Up @@ -62,7 +63,7 @@ module.exports = require('./components/AltContainer.js');
*/
'use strict';

var React = (window.React);
var React = (typeof window !== "undefined" ? window.React : typeof global !== "undefined" ? global.React : null);
var mixinContainer = require('./mixinContainer');
var assign = require('../utils/functions').assign;

Expand All @@ -76,6 +77,7 @@ var AltContainer = React.createClass(assign({

module.exports = AltContainer;

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"../utils/functions":27,"./mixinContainer":3}],3:[function(require,module,exports){
'use strict';

Expand Down Expand Up @@ -1496,6 +1498,7 @@ var AltStore = (function () {
}, {
key: 'unlisten',
value: function unlisten(cb) {
if (!cb) throw new TypeError('Unlisten must receive a function');
this[Sym.LIFECYCLE].emit('unlisten');
this[EE].removeListener('change', cb);
}
Expand Down Expand Up @@ -1958,7 +1961,6 @@ var STATE_CONTAINER = (0, _esSymbol2['default'])();
exports.STATE_CONTAINER = STATE_CONTAINER;

},{"es-symbol":5}],16:[function(require,module,exports){
/* istanbul ignore next */
'use strict';

Object.defineProperty(exports, '__esModule', {
Expand All @@ -1969,6 +1971,7 @@ exports.warn = warn;
exports.uid = uid;
exports.formatAsConstant = formatAsConstant;
exports.dispatchIdentity = dispatchIdentity;
/* istanbul ignore next */
function NoopClass() {}

var builtIns = Object.getOwnPropertyNames(NoopClass);
Expand Down Expand Up @@ -2162,6 +2165,16 @@ exports['default'] = ActionListeners;
module.exports = exports['default'];

},{"es-symbol":5}],19:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});

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; }; })();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

/**
* AltManager(Alt: AltClass): undefined
*
Expand All @@ -2188,16 +2201,6 @@ module.exports = exports['default'];
* ```
*/

'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});

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; }; })();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

var AltManager = (function () {
function AltManager(Alt) {
_classCallCheck(this, AltManager);
Expand Down Expand Up @@ -2493,12 +2496,12 @@ function atomic(alt) {
module.exports = exports['default'];

},{"./functions":24,"./makeFinalStore":25}],22:[function(require,module,exports){
/*global window*/
'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});
/*global window*/
exports['default'] = chromeDebug;

function chromeDebug(alt) {
Expand All @@ -2509,6 +2512,7 @@ function chromeDebug(alt) {
module.exports = exports['default'];

},{}],23:[function(require,module,exports){
(function (global){
/**
* 'Higher Order Component' that controls the props of a wrapped
* component via stores.
Expand Down Expand Up @@ -2562,7 +2566,7 @@ Object.defineProperty(exports, '__esModule', {

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _react = (window.React);
var _react = (typeof window !== "undefined" ? window.React : typeof global !== "undefined" ? global.React : null);

var _react2 = _interopRequireDefault(_react);

Expand All @@ -2582,39 +2586,36 @@ function connectToStores(Component) {
displayName: 'StoreConnection',

getInitialState: function getInitialState() {
return Component.getPropsFromStores(this.props);
return Component.getPropsFromStores(this.props, this.context);
},

componentDidMount: function componentDidMount() {
var _this = this;

var stores = Component.getStores(this.props);
var stores = Component.getStores(this.props, this.context);
stores.forEach(function (store) {
store.listen(_this.onChange);
});
var component = this.refs['connectToStores-component'];
if (typeof component.componentDidConnect === 'function') {
component.componentDidConnect();
if (Component.componentDidConnect) {
Component.componentDidConnect(this.props, this.context);
}
},

componentWillUnmount: function componentWillUnmount() {
var _this2 = this;

var stores = Component.getStores(this.props);
var stores = Component.getStores(this.props, this.context);
stores.forEach(function (store) {
store.unlisten(_this2.onChange);
});
},

onChange: function onChange() {
this.setState(Component.getPropsFromStores(this.props));
this.setState(Component.getPropsFromStores(this.props, this.context));
},

render: function render() {
return _react2['default'].createElement(Component, (0, _functions.assign)({
ref: 'connectToStores-component'
}, this.props, this.state));
return _react2['default'].createElement(Component, (0, _functions.assign)({}, this.props, this.state));
}
});

Expand All @@ -2624,6 +2625,7 @@ function connectToStores(Component) {
exports['default'] = connectToStores;
module.exports = exports['default'];

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./functions":24}],24:[function(require,module,exports){
'use strict';

Expand Down Expand Up @@ -2658,6 +2660,12 @@ function assign(target) {
}

},{}],25:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = makeFinalStore;
/**
* makeFinalStore(alt: AltInstance): AltStore
*
Expand All @@ -2682,12 +2690,6 @@ function assign(target) {
* ```
*/

"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = makeFinalStore;
function FinalStore() {
var _this = this;

Expand All @@ -2710,6 +2712,7 @@ function makeFinalStore(alt) {
module.exports = exports["default"];

},{}],26:[function(require,module,exports){
(function (global){
'use strict';

Object.defineProperty(exports, '__esModule', {
Expand All @@ -2719,7 +2722,7 @@ exports['default'] = withAltContext;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _react = (window.React);
var _react = (typeof window !== "undefined" ? window.React : typeof global !== "undefined" ? global.React : null);

var _react2 = _interopRequireDefault(_react);

Expand All @@ -2743,6 +2746,7 @@ function withAltContext(flux) {

module.exports = exports['default'];

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],27:[function(require,module,exports){
'use strict';

Expand Down
3 changes: 2 additions & 1 deletion dist/alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ var AltStore = (function () {
}, {
key: 'unlisten',
value: function unlisten(cb) {
if (!cb) throw new TypeError('Unlisten must receive a function');
this[Sym.LIFECYCLE].emit('unlisten');
this[EE].removeListener('change', cb);
}
Expand Down Expand Up @@ -1371,7 +1372,6 @@ var STATE_CONTAINER = (0, _esSymbol2['default'])();
exports.STATE_CONTAINER = STATE_CONTAINER;

},{"es-symbol":1}],11:[function(require,module,exports){
/* istanbul ignore next */
'use strict';

Object.defineProperty(exports, '__esModule', {
Expand All @@ -1382,6 +1382,7 @@ exports.warn = warn;
exports.uid = uid;
exports.formatAsConstant = formatAsConstant;
exports.dispatchIdentity = dispatchIdentity;
/* istanbul ignore next */
function NoopClass() {}

var builtIns = Object.getOwnPropertyNames(NoopClass);
Expand Down
12 changes: 6 additions & 6 deletions src/utils/connectToStores.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,28 @@ function connectToStores(Component) {
// Wrapper Component.
const StoreConnection = React.createClass({
getInitialState() {
return Component.getPropsFromStores(this.props)
return Component.getPropsFromStores(this.props, this.context)
},

componentDidMount() {
const stores = Component.getStores(this.props)
const stores = Component.getStores(this.props, this.context)
stores.forEach((store) => {
store.listen(this.onChange)
})
if (Component.componentDidConnect !== undefined) {
Component.componentDidConnect(this.props)
if (Component.componentDidConnect) {
Component.componentDidConnect(this.props, this.context)
}
},

componentWillUnmount() {
const stores = Component.getStores(this.props)
const stores = Component.getStores(this.props, this.context)
stores.forEach((store) => {
store.unlisten(this.onChange)
})
},

onChange() {
this.setState(Component.getPropsFromStores(this.props))
this.setState(Component.getPropsFromStores(this.props, this.context))
},

render() {
Expand Down

0 comments on commit 7cf737d

Please sign in to comment.