flux
Advanced tools
Comparing version 2.1.1 to 3.0.0
@@ -0,1 +1,4 @@ | ||
/** | ||
* Flux v3.0.0 | ||
*/ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
@@ -5,3 +8,3 @@ if(typeof exports === 'object' && typeof module === 'object') | ||
else if(typeof define === 'function' && define.amd) | ||
define(factory); | ||
define([], factory); | ||
else if(typeof exports === 'object') | ||
@@ -207,2 +210,3 @@ exports["Flux"] = factory(); | ||
Dispatcher.prototype.register = function register(callback) { | ||
!!this._isDispatching ? true ? invariant(false, 'Dispatcher.register(...): Cannot register in the middle of a dispatch.') : invariant(false) : undefined; | ||
var id = _prefix + this._lastID++; | ||
@@ -218,2 +222,3 @@ this._callbacks[id] = callback; | ||
Dispatcher.prototype.unregister = function unregister(id) { | ||
!!this._isDispatching ? true ? invariant(false, 'Dispatcher.unregister(...): Cannot unregister in the middle of a dispatch.') : invariant(false) : undefined; | ||
!this._callbacks[id] ? true ? invariant(false, 'Dispatcher.unregister(...): `%s` does not map to a registered callback.', id) : invariant(false) : undefined; | ||
@@ -318,3 +323,3 @@ delete this._callbacks[id]; | ||
/** | ||
* Copyright 2013-2015, Facebook, Inc. | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
@@ -326,6 +331,5 @@ * | ||
* | ||
* @providesModule invariant | ||
*/ | ||
"use strict"; | ||
'use strict'; | ||
@@ -343,3 +347,3 @@ /** | ||
var invariant = function invariant(condition, format, a, b, c, d, e, f) { | ||
function invariant(condition, format, a, b, c, d, e, f) { | ||
if (true) { | ||
@@ -358,5 +362,6 @@ if (format === undefined) { | ||
var argIndex = 0; | ||
error = new Error('Invariant Violation: ' + format.replace(/%s/g, function () { | ||
error = new Error(format.replace(/%s/g, function () { | ||
return args[argIndex++]; | ||
})); | ||
error.name = 'Invariant Violation'; | ||
} | ||
@@ -367,3 +372,3 @@ | ||
} | ||
}; | ||
} | ||
@@ -370,0 +375,0 @@ module.exports = invariant; |
@@ -1,1 +0,10 @@ | ||
!function(i,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):"object"==typeof exports?exports.Flux=t():i.Flux=t()}(this,function(){return function(i){function t(s){if(n[s])return n[s].exports;var e=n[s]={exports:{},id:s,loaded:!1};return i[s].call(e.exports,e,e.exports,t),e.loaded=!0,e.exports}var n={};return t.m=i,t.c=n,t.p="",t(0)}([function(i,t,n){"use strict";i.exports.Dispatcher=n(1)},function(i,t,n){"use strict";function s(i,t){if(!(i instanceof t))throw new TypeError("Cannot call a class as a function")}var e,o,r;t.__esModule=!0,e=n(2),o="ID_",r=function(){function i(){s(this,i),this._callbacks={},this._isDispatching=!1,this._isHandled={},this._isPending={},this._lastID=1}return i.prototype.register=function(i){var t=o+this._lastID++;return this._callbacks[t]=i,t},i.prototype.unregister=function(i){this._callbacks[i]?void 0:e(!1),delete this._callbacks[i]},i.prototype.waitFor=function(i){var t,n;for(this._isDispatching?void 0:e(!1),t=0;t<i.length;t++)n=i[t],this._isPending[n]?this._isHandled[n]?void 0:e(!1):(this._callbacks[n]?void 0:e(!1),this._invokeCallback(n))},i.prototype.dispatch=function(i){this._isDispatching?e(!1):void 0,this._startDispatching(i);try{for(var t in this._callbacks)this._isPending[t]||this._invokeCallback(t)}finally{this._stopDispatching()}},i.prototype.isDispatching=function(){return this._isDispatching},i.prototype._invokeCallback=function(i){this._isPending[i]=!0,this._callbacks[i](this._pendingPayload),this._isHandled[i]=!0},i.prototype._startDispatching=function(i){for(var t in this._callbacks)this._isPending[t]=!1,this._isHandled[t]=!1;this._pendingPayload=i,this._isDispatching=!0},i.prototype._stopDispatching=function(){delete this._pendingPayload,this._isDispatching=!1},i}(),i.exports=r},function(i,t,n){"use strict";var s=function(i,t,n,s,e,o,r,a){var c,p,l;if(!i)throw void 0===t?c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings."):(p=[n,s,e,o,r,a],l=0,c=new Error("Invariant Violation: "+t.replace(/%s/g,function(){return p[l++]}))),c.framesToPop=1,c};i.exports=s}])}); | ||
/** | ||
* Flux v3.0.0 | ||
* | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
!function(i,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Flux=t():i.Flux=t()}(this,function(){return function(i){function t(s){if(n[s])return n[s].exports;var e=n[s]={exports:{},id:s,loaded:!1};return i[s].call(e.exports,e,e.exports,t),e.loaded=!0,e.exports}var n={};return t.m=i,t.c=n,t.p="",t(0)}([function(i,t,n){"use strict";i.exports.Dispatcher=n(1)},function(i,t,n){"use strict";function s(i,t){if(!(i instanceof t))throw new TypeError("Cannot call a class as a function")}var e,o,a;t.__esModule=!0,e=n(2),o="ID_",a=function(){function i(){s(this,i),this._callbacks={},this._isDispatching=!1,this._isHandled={},this._isPending={},this._lastID=1}return i.prototype.register=function(i){this._isDispatching?e(!1):void 0;var t=o+this._lastID++;return this._callbacks[t]=i,t},i.prototype.unregister=function(i){this._isDispatching?e(!1):void 0,this._callbacks[i]?void 0:e(!1),delete this._callbacks[i]},i.prototype.waitFor=function(i){var t,n;for(this._isDispatching?void 0:e(!1),t=0;t<i.length;t++)n=i[t],this._isPending[n]?this._isHandled[n]?void 0:e(!1):(this._callbacks[n]?void 0:e(!1),this._invokeCallback(n))},i.prototype.dispatch=function(i){this._isDispatching?e(!1):void 0,this._startDispatching(i);try{for(var t in this._callbacks)this._isPending[t]||this._invokeCallback(t)}finally{this._stopDispatching()}},i.prototype.isDispatching=function(){return this._isDispatching},i.prototype._invokeCallback=function(i){this._isPending[i]=!0,this._callbacks[i](this._pendingPayload),this._isHandled[i]=!0},i.prototype._startDispatching=function(i){for(var t in this._callbacks)this._isPending[t]=!1,this._isHandled[t]=!1;this._pendingPayload=i,this._isDispatching=!0},i.prototype._stopDispatching=function(){delete this._pendingPayload,this._isDispatching=!1},i}(),i.exports=a},function(i,t,n){"use strict";function s(i,t,n,s,e,o,a,r){var c,p,h;if(!i)throw void 0===t?c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings."):(p=[n,s,e,o,a,r],h=0,c=new Error(t.replace(/%s/g,function(){return p[h++]})),c.name="Invariant Violation"),c.framesToPop=1,c}i.exports=s}])}); |
@@ -129,2 +129,3 @@ /** | ||
Dispatcher.prototype.register = function register(callback) { | ||
!!this._isDispatching ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Dispatcher.register(...): Cannot register in the middle of a dispatch.') : invariant(false) : undefined; | ||
var id = _prefix + this._lastID++; | ||
@@ -140,2 +141,3 @@ this._callbacks[id] = callback; | ||
Dispatcher.prototype.unregister = function unregister(id) { | ||
!!this._isDispatching ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Dispatcher.unregister(...): Cannot unregister in the middle of a dispatch.') : invariant(false) : undefined; | ||
!this._callbacks[id] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Dispatcher.unregister(...): `%s` does not map to a registered callback.', id) : invariant(false) : undefined; | ||
@@ -142,0 +144,0 @@ delete this._callbacks[id]; |
@@ -12,2 +12,3 @@ /** | ||
*/ | ||
'use strict'; | ||
@@ -21,3 +22,4 @@ | ||
var FluxStoreGroup = require('./FluxStoreGroup'); | ||
var FluxContainerSubscriptions = require('./FluxContainerSubscriptions'); | ||
var React = require('react'); | ||
@@ -27,5 +29,8 @@ var invariant = require('fbjs/lib/invariant'); | ||
var Component = React.Component; | ||
var DEFAULT_OPTIONS = { | ||
pure: true, | ||
withProps: false | ||
withProps: false, | ||
withContext: false | ||
}; | ||
@@ -40,2 +45,60 @@ | ||
* must implement. A simple container may look like: | ||
* | ||
* class FooContainer extends Component { | ||
* static getStores() { | ||
* return [FooStore]; | ||
* } | ||
* | ||
* static calculateState() { | ||
* return { | ||
* foo: FooStore.getState(), | ||
* }; | ||
* } | ||
* | ||
* render() { | ||
* return <FooView {...this.state} />; | ||
* } | ||
* } | ||
* | ||
* module.exports = FluxContainer.create(FooContainer); | ||
* | ||
* Flux container also supports some other, more advanced use cases. If you need | ||
* to base your state off of props as well: | ||
* | ||
* class FooContainer extends Component { | ||
* ... | ||
* | ||
* static calculateState(prevState, props) { | ||
* return { | ||
* foo: FooStore.getSpecificFoo(props.id), | ||
* }; | ||
* } | ||
* | ||
* ... | ||
* } | ||
* | ||
* module.exports = FluxContainer.create(FooContainer, {withProps: true}); | ||
* | ||
* Or if your stores are passed through your props: | ||
* | ||
* class FooContainer extends Component { | ||
* ... | ||
* | ||
* static getStores(props) { | ||
* const {BarStore, FooStore} = props.stores; | ||
* return [BarStore, FooStore]; | ||
* } | ||
* | ||
* statc calculateState(prevState, props) { | ||
* const {BarStore, FooStore} = props.stores; | ||
* return { | ||
* bar: BarStore.getState(), | ||
* foo: FooStore.getState(), | ||
* }; | ||
* } | ||
* | ||
* ... | ||
* } | ||
* | ||
* module.exports = FluxContainer.create(FooContainer, {withProps: true}); | ||
*/ | ||
@@ -45,55 +108,44 @@ function create(Base, options) { | ||
// Construct the options using default, override with user values as necessary | ||
// Construct the options using default, override with user values as necessary. | ||
var realOptions = _extends({}, DEFAULT_OPTIONS, options || {}); | ||
var FluxContainerClass = (function (_Base) { | ||
_inherits(FluxContainerClass, _Base); | ||
var getState = function (state, maybeProps, maybeContext) { | ||
var props = realOptions.withProps ? maybeProps : undefined; | ||
var context = realOptions.withContext ? maybeContext : undefined; | ||
return Base.calculateState(state, props, context); | ||
}; | ||
function FluxContainerClass(props) { | ||
_classCallCheck(this, FluxContainerClass); | ||
var getStores = function (maybeProps, maybeContext) { | ||
var props = realOptions.withProps ? maybeProps : undefined; | ||
var context = realOptions.withContext ? maybeContext : undefined; | ||
return Base.getStores(props, context); | ||
}; | ||
_Base.call(this, props); | ||
this.state = realOptions.withProps ? Base.calculateState(null, props) : Base.calculateState(null, undefined); | ||
} | ||
// Build the container class. | ||
// Make sure we override shouldComponentUpdate only if the pure option is | ||
// specified. We can't override this above because we don't want to override | ||
// the default behavior on accident. Super works weird with react ES6 classes | ||
// right now | ||
var ContainerClass = (function (_Base) { | ||
_inherits(ContainerClass, _Base); | ||
FluxContainerClass.prototype.componentDidMount = function componentDidMount() { | ||
function ContainerClass(props, context) { | ||
var _this = this; | ||
if (_Base.prototype.componentDidMount) { | ||
_Base.prototype.componentDidMount.call(this); | ||
} | ||
_classCallCheck(this, ContainerClass); | ||
var stores = Base.getStores(); | ||
// This tracks when any store has changed and we may need to update. | ||
var changed = false; | ||
var setChanged = function () { | ||
changed = true; | ||
}; | ||
// This adds subscriptions to stores. When a store changes all we do is | ||
// set changed to true. | ||
this._fluxContainerSubscriptions = stores.map(function (store) { | ||
return store.addListener(setChanged); | ||
_Base.call(this, props, context); | ||
this._fluxContainerSubscriptions = new FluxContainerSubscriptions(); | ||
this._fluxContainerSubscriptions.setStores(getStores(props)); | ||
this._fluxContainerSubscriptions.addListener(function () { | ||
_this.setState(function (prevState, currentProps) { | ||
return getState(prevState, currentProps, context); | ||
}); | ||
}); | ||
var calculatedState = getState(undefined, props, context); | ||
this.state = _extends({}, this.state || {}, calculatedState); | ||
} | ||
// This callback is called after the dispatch of the relevant stores. If | ||
// any have reported a change we update the state, then reset changed. | ||
var callback = function () { | ||
if (changed) { | ||
_this.setState(function (prevState) { | ||
return realOptions.withProps ? Base.calculateState(prevState, _this.props) : Base.calculateState(prevState, undefined); | ||
}); | ||
} | ||
changed = false; | ||
}; | ||
this._fluxContainerStoreGroup = new FluxStoreGroup(stores, callback); | ||
}; | ||
// Make sure we override shouldComponentUpdate only if the pure option is | ||
// specified. We can't override this above because we don't want to override | ||
// the default behavior on accident. Super works weird with react ES6 classes. | ||
FluxContainerClass.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextContext) { | ||
ContainerClass.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextContext) { | ||
if (_Base.prototype.componentWillReceiveProps) { | ||
@@ -103,19 +155,12 @@ _Base.prototype.componentWillReceiveProps.call(this, nextProps, nextContext); | ||
// Don't do anything else if the container is not configured to use props | ||
if (!realOptions.withProps) { | ||
return; | ||
if (realOptions.withProps || realOptions.withContext) { | ||
// Update both stores and state. | ||
this._fluxContainerSubscriptions.setStores(getStores(nextProps, nextContext)); | ||
this.setState(function (prevState) { | ||
return getState(prevState, nextProps, nextContext); | ||
}); | ||
} | ||
// If it's pure we can potentially optimize out the calculate state | ||
if (realOptions.pure && shallowEqual(this.props, nextProps)) { | ||
return; | ||
} | ||
// Finally update the state using the new props | ||
this.setState(function (prevState) { | ||
return Base.calculateState(prevState, nextProps); | ||
}); | ||
}; | ||
FluxContainerClass.prototype.componentWillUnmount = function componentWillUnmount() { | ||
ContainerClass.prototype.componentWillUnmount = function componentWillUnmount() { | ||
if (_Base.prototype.componentWillUnmount) { | ||
@@ -125,26 +170,9 @@ _Base.prototype.componentWillUnmount.call(this); | ||
this._fluxContainerStoreGroup.release(); | ||
for (var _iterator = this._fluxContainerSubscriptions, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var subscription = _ref; | ||
subscription.remove(); | ||
} | ||
this._fluxContainerSubscriptions = []; | ||
this._fluxContainerSubscriptions.reset(); | ||
}; | ||
return FluxContainerClass; | ||
return ContainerClass; | ||
})(Base); | ||
var container = realOptions.pure ? createPureContainer(FluxContainerClass) : FluxContainerClass; | ||
var container = realOptions.pure ? createPureComponent(ContainerClass) : ContainerClass; | ||
@@ -154,25 +182,23 @@ // Update the name of the container before returning | ||
container.displayName = 'FluxContainer(' + componentName + ')'; | ||
return container; | ||
} | ||
// TODO: typecheck this better | ||
function createPureContainer(FluxContainerBase) { | ||
var PureFluxContainerClass = (function (_FluxContainerBase) { | ||
_inherits(PureFluxContainerClass, _FluxContainerBase); | ||
function createPureComponent(BaseComponent) { | ||
var PureComponent = (function (_BaseComponent) { | ||
_inherits(PureComponent, _BaseComponent); | ||
function PureFluxContainerClass() { | ||
_classCallCheck(this, PureFluxContainerClass); | ||
function PureComponent() { | ||
_classCallCheck(this, PureComponent); | ||
_FluxContainerBase.apply(this, arguments); | ||
_BaseComponent.apply(this, arguments); | ||
} | ||
PureFluxContainerClass.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) { | ||
PureComponent.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) { | ||
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState); | ||
}; | ||
return PureFluxContainerClass; | ||
})(FluxContainerBase); | ||
return PureComponent; | ||
})(BaseComponent); | ||
return PureFluxContainerClass; | ||
return PureComponent; | ||
} | ||
@@ -185,2 +211,66 @@ | ||
module.exports = { create: create }; | ||
/** | ||
* This is a way to connect stores to a functional stateless view. Here's a | ||
* simple example: | ||
* | ||
* // FooView.js | ||
* | ||
* function FooView(props) { | ||
* return <div>{props.value}</div>; | ||
* } | ||
* | ||
* module.exports = FooView; | ||
* | ||
* | ||
* // FooContainer.js | ||
* | ||
* function getStores() { | ||
* return [FooStore]; | ||
* } | ||
* | ||
* function calculateState() { | ||
* return { | ||
* value: FooStore.getState(); | ||
* }; | ||
* } | ||
* | ||
* module.exports = FluxContainer.createFunctional( | ||
* FooView, | ||
* getStores, | ||
* calculateState, | ||
* ); | ||
* | ||
*/ | ||
function createFunctional(viewFn, _getStores, _calculateState, options) { | ||
var FunctionalContainer = (function (_Component) { | ||
_inherits(FunctionalContainer, _Component); | ||
function FunctionalContainer() { | ||
_classCallCheck(this, FunctionalContainer); | ||
_Component.apply(this, arguments); | ||
} | ||
// Update the name of the component before creating the container. | ||
FunctionalContainer.getStores = function getStores(props, context) { | ||
return _getStores(props, context); | ||
}; | ||
FunctionalContainer.calculateState = function calculateState(prevState, props, context) { | ||
return _calculateState(prevState, props, context); | ||
}; | ||
FunctionalContainer.prototype.render = function render() { | ||
return viewFn(this.state); | ||
}; | ||
return FunctionalContainer; | ||
})(Component); | ||
var viewFnName = viewFn.displayName || viewFn.name || 'FunctionalContainer'; | ||
FunctionalContainer.displayName = viewFnName; | ||
return create(FunctionalContainer, options); | ||
} | ||
module.exports = { create: create, createFunctional: createFunctional }; |
/** | ||
* Copyright (c) 2014-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
@@ -56,9 +55,15 @@ * This source code is licensed under the BSD-style license found in the | ||
function FluxMixinLegacy(stores) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? { withProps: false } : arguments[1]; | ||
stores = stores.filter(function (store) { | ||
return !!store; | ||
}); | ||
return { | ||
getInitialState: function () { | ||
enforceInterface(this); | ||
return this.constructor.calculateState(null); | ||
return options.withProps ? this.constructor.calculateState(null, this.props) : this.constructor.calculateState(null, undefined); | ||
}, | ||
componentDidMount: function () { | ||
componentWillMount: function () { | ||
var _this = this; | ||
@@ -83,3 +88,3 @@ | ||
_this.setState(function (prevState) { | ||
return _this.constructor.calculateState(_this.state); | ||
return options.withProps ? _this.constructor.calculateState(prevState, _this.props) : _this.constructor.calculateState(prevState, undefined); | ||
}); | ||
@@ -86,0 +91,0 @@ } |
/** | ||
* Copyright (c) 2014-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
@@ -24,2 +23,24 @@ * This source code is licensed under the BSD-style license found in the | ||
/** | ||
* This is the basic building block of a Flux application. All of your stores | ||
* should extend this class. | ||
* | ||
* class CounterStore extends FluxReduceStore<number> { | ||
* getInitialState(): number { | ||
* return 1; | ||
* } | ||
* | ||
* reduce(state: number, action: Object): number { | ||
* switch(action.type) { | ||
* case: 'add': | ||
* return state + action.value; | ||
* case: 'double': | ||
* return state * 2; | ||
* default: | ||
* return state; | ||
* } | ||
* } | ||
* } | ||
*/ | ||
var FluxReduceStore = (function (_FluxStore) { | ||
@@ -55,3 +76,3 @@ _inherits(FluxReduceStore, _FluxStore); | ||
* Used to reduce a stream of actions coming from the dispatcher into a | ||
* single state object | ||
* single state object. | ||
*/ | ||
@@ -72,14 +93,10 @@ | ||
/** | ||
* Use reduce and track _state instead of using __onDispatch | ||
*/ | ||
FluxReduceStore.prototype.__invokeOnDispatch = function __invokeOnDispatch(action) { | ||
this.__changed = false; | ||
// reduce the stream of incoming actions to state, update when necessary | ||
// Reduce the stream of incoming actions to state, update when necessary. | ||
var startingState = this._state; | ||
var endingState = this.reduce(startingState, action); | ||
// This means your ending state should never be undefined | ||
// This means your ending state should never be undefined. | ||
!(endingState !== undefined) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s returned undefined from reduce(...), did you forget to return ' + 'state in the default case? (use null if this was intentional)', this.constructor.name) : invariant(false) : undefined; | ||
@@ -86,0 +103,0 @@ |
/** | ||
* Copyright (c) 2014-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
@@ -24,45 +23,8 @@ * This source code is licensed under the BSD-style license found in the | ||
/** | ||
* This class should be extended by the stores in your application, like so: | ||
* | ||
* var FluxStore = require('FluxStore'); | ||
* var MyDispatcher = require('MyDispatcher'); | ||
* | ||
* var _foo; | ||
* | ||
* class MyStore extends FluxStore { | ||
* | ||
* getFoo() { | ||
* return _foo; | ||
* } | ||
* | ||
* __onDispatch = function(action) { | ||
* switch(action.type) { | ||
* | ||
* case 'an-action': | ||
* changeState(action.someData); | ||
* this.__emitChange(); | ||
* break; | ||
* | ||
* case 'another-action': | ||
* changeStateAnotherWay(action.otherData); | ||
* this.__emitChange(); | ||
* break; | ||
* | ||
* default: | ||
* // no op | ||
* } | ||
* } | ||
* | ||
* } | ||
* | ||
* module.exports = new MyStore(MyDispatcher); | ||
* This class represents the most basic functionality for a FluxStore. Do not | ||
* extend this store directly; instead extend FluxReduceStore when creating a | ||
* new store. | ||
*/ | ||
var FluxStore = (function () { | ||
/** | ||
* @public | ||
* @param {Dispatcher} dispatcher | ||
*/ | ||
function FluxStore(dispatcher) { | ||
@@ -84,9 +46,2 @@ var _this = this; | ||
/** | ||
* @public | ||
* @param {function} callback | ||
* @return {object} EmitterSubscription that can be used with | ||
* SubscriptionsHandler or directly used to release the subscription. | ||
*/ | ||
FluxStore.prototype.addListener = function addListener(callback) { | ||
@@ -96,7 +51,2 @@ return this.__emitter.addListener(this.__changeEvent, callback); | ||
/** | ||
* @public | ||
* @return {Dispatcher} The dispatcher that this store is registered with. | ||
*/ | ||
FluxStore.prototype.getDispatcher = function getDispatcher() { | ||
@@ -107,6 +57,5 @@ return this.__dispatcher; | ||
/** | ||
* @public | ||
* @return {string} A string the dispatcher uses to identify each store's | ||
* registered callback. This is used with the dispatcher's waitFor method | ||
* to declaratively depend on other stores updating themselves first. | ||
* This exposes a unique string to identify each store's registered callback. | ||
* This is used with the dispatcher's waitFor method to devlaratively depend | ||
* on other stores updating themselves first. | ||
*/ | ||
@@ -119,5 +68,3 @@ | ||
/** | ||
* @public | ||
* @return {boolean} Whether the store has changed during the most recent | ||
* dispatch. | ||
* Returns whether the store has changed during the most recent dispatch. | ||
*/ | ||
@@ -130,7 +77,2 @@ | ||
/** | ||
* @protected | ||
* Emit an event notifying listeners that the state of the store has changed. | ||
*/ | ||
FluxStore.prototype.__emitChange = function __emitChange() { | ||
@@ -145,7 +87,2 @@ !this.__dispatcher.isDispatching() ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.__emitChange(): Must be invoked while dispatching.', this.__className) : invariant(false) : undefined; | ||
* subclass has handled a payload. | ||
* | ||
* @protected | ||
* @param {object} payload The data dispatched by the dispatcher, describing | ||
* something that has happened in the real world: the user clicked, the | ||
* server responded, time passed, etc. | ||
*/ | ||
@@ -165,8 +102,2 @@ | ||
* only way the store receives new data. | ||
* | ||
* @protected | ||
* @override | ||
* @param {object} payload The data dispatched by the dispatcher, describing | ||
* something that has happened in the real world: the user clicked, the | ||
* server responded, time passed, etc. | ||
*/ | ||
@@ -173,0 +104,0 @@ |
@@ -32,3 +32,3 @@ /** | ||
// precompute store tokens | ||
// Precompute store tokens. | ||
var storeTokens = stores.map(function (store) { | ||
@@ -38,3 +38,3 @@ return store.getDispatchToken(); | ||
// register with the dispatcher | ||
// Register with the dispatcher. | ||
this._dispatchToken = this._dispatcher.register(function (payload) { | ||
@@ -41,0 +41,0 @@ _this._dispatcher.waitFor(storeTokens); |
{ | ||
"name": "flux", | ||
"version": "2.1.1", | ||
"version": "3.0.0", | ||
"description": "An application architecture based on a unidirectional data flow", | ||
@@ -17,3 +17,2 @@ "keywords": [ | ||
"README.md", | ||
"flow", | ||
"index.js", | ||
@@ -38,3 +37,3 @@ "lib", | ||
"Bill Fisher <fisherwebdev@gmail.com>", | ||
"Paul O'Shannessy <paul@oshanessy.com>", | ||
"Paul O'Shannessy <paul@oshannessy.com>", | ||
"Kyle Davis <kyldvs@gmail.com>" | ||
@@ -44,22 +43,30 @@ ], | ||
"devDependencies": { | ||
"babel": "^5.4.7", | ||
"babel-core": "^5.8.22", | ||
"babel-loader": "^5.3.2", | ||
"del": "^1.2.0", | ||
"del": "^2.2.0", | ||
"fbjs-scripts": "^0.5.0", | ||
"gulp": "^3.9.0", | ||
"gulp-babel": "^5.1.0", | ||
"gulp-flatten": "^0.1.1", | ||
"gulp-flatten": "^0.2.0", | ||
"gulp-header": "1.8.2", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-util": "^3.0.6", | ||
"jest-cli": "^0.4.18", | ||
"object-assign": "^3.0.0", | ||
"immutable": "^3.7.4", | ||
"jest": "^15.1.1", | ||
"object-assign": "^4.0.1", | ||
"react": "^15.0.2", | ||
"react-addons-test-utils": "^15.0.1", | ||
"react-dom": "^15.0.1", | ||
"run-sequence": "^1.1.0", | ||
"vinyl-source-stream": "^1.0.0", | ||
"webpack": "^1.11.0", | ||
"webpack-stream": "^2.1.0" | ||
"webpack-stream": "^3.1.0" | ||
}, | ||
"dependencies": { | ||
"fbemitter": "^2.0.0", | ||
"fbjs": "0.1.0-alpha.7", | ||
"immutable": "^3.7.4" | ||
"fbjs": "^0.8.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^15.0.2" | ||
}, | ||
"jest": { | ||
@@ -70,16 +77,12 @@ "modulePathIgnorePatterns": [ | ||
], | ||
"persistModuleRegistryBetweenSpecs": true, | ||
"preprocessorIgnorePatterns": [ | ||
"/node_modules/" | ||
], | ||
"rootDir": "", | ||
"rootDir": "./", | ||
"scriptPreprocessor": "scripts/jest/preprocessor.js", | ||
"setupEnvScriptFile": "scripts/jest/environment.js", | ||
"setupFiles": ["scripts/jest/environment.js"], | ||
"testPathDirs": [ | ||
"<rootDir>/src" | ||
], | ||
"unmockedModulePathPatterns": [ | ||
"<rootDir>/node_modules/(?!fbemitter)" | ||
] | ||
} | ||
} |
@@ -84,3 +84,3 @@ # Flux | ||
We originally set out to deal correctly with derived data: for example, we wanted to show an unread count for message threads while another view showed a list of threads, with the unread ones highlighted. This was difficult to handle with MVC — marking a single thread as read would update the thread model, and then also need to update the unread count model. These dependencies and cascading updates often occur in a large MVC application, leading to a tangled weave of data flow and unpredictable results. | ||
We originally set out to correctly deal with derived data: for example, we wanted to show an unread count for message threads while another view showed a list of threads, with the unread ones highlighted. This was difficult to handle with MVC — marking a single thread as read would update the thread model, and then also need to update the unread count model. These dependencies and cascading updates often occur in a large MVC application, leading to a tangled weave of data flow and unpredictable results. | ||
@@ -87,0 +87,0 @@ Control is inverted with ___stores___: the stores accept updates and reconcile them as appropriate, rather than depending on something external to update its data in a consistent way. Nothing outside the store has any insight into how it manages the data for its domain, helping to keep a clear separation of concerns. This also makes stores more testable than models, especially since stores have no direct setter methods like `setAsRead()`, but instead have only an input point for a data payload, which is delivered through the ___dispatcher___ and originates with ___action creators___. |
@@ -11,5 +11,4 @@ /** | ||
module.exports.Container = require('./lib/FluxContainer'); | ||
module.exports.MapStore = require('./lib/FluxMapStore'); | ||
module.exports.Mixin = require('./lib/FluxMixinLegacy'); | ||
module.exports.ReduceStore = require('./lib/FluxReduceStore'); | ||
module.exports.Store = require('./lib/FluxStore'); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
307959
27
6112
20
20
1
+ Addedcreate-react-class@15.7.0(transitive)
+ Addedprop-types@15.8.1(transitive)
+ Addedreact@15.7.0(transitive)
+ Addedreact-is@16.13.1(transitive)
- Removedimmutable@^3.7.4
- Removedfbjs@0.1.0-alpha.7(transitive)
- Removedimmutable@3.8.2(transitive)
- Removedwhatwg-fetch@0.9.0(transitive)
Updatedfbjs@^0.8.0