Comparing version 0.13.10 to 0.13.11
128
CHANGELOG.md
@@ -7,7 +7,129 @@ # Changelog | ||
* DispatcherRecorder is a util that allows you to record and replay a series of actions. | ||
* FinalStore is a util Store that emits a change once all other stores have emitted. | ||
* DispatcherRecorder is a util that allows you to record and replay a series of actions. [commit](https://github.com/goatslacker/alt/commit/834ccf1718ccd6067dadbb286ca0fbbfd5510ecb) | ||
* FinalStore is a util Store that emits a change once all other stores have emitted. [commit](https://github.com/goatslacker/alt/commit/c104fb73eedd61f4c1dbd4ac074ce8a2f4b818bf) | ||
Fixed: | ||
* All the mixins in the mixins folder don't make React complain about binding. | ||
* All the mixins in the mixins folder don't make React complain about binding. [commit](https://github.com/goatslacker/alt/commit/1e5ca13d93f66f6839277dadf9eb3c62989f5569) | ||
## 0.13.8 | ||
New: | ||
* Create context on `add` in `Subscribe` mixin. [commit](https://github.com/goatslacker/alt/commit/df952a22b1b785b719c82df602489cac3cb8d884) | ||
Fixed: | ||
* Change lifecycle hook for `Listener` mixin to `ComponentWillMount` so that it functions are identical | ||
between server rendering and client rendering. [commit](https://github.com/goatslacker/alt/commit/a3a83b963c970e44db10f13afd0c20f74d01084b) | ||
## 0.13.7 | ||
New: | ||
* Add `bindListeners` method to Store. This is the inverse of `bindActions`. [commit](https://github.com/goatslacker/alt/commit/3997f7960ac0b6c1f4fac00b33dc520b9816d70d) | ||
* Create shorthand form of `createActions`, `generateActions`. [commit](https://github.com/goatslacker/alt/commit/84e6bc40f1d7d03dc51f4f68d76bcca5b2fae748) | ||
* Add/update several helpful mixins: `FluxyMixin`, `ReactStateMagicMixin`, and `Subscribe`. [commit](https://github.com/goatslacker/alt/commit/c6acbf5deeee4aa60bd1e6bfcf590d4673926016) | ||
Removed: | ||
* Remove `ReactStoreMixin`. [commit](https://github.com/goatslacker/alt/commit/fb1823c900a61fa5a99dffc4ce1a2be17f8d1717) | ||
Refactored: | ||
* Utilize ES6 import. [commit](https://github.com/goatslacker/alt/commit/ffc66dd99447b42b7ac08f7282f41d7d495ed547) | ||
## 0.13.4 | ||
New: | ||
* Add tests. | ||
## 0.13.5 | ||
New: | ||
* Add `bower.json` to enable Alt with Bower. [commit](https://github.com/goatslacker/alt/commit/3f7fc4248c8bc8bd07c9d8f298dda5610af994b5) | ||
* Initial mixin pack addition. [commit](https://github.com/goatslacker/alt/commit/1d5ed1ec06c675a8b85aa683930cc208e88ae60b) | ||
* `ListenerMixin` updated to `listenTo` various stores. [commit](https://github.com/goatslacker/alt/commit/eb7ba8d86f96f5c809aa3787dd29619426c7be60) | ||
## 0.13.3 | ||
Dependency Updates: | ||
* Upgrade to Babel 4.0 (formerly 6to5). [commit](https://github.com/goatslacker/alt/commit/b7dd7795fb8e5b727f07ca578ca1fc930ed6c18b) | ||
## 0.13.2 | ||
New: | ||
* Allow dispatching specific actions with any data. [commit](https://github.com/goatslacker/alt/commit/48efd697378d1b6f794270e0aa6bbad44f0036e5) | ||
* Remove dispatcher symbol from actions. [commit](https://github.com/goatslacker/alt/commit/6a3a7c272d2d46cbb8fee5058aac0a8064a3ad07) | ||
Fixed: | ||
* Assure that store instances do not collide. [commit](https://github.com/goatslacker/alt/commit/6fa0e4a0e868eea4c0b91c7f630589619530f62b) | ||
* Fix bug with defer where it is not variadic. [commit](https://github.com/goatslacker/alt/commit/eb4e3a01279c4e9d7a85d8adcce525e851d09ad9) | ||
## 0.13.1 | ||
New: | ||
* Allow same action name on different Action Classes. [commit](https://github.com/goatslacker/alt/commit/b17d39209ed9e771adc267edc058cf5ef70bb44e) | ||
## 0.13.0 | ||
New: | ||
* Allow unlimited bootstraps. [commit](https://github.com/goatslacker/alt/commit/0ba7b85a97df7dfef37d8f6c97ec48e5ee35b198) | ||
## 0.12.0 | ||
New: | ||
* Replace lifecycle method API. [commit](https://github.com/goatslacker/alt/commit/4c76f7a54f3ceec028ca473b024fdc88ae34292f) | ||
* Add lifecycle methods, `onBootstrapped` and `onRolledBack`. [commit](https://github.com/goatslacker/alt/commit/25dd191b3108fc3b1c73790b38f92000654658b6) | ||
* Distribute Alt with 6to5 runtime. [commit](https://github.com/goatslacker/alt/commit/0147a2e4e072b9574e92a20687e9613c9da4b2c9) | ||
* Allow creating many instances of Stores. [commit](https://github.com/goatslacker/alt/commit/7d9c255bb4f6923b1b17b5e2a6d65e2139636b3a) | ||
## 0.11.0 | ||
Dependency Updates: | ||
* Update 6to5. [commit](https://github.com/goatslacker/alt/commit/5facbbbc8d5fb8573e7edcf5b0dd76b20b37de32) | ||
* Update es-symbol [commit](https://github.com/goatslacker/alt/commit/d2a1377357eff68c8512be2971228ab863751cba) | ||
## 0.10.2 | ||
New: | ||
* Add a class to safeguard call checks. [commit](https://github.com/goatslacker/alt/commit/29012097425e5dc232897a957eb63f4488d5d2dd) | ||
## 0.10.1 | ||
New: | ||
* Add `exportObj` argument to `createActions`. [commit](https://github.com/goatslacker/alt/commit/dc7c75d47866afe1e6d2a0f50e859c1df6b530c1) | ||
## 0.10.0 | ||
New: | ||
* Allow recycling of specific stores. [commit](https://github.com/goatslacker/alt/commit/614843bd2cc84a651229f89a0f0bc749a0249537) | ||
Refactored: | ||
* Utilize ES6 `let`. [commit](https://github.com/goatslacker/alt/commit/6062ad9261be79ed471abfccfe237bda4fb58c7f) | ||
## 0.9.0 | ||
New: | ||
* Unlimited boostrapping on server. [commit](https://github.com/goatslacker/alt/commit/14601b4771afc01f5310c860c63a119bebc45ea9) | ||
## 0.8.0 | ||
New: | ||
* Add `recycle` and `flush` methods. [commit](https://github.com/goatslacker/alt/commit/e3016347f41c14b019235c096415dfa29158d6f8) | ||
* Make stores available in `alt.stores`. [commit](https://github.com/goatslacker/alt/commit/598624c2e281ffed6b5c6b4122930ce5a6a0d7be) |
"use strict"; | ||
var Dispatcher = require("flux").Dispatcher; | ||
var EventEmitter = babelHelpers.interopRequire(require("eventemitter3")); | ||
var Symbol = babelHelpers.interopRequire(require("es-symbol")); | ||
var assign = babelHelpers.interopRequire(require("object-assign")); | ||
@@ -51,2 +50,3 @@ | ||
var _this6 = this; | ||
babelHelpers.classCallCheck(this, AltStore); | ||
@@ -74,2 +74,9 @@ | ||
babelHelpers.prototypeProperties(AltStore, null, { | ||
getEventEmitter: { | ||
value: function getEventEmitter() { | ||
return this[EE]; | ||
}, | ||
writable: true, | ||
configurable: true | ||
}, | ||
emitChange: { | ||
@@ -105,3 +112,2 @@ value: function emitChange() { | ||
}); | ||
return AltStore; | ||
@@ -129,3 +135,2 @@ })(); | ||
}); | ||
return ActionCreator; | ||
@@ -161,2 +166,3 @@ })(); | ||
var _this6 = this; | ||
Object.keys(actions).forEach(function (action) { | ||
@@ -189,2 +195,3 @@ var symbol = actions[action]; | ||
var _this6 = this; | ||
Object.keys(obj).forEach(function (methodName) { | ||
@@ -208,7 +215,17 @@ var symbol = obj[methodName]; | ||
waitFor: function waitFor(tokens) { | ||
if (!tokens) { | ||
waitFor: function waitFor(sources) { | ||
if (!sources) { | ||
throw new ReferenceError("Dispatch tokens not provided"); | ||
} | ||
tokens = Array.isArray(tokens) ? tokens : [tokens]; | ||
if (arguments.length === 1) { | ||
sources = Array.isArray(sources) ? sources : [sources]; | ||
} else { | ||
sources = Array.prototype.slice.call(arguments); | ||
} | ||
var tokens = sources.map(function (source) { | ||
return source.dispatchToken || source; | ||
}); | ||
this.dispatcher.waitFor(tokens); | ||
@@ -277,2 +294,3 @@ } | ||
var saveStore = arguments[2] === undefined ? true : arguments[2]; | ||
var storeInstance = undefined; | ||
@@ -288,4 +306,5 @@ var key = iden || StoreModel.displayName || StoreModel.name; | ||
// so we can inherit any extensions from the provided store. | ||
var Store = (function (StoreModel) { | ||
function Store() { | ||
function Store(alt) { | ||
babelHelpers.classCallCheck(this, Store); | ||
@@ -295,7 +314,6 @@ | ||
this[LISTENERS] = {}; | ||
babelHelpers.get(Object.getPrototypeOf(Store.prototype), "constructor", this).call(this); | ||
babelHelpers.get(Object.getPrototypeOf(Store.prototype), "constructor", this).call(this, alt); | ||
} | ||
babelHelpers.inherits(Store, StoreModel); | ||
return Store; | ||
@@ -308,8 +326,18 @@ })(StoreModel); | ||
dispatcher: this.dispatcher, | ||
getInstance: function () { | ||
getInstance: function getInstance() { | ||
return storeInstance; | ||
}, | ||
emitChange: function emitChange() { | ||
this.getInstance().emitChange(); | ||
}, | ||
setState: function setState() { | ||
var values = arguments[0] === undefined ? {} : arguments[0]; | ||
assign(this, values); | ||
this.emitChange(); | ||
return false; | ||
} | ||
}); | ||
var store = new Store(); | ||
var store = new Store(this); | ||
@@ -336,2 +364,3 @@ storeInstance = assign(new AltStore(this.dispatcher, store), getInternalMethods(StoreModel, builtIns)); | ||
var _ref; | ||
(_ref = this).generateActions.apply(_ref, actionNames); | ||
@@ -346,3 +375,5 @@ }); | ||
var _this6 = this; | ||
var exportObj = arguments[1] === undefined ? {} : arguments[1]; | ||
var actions = assign({}, getInternalMethods(ActionsClass.prototype, builtInProto)); | ||
@@ -352,10 +383,9 @@ var key = ActionsClass.displayName || ActionsClass.name; | ||
var ActionsGenerator = (function (ActionsClass) { | ||
function ActionsGenerator() { | ||
function ActionsGenerator(alt) { | ||
babelHelpers.classCallCheck(this, ActionsGenerator); | ||
babelHelpers.get(Object.getPrototypeOf(ActionsGenerator.prototype), "constructor", this).call(this); | ||
babelHelpers.get(Object.getPrototypeOf(ActionsGenerator.prototype), "constructor", this).call(this, alt); | ||
} | ||
babelHelpers.inherits(ActionsGenerator, ActionsClass); | ||
babelHelpers.prototypeProperties(ActionsGenerator, null, { | ||
@@ -383,7 +413,6 @@ generateActions: { | ||
}); | ||
return ActionsGenerator; | ||
})(ActionsClass); | ||
new ActionsGenerator(); | ||
new ActionsGenerator(this); | ||
@@ -485,4 +514,4 @@ return Object.keys(actions).reduce(function (obj, action) { | ||
addStore: { | ||
value: function addStore(name, StoreModel) { | ||
this.createStore(StoreModel, name); | ||
value: function addStore(name, StoreModel, saveStore) { | ||
this.createStore(StoreModel, name, saveStore); | ||
}, | ||
@@ -507,3 +536,2 @@ writable: true, | ||
}); | ||
return Alt; | ||
@@ -510,0 +538,0 @@ })(); |
@@ -14,2 +14,3 @@ "use strict"; | ||
var Dispatcher = require("flux").Dispatcher; | ||
var EventEmitter = _interopRequire(require("eventemitter3")); | ||
@@ -62,2 +63,3 @@ | ||
var _this6 = this; | ||
_classCallCheck(this, AltStore); | ||
@@ -85,2 +87,9 @@ | ||
_prototypeProperties(AltStore, null, { | ||
getEventEmitter: { | ||
value: function getEventEmitter() { | ||
return this[EE]; | ||
}, | ||
writable: true, | ||
configurable: true | ||
}, | ||
emitChange: { | ||
@@ -170,2 +179,3 @@ value: function emitChange() { | ||
var _this6 = this; | ||
Object.keys(actions).forEach(function (action) { | ||
@@ -198,2 +208,3 @@ var symbol = actions[action]; | ||
var _this6 = this; | ||
Object.keys(obj).forEach(function (methodName) { | ||
@@ -217,7 +228,17 @@ var symbol = obj[methodName]; | ||
waitFor: function waitFor(tokens) { | ||
if (!tokens) { | ||
waitFor: function waitFor(sources) { | ||
if (!sources) { | ||
throw new ReferenceError("Dispatch tokens not provided"); | ||
} | ||
tokens = Array.isArray(tokens) ? tokens : [tokens]; | ||
if (arguments.length === 1) { | ||
sources = Array.isArray(sources) ? sources : [sources]; | ||
} else { | ||
sources = Array.prototype.slice.call(arguments); | ||
} | ||
var tokens = sources.map(function (source) { | ||
return source.dispatchToken || source; | ||
}); | ||
this.dispatcher.waitFor(tokens); | ||
@@ -286,2 +307,3 @@ } | ||
var saveStore = arguments[2] === undefined ? true : arguments[2]; | ||
var storeInstance = undefined; | ||
@@ -297,4 +319,5 @@ var key = iden || StoreModel.displayName || StoreModel.name; | ||
// so we can inherit any extensions from the provided store. | ||
var Store = (function (StoreModel) { | ||
function Store() { | ||
function Store(alt) { | ||
_classCallCheck(this, Store); | ||
@@ -304,3 +327,3 @@ | ||
this[LISTENERS] = {}; | ||
_get(Object.getPrototypeOf(Store.prototype), "constructor", this).call(this); | ||
_get(Object.getPrototypeOf(Store.prototype), "constructor", this).call(this, alt); | ||
} | ||
@@ -317,8 +340,18 @@ | ||
dispatcher: this.dispatcher, | ||
getInstance: function () { | ||
getInstance: function getInstance() { | ||
return storeInstance; | ||
}, | ||
emitChange: function emitChange() { | ||
this.getInstance().emitChange(); | ||
}, | ||
setState: function setState() { | ||
var values = arguments[0] === undefined ? {} : arguments[0]; | ||
assign(this, values); | ||
this.emitChange(); | ||
return false; | ||
} | ||
}); | ||
var store = new Store(); | ||
var store = new Store(this); | ||
@@ -345,2 +378,3 @@ storeInstance = assign(new AltStore(this.dispatcher, store), getInternalMethods(StoreModel, builtIns)); | ||
var _ref; | ||
(_ref = this).generateActions.apply(_ref, actionNames); | ||
@@ -355,3 +389,5 @@ }); | ||
var _this6 = this; | ||
var exportObj = arguments[1] === undefined ? {} : arguments[1]; | ||
var actions = assign({}, getInternalMethods(ActionsClass.prototype, builtInProto)); | ||
@@ -361,6 +397,6 @@ var key = ActionsClass.displayName || ActionsClass.name; | ||
var ActionsGenerator = (function (ActionsClass) { | ||
function ActionsGenerator() { | ||
function ActionsGenerator(alt) { | ||
_classCallCheck(this, ActionsGenerator); | ||
_get(Object.getPrototypeOf(ActionsGenerator.prototype), "constructor", this).call(this); | ||
_get(Object.getPrototypeOf(ActionsGenerator.prototype), "constructor", this).call(this, alt); | ||
} | ||
@@ -396,3 +432,3 @@ | ||
new ActionsGenerator(); | ||
new ActionsGenerator(this); | ||
@@ -494,4 +530,4 @@ return Object.keys(actions).reduce(function (obj, action) { | ||
addStore: { | ||
value: function addStore(name, StoreModel) { | ||
this.createStore(StoreModel, name); | ||
value: function addStore(name, StoreModel, saveStore) { | ||
this.createStore(StoreModel, name, saveStore); | ||
}, | ||
@@ -498,0 +534,0 @@ writable: true, |
@@ -1,43 +0,44 @@ | ||
// This mixin lets you setup your listeners. It is similar to Fluxible's mixin. | ||
// | ||
// Usage: | ||
// | ||
// mixins: [FluxyMixin], | ||
// | ||
// statics: { | ||
// storeListeners: { | ||
// doFoo: FooStore, | ||
// doBar: BarStore | ||
// } | ||
// }, | ||
// | ||
// doFoo: function (storeState) { | ||
// this.setState({ foo: FooStore.getState() }) | ||
// }, | ||
// | ||
// doBar: function (storeState) { }, | ||
// | ||
// render: function () { | ||
// // state will be in the keys you provided | ||
// this.state.foo | ||
// } | ||
// | ||
// ---- | ||
// | ||
// You can also pass in an Array of stores to storeListeners: | ||
// | ||
// statics: { | ||
// storeListeners: [FooStore, BarStore] | ||
// } | ||
// | ||
// Changes will then be passed to a function `onChange` which you will have | ||
// to define: | ||
// | ||
// onChange() { | ||
// this.setState({ | ||
// foo: FooStore.getState(), | ||
// bar: BarStore.getState() | ||
// }) | ||
// } | ||
// | ||
/** | ||
* This mixin lets you setup your listeners. It is similar to Fluxible's mixin. | ||
* | ||
* Usage: | ||
* | ||
* mixins: [FluxyMixin], | ||
* | ||
* statics: { | ||
* storeListeners: { | ||
* doFoo: FooStore, | ||
* doBar: BarStore | ||
* } | ||
* }, | ||
* | ||
* doFoo: function (storeState) { | ||
* this.setState({ foo: FooStore.getState() }) | ||
* }, | ||
* | ||
* doBar: function (storeState) { }, | ||
* | ||
* render: function () { | ||
* // state will be in the keys you provided | ||
* this.state.foo | ||
* } | ||
* | ||
* ---- | ||
* | ||
* You can also pass in an Array of stores to storeListeners: | ||
* | ||
* statics: { | ||
* storeListeners: [FooStore, BarStore] | ||
* } | ||
* | ||
* Changes will then be passed to a function `onChange` which you will have | ||
* to define: | ||
* | ||
* onChange() { | ||
* this.setState({ | ||
* foo: FooStore.getState(), | ||
* bar: BarStore.getState() | ||
* }) | ||
* } | ||
*/ | ||
var Subscribe = require('./Subscribe') | ||
@@ -44,0 +45,0 @@ |
@@ -1,30 +0,32 @@ | ||
// This mixin automatically sets the state for you based on the key you provide | ||
// | ||
// Usage: | ||
// | ||
// mixins: [ReactStateMagicMixin], | ||
// | ||
// statics: { | ||
// registerStores: { | ||
// foo: FooStore, | ||
// bar: BarStore | ||
// } | ||
// }, | ||
// | ||
// render: function () { | ||
// // state will be in the keys you provided | ||
// this.state.foo | ||
// this.state.bar | ||
// } | ||
// | ||
// Alternatively: | ||
// | ||
// statics: { | ||
// registerStore: FooStore | ||
// }, | ||
// | ||
// render: function () { | ||
// // all of FooStore's state will be dumped into this.state | ||
// this.state | ||
// } | ||
/** | ||
* This mixin automatically sets the state for you based on the key you provide | ||
* | ||
* Usage: | ||
* | ||
* mixins: [ReactStateMagicMixin], | ||
* | ||
* statics: { | ||
* registerStores: { | ||
* foo: FooStore, | ||
* bar: BarStore | ||
* } | ||
* }, | ||
* | ||
* render: function () { | ||
* // state will be in the keys you provided | ||
* this.state.foo | ||
* this.state.bar | ||
* } | ||
* | ||
* Alternatively: | ||
* | ||
* statics: { | ||
* registerStore: FooStore | ||
* }, | ||
* | ||
* render: function () { | ||
* // all of FooStore's state will be dumped into this.state | ||
* this.state | ||
* } | ||
*/ | ||
var Subscribe = require('./Subscribe') | ||
@@ -31,0 +33,0 @@ |
{ | ||
"name": "alt", | ||
"version": "0.13.10", | ||
"version": "0.13.11", | ||
"description": "A flux implementation", | ||
@@ -13,3 +13,3 @@ "main": "dist/alt.js", | ||
"devDependencies": { | ||
"babel": "^4.0.1", | ||
"babel": "^4.6.6", | ||
"coveralls": "^2.11.2", | ||
@@ -16,0 +16,0 @@ "istanbul": "^0.3.5", |
@@ -13,12 +13,14 @@ # alt | ||
If you're in a hurry [show me the code](#examples) or [tl;dr](#tldr). | ||
Alt is a [flux](http://facebook.github.io/flux/docs/overview.html) implementation that is [small](https://github.com/goatslacker/alt/blob/master/src/alt.js) (< 500 LOC), [well tested](https://github.com/goatslacker/alt/tree/master/test), [terse](https://github.com/goatslacker/alt#differences), [insanely flexible](#flexibility), and [forward thinking](#es6). | ||
Why you should be using Alt | ||
Some boilerplate has been removed from flux such as the [JS "constants"](https://github.com/facebook/flux/blob/master/examples/flux-chat/js/constants/ChatConstants.js), | ||
the [static string tossing](https://github.com/facebook/flux/blob/master/examples/flux-chat/js/dispatcher/ChatAppDispatcher.js#L39), | ||
and the [massive switch statements](https://github.com/facebook/flux/blob/master/examples/flux-chat/js/stores/MessageStore.js#L111) you're required to code. | ||
* It is pure [flux](http://facebook.github.io/flux/docs/overview.html). | ||
* It's [small](https://github.com/goatslacker/alt/blob/master/src/alt.js) and readable. | ||
* It is [terse](https://github.com/goatslacker/alt#no-boilerplate). No boilerplate. | ||
* Extremely [flexible](#flexibility) and unopionated in how you use flux. | ||
* Alt is [forward thinking](#es6). | ||
* It's being used and actively maintained. | ||
Alt is pure flux though. Data flows one way. Here's an ascii chart to prove it. | ||
Alt is pure flux and data flows one way. Here's an ascii chart to prove it. | ||
@@ -55,5 +57,7 @@ ```txt | ||
## Differences | ||
## No Boilerplate | ||
Some boilerplate has been removed from flux. | ||
Some boilerplate has been removed from flux such as the [JS "constants"](https://github.com/facebook/flux/blob/master/examples/flux-chat/js/constants/ChatConstants.js), | ||
the [static string tossing](https://github.com/facebook/flux/blob/master/examples/flux-chat/js/dispatcher/ChatAppDispatcher.js#L39), | ||
and the [massive switch statements](https://github.com/facebook/flux/blob/master/examples/flux-chat/js/stores/MessageStore.js#L111) you're required to code. | ||
@@ -436,3 +440,3 @@ There is no giant switch statement you have to write in your store and this is because alt removes the burden of constants from the developer. | ||
componentWillMount() { | ||
componentDidMount() { | ||
locationStore.listen(this.onChange) | ||
@@ -476,3 +480,3 @@ }, | ||
componentWillMount() { | ||
componentDidMount() { | ||
this.listenTo(locationStore, this.onChange) | ||
@@ -479,0 +483,0 @@ }, |
@@ -11,4 +11,2 @@ import Alt from '../dist/alt-with-runtime' | ||
import makeFinalStore from '../utils/makeFinalStore' | ||
let alt = new Alt() | ||
@@ -55,2 +53,3 @@ | ||
} | ||
} | ||
@@ -215,2 +214,15 @@ | ||
class ThirdStore { | ||
constructor() { | ||
this.bindAction(myActions.updateName, this.onUpdateName) | ||
} | ||
onUpdateName() { | ||
this.waitFor(myStore, secondStore) // Not referencing dispatchToken! | ||
this.name = secondStore.getState().name + '3' | ||
} | ||
} | ||
let thirdStore = alt.createStore(ThirdStore) | ||
// Alt instances... | ||
@@ -277,3 +289,3 @@ | ||
let storePrototype = Object.getPrototypeOf(myStore) | ||
let assertMethods = ['constructor', 'emitChange', 'listen', 'unlisten', 'getState'] | ||
let assertMethods = ['constructor', 'getEventEmitter', 'emitChange', 'listen', 'unlisten', 'getState'] | ||
assert.deepEqual(Object.getOwnPropertyNames(storePrototype), assertMethods, 'methods exist for store') | ||
@@ -354,2 +366,3 @@ assert.equal(typeof myStore.addListener, 'undefined', 'event emitter methods not present') | ||
assert.equal(secondStore.getState().name, 'bear', 'second store gets its value from myStore') | ||
assert.equal(thirdStore.getState().name, 'bear3', 'third store gets its value from secondStore, adds 3') | ||
}, | ||
@@ -855,3 +868,3 @@ | ||
this.test = true | ||
this.getInstance().emitChange() | ||
this.emitChange() | ||
}) | ||
@@ -1162,62 +1175,4 @@ return false | ||
}, | ||
'make final store'() { | ||
function Action() { this.generateActions('set') } | ||
let action = alt.createActions(Action) | ||
function Store1() { | ||
this.bindActions(action) | ||
this.value = null | ||
} | ||
Store1.prototype.set = function () { | ||
this.value = 1 | ||
} | ||
function Store2() { | ||
this.bindActions(action) | ||
this.value = null | ||
} | ||
Store2.prototype.set = function () { | ||
this.value = 2 | ||
} | ||
function Store3() { | ||
this.bindActions(action) | ||
this.value = null | ||
} | ||
Store3.prototype.set = function () { | ||
this.value = 3 | ||
} | ||
// I put these out of order intentionally because order shouldn't | ||
// determine when these get called, the finalstore should always be last. | ||
let store1 = alt.createStore(Store1) | ||
let FinalStore = makeFinalStore(alt) | ||
let store2 = alt.createStore(Store2) | ||
let store3 = alt.createStore(Store3) | ||
let finalStoreCalls = 0 | ||
FinalStore.listen(() => { | ||
assert.equal(++finalStoreCalls, 1, 'final store was called only once') | ||
assert.equal(store1.getState().value, 1, 'store1 value correct') | ||
assert.equal(store2.getState().value, 2, 'store2 value correct') | ||
assert.equal(store3.getState().value, 3, 'store3 value correct') | ||
}) | ||
let store2Calls = 0 | ||
store2.listen(() => { | ||
assert.equal(++store2Calls, 1, 'store 2 listen was only called once') | ||
assert.equal(store2.getState().value, 2, 'store2 state was updated successfully') | ||
}) | ||
// Fire off the action | ||
action.set() | ||
}, | ||
} | ||
export default tests |
@@ -0,1 +1,28 @@ | ||
/** | ||
* DispatcherRecorder(alt: AltInstance): DispatcherInstance | ||
* | ||
* > Record and replay your actions at any point in time. | ||
* | ||
* This util allows you to record a set of dispatches which you can later | ||
* replay at your convenience. | ||
* | ||
* Good for: Debugging, repeating, logging. | ||
* | ||
* Usage: | ||
* | ||
* ```js | ||
* var recorder = new DispatcherRecorder(alt); | ||
* | ||
* // start recording | ||
* recorder.record(); | ||
* | ||
* // call a series of actions | ||
* | ||
* // stop recording | ||
* recorder.stop(); | ||
* | ||
* // replay the events that took place | ||
* recorder.replay(); | ||
* ``` | ||
*/ | ||
module.exports = DispatcherRecorder | ||
@@ -9,2 +36,7 @@ | ||
/** | ||
* record(): boolean | ||
* If recording started you get true, otherwise false since there's a recording | ||
* in progress. | ||
*/ | ||
DispatcherRecorder.prototype.record = function () { | ||
@@ -22,2 +54,5 @@ if (this.dispatchToken) { | ||
/** | ||
* Stops the recording in progress. | ||
*/ | ||
DispatcherRecorder.prototype.stop = function () { | ||
@@ -28,2 +63,5 @@ this.alt.dispatcher.unregister(this.dispatchToken) | ||
/** | ||
* Clear all events from memory. | ||
*/ | ||
DispatcherRecorder.prototype.clear = function () { | ||
@@ -33,2 +71,5 @@ this.events = [] | ||
/** | ||
* Synchronously replay all events that were recorded. | ||
*/ | ||
DispatcherRecorder.prototype.replay = function () { | ||
@@ -35,0 +76,0 @@ this.events.forEach(function (payload) { |
@@ -0,1 +1,24 @@ | ||
/** | ||
* makeFinalStore(alt: AltInstance): AltStore | ||
* | ||
* > Creates a `FinalStore` which is a store like any other except that it | ||
* waits for all other stores in your alt instance to emit a change before it | ||
* emits a change itself. | ||
* | ||
* Want to know when a particular dispatch has completed? This is the util | ||
* you want. | ||
* | ||
* Good for: taking a snapshot and persisting it somewhere, saving data from | ||
* a set of stores, syncing data, etc. | ||
* | ||
* Usage: | ||
* | ||
* ```js | ||
* var FinalStore = makeFinalStore(alt); | ||
* | ||
* FinalStore.listen(function () { | ||
* // all stores have now changed | ||
* }); | ||
* ``` | ||
*/ | ||
module.exports = makeFinalStore | ||
@@ -2,0 +25,0 @@ |
136778
37
2488
752