Comparing version 0.13.1 to 0.13.2
@@ -13,3 +13,2 @@ "use strict"; | ||
var ACTION_DISPATCHER = Symbol("action dispatcher storage"); | ||
var ACTION_HANDLER = Symbol("action creator handler"); | ||
@@ -50,3 +49,3 @@ var ACTION_KEY = Symbol("holds the actions uid symbol for listening"); | ||
function AltStore(dispatcher, state) { | ||
var _this = this; | ||
var _this5 = this; | ||
to5Runtime.classCallCheck(this, AltStore); | ||
@@ -64,3 +63,3 @@ | ||
var result = state[LISTENERS][payload.action](payload.data); | ||
result !== false && _this.emitChange(); | ||
result !== false && _this5.emitChange(); | ||
} | ||
@@ -113,3 +112,2 @@ }); | ||
this[ACTION_DISPATCHER] = alt.dispatcher; | ||
this[ACTION_UID] = name; | ||
@@ -124,6 +122,3 @@ this[ACTION_HANDLER] = action.bind(this); | ||
value: function dispatch(data) { | ||
this[ACTION_DISPATCHER].dispatch({ | ||
action: this[ACTION_UID], | ||
data: data | ||
}); | ||
this.alt.dispatch(this[ACTION_UID], data); | ||
}, | ||
@@ -164,3 +159,3 @@ writable: true, | ||
bindActions: function bindActions(actions) { | ||
var _this = this; | ||
var _this5 = this; | ||
Object.keys(actions).forEach(function (action) { | ||
@@ -174,15 +169,15 @@ var symbol = actions[action]; | ||
if (_this[action] && _this[assumedEventHandler]) { | ||
if (_this5[action] && _this5[assumedEventHandler]) { | ||
// If you have both action and onAction | ||
throw new ReferenceError("You have multiple action handlers bound to an action: " + ("" + action + " and " + assumedEventHandler)); | ||
} else if (_this[action]) { | ||
} else if (_this5[action]) { | ||
// action | ||
handler = _this[action]; | ||
} else if (_this[assumedEventHandler]) { | ||
handler = _this5[action]; | ||
} else if (_this5[assumedEventHandler]) { | ||
// onAction | ||
handler = _this[assumedEventHandler]; | ||
handler = _this5[assumedEventHandler]; | ||
} | ||
if (handler) { | ||
_this.bindAction(symbol, handler); | ||
_this5.bindAction(symbol, handler); | ||
} | ||
@@ -250,5 +245,12 @@ }); | ||
to5Runtime.prototypeProperties(Alt, null, { | ||
dispatch: { | ||
value: function dispatch(action, data) { | ||
this.dispatcher.dispatch({ action: action, data: data }); | ||
}, | ||
writable: true, | ||
configurable: true | ||
}, | ||
createStore: { | ||
value: function createStore(StoreModel, iden) { | ||
var _this = this; | ||
var _this5 = this; | ||
var key = iden || StoreModel.displayName || StoreModel.name; | ||
@@ -258,8 +260,16 @@ // Creating a class here so we don't overload the provided store's | ||
// so we can inherit any extensions from the provided store. | ||
function Store() { | ||
this[LIFECYCLE] = {}; | ||
this[LISTENERS] = {}; | ||
StoreModel.call(this); | ||
} | ||
Store.prototype = StoreModel.prototype; | ||
var Store = (function (StoreModel) { | ||
function Store() { | ||
to5Runtime.classCallCheck(this, Store); | ||
this[LIFECYCLE] = {}; | ||
this[LISTENERS] = {}; | ||
to5Runtime.get(Object.getPrototypeOf(Store.prototype), "constructor", this).call(this); | ||
} | ||
to5Runtime.inherits(Store, StoreModel); | ||
return Store; | ||
})(StoreModel); | ||
assign(Store.prototype, StoreMixin, { | ||
@@ -270,3 +280,3 @@ _storeName: key, | ||
getInstance: function () { | ||
return _this.stores[key]; | ||
return _this5.stores[key]; | ||
} | ||
@@ -292,3 +302,3 @@ }); | ||
value: function createActions(ActionsClass) { | ||
var _this = this; | ||
var _this5 = this; | ||
var exportObj = arguments[1] === undefined ? {} : arguments[1]; | ||
@@ -298,23 +308,37 @@ var actions = assign({}, getInternalMethods(ActionsClass.prototype, builtInProto)); | ||
function ActionsGenerator() { | ||
ActionsClass.call(this); | ||
} | ||
ActionsGenerator.prototype = ActionsClass.prototype; | ||
ActionsGenerator.prototype.generateActions = function () { | ||
for (var _len = arguments.length, actionNames = Array(_len), _key = 0; _key < _len; _key++) { | ||
actionNames[_key] = arguments[_key]; | ||
var ActionsGenerator = (function (ActionsClass) { | ||
function ActionsGenerator() { | ||
to5Runtime.classCallCheck(this, ActionsGenerator); | ||
to5Runtime.get(Object.getPrototypeOf(ActionsGenerator.prototype), "constructor", this).call(this); | ||
} | ||
actionNames.forEach(function (actionName) { | ||
// This is a function so we can later bind this to ActionCreator | ||
actions[actionName] = function (x) { | ||
for (var _len2 = arguments.length, a = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
a[_key2 - 1] = arguments[_key2]; | ||
} | ||
to5Runtime.inherits(ActionsGenerator, ActionsClass); | ||
this.dispatch(a.length ? [x].concat(a) : x); | ||
}; | ||
to5Runtime.prototypeProperties(ActionsGenerator, null, { | ||
generateActions: { | ||
value: function generateActions() { | ||
for (var _len = arguments.length, actionNames = Array(_len), _key = 0; _key < _len; _key++) { | ||
actionNames[_key] = arguments[_key]; | ||
} | ||
actionNames.forEach(function (actionName) { | ||
// This is a function so we can later bind this to ActionCreator | ||
actions[actionName] = function (x) { | ||
for (var _len2 = arguments.length, a = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
a[_key2 - 1] = arguments[_key2]; | ||
} | ||
this.dispatch(a.length ? [x].concat(a) : x); | ||
}; | ||
}); | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
}; | ||
return ActionsGenerator; | ||
})(ActionsClass); | ||
new ActionsGenerator(); | ||
@@ -327,9 +351,13 @@ | ||
// Wrap the action so we can provide a dispatch method | ||
var newAction = new ActionCreator(_this, actionName, actions[action], obj); | ||
var newAction = new ActionCreator(_this5, actionName, actions[action], obj); | ||
// Set all the properties on action | ||
obj[action] = newAction[ACTION_HANDLER]; | ||
obj[action].defer = function (x) { | ||
return setTimeout(function () { | ||
return newAction[ACTION_HANDLER](x); | ||
obj[action].defer = function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
setTimeout(function () { | ||
return newAction[ACTION_HANDLER].apply(null, args); | ||
}); | ||
@@ -336,0 +364,0 @@ }; |
120
dist/alt.js
"use strict"; | ||
var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
var _inherits = function (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; }; | ||
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; | ||
@@ -17,3 +21,2 @@ | ||
var ACTION_DISPATCHER = Symbol("action dispatcher storage"); | ||
var ACTION_HANDLER = Symbol("action creator handler"); | ||
@@ -54,3 +57,3 @@ var ACTION_KEY = Symbol("holds the actions uid symbol for listening"); | ||
function AltStore(dispatcher, state) { | ||
var _this = this; | ||
var _this5 = this; | ||
_classCallCheck(this, AltStore); | ||
@@ -68,3 +71,3 @@ | ||
var result = state[LISTENERS][payload.action](payload.data); | ||
result !== false && _this.emitChange(); | ||
result !== false && _this5.emitChange(); | ||
} | ||
@@ -117,3 +120,2 @@ }); | ||
this[ACTION_DISPATCHER] = alt.dispatcher; | ||
this[ACTION_UID] = name; | ||
@@ -128,6 +130,3 @@ this[ACTION_HANDLER] = action.bind(this); | ||
value: function dispatch(data) { | ||
this[ACTION_DISPATCHER].dispatch({ | ||
action: this[ACTION_UID], | ||
data: data | ||
}); | ||
this.alt.dispatch(this[ACTION_UID], data); | ||
}, | ||
@@ -168,3 +167,3 @@ writable: true, | ||
bindActions: function bindActions(actions) { | ||
var _this = this; | ||
var _this5 = this; | ||
Object.keys(actions).forEach(function (action) { | ||
@@ -178,15 +177,15 @@ var symbol = actions[action]; | ||
if (_this[action] && _this[assumedEventHandler]) { | ||
if (_this5[action] && _this5[assumedEventHandler]) { | ||
// If you have both action and onAction | ||
throw new ReferenceError("You have multiple action handlers bound to an action: " + ("" + action + " and " + assumedEventHandler)); | ||
} else if (_this[action]) { | ||
} else if (_this5[action]) { | ||
// action | ||
handler = _this[action]; | ||
} else if (_this[assumedEventHandler]) { | ||
handler = _this5[action]; | ||
} else if (_this5[assumedEventHandler]) { | ||
// onAction | ||
handler = _this[assumedEventHandler]; | ||
handler = _this5[assumedEventHandler]; | ||
} | ||
if (handler) { | ||
_this.bindAction(symbol, handler); | ||
_this5.bindAction(symbol, handler); | ||
} | ||
@@ -254,5 +253,12 @@ }); | ||
_prototypeProperties(Alt, null, { | ||
dispatch: { | ||
value: function dispatch(action, data) { | ||
this.dispatcher.dispatch({ action: action, data: data }); | ||
}, | ||
writable: true, | ||
configurable: true | ||
}, | ||
createStore: { | ||
value: function createStore(StoreModel, iden) { | ||
var _this = this; | ||
var _this5 = this; | ||
var key = iden || StoreModel.displayName || StoreModel.name; | ||
@@ -262,8 +268,16 @@ // Creating a class here so we don't overload the provided store's | ||
// so we can inherit any extensions from the provided store. | ||
function Store() { | ||
this[LIFECYCLE] = {}; | ||
this[LISTENERS] = {}; | ||
StoreModel.call(this); | ||
} | ||
Store.prototype = StoreModel.prototype; | ||
var Store = (function (StoreModel) { | ||
function Store() { | ||
_classCallCheck(this, Store); | ||
this[LIFECYCLE] = {}; | ||
this[LISTENERS] = {}; | ||
_get(Object.getPrototypeOf(Store.prototype), "constructor", this).call(this); | ||
} | ||
_inherits(Store, StoreModel); | ||
return Store; | ||
})(StoreModel); | ||
assign(Store.prototype, StoreMixin, { | ||
@@ -274,3 +288,3 @@ _storeName: key, | ||
getInstance: function () { | ||
return _this.stores[key]; | ||
return _this5.stores[key]; | ||
} | ||
@@ -296,3 +310,3 @@ }); | ||
value: function createActions(ActionsClass) { | ||
var _this = this; | ||
var _this5 = this; | ||
var exportObj = arguments[1] === undefined ? {} : arguments[1]; | ||
@@ -302,23 +316,37 @@ var actions = assign({}, getInternalMethods(ActionsClass.prototype, builtInProto)); | ||
function ActionsGenerator() { | ||
ActionsClass.call(this); | ||
} | ||
ActionsGenerator.prototype = ActionsClass.prototype; | ||
ActionsGenerator.prototype.generateActions = function () { | ||
for (var _len = arguments.length, actionNames = Array(_len), _key = 0; _key < _len; _key++) { | ||
actionNames[_key] = arguments[_key]; | ||
var ActionsGenerator = (function (ActionsClass) { | ||
function ActionsGenerator() { | ||
_classCallCheck(this, ActionsGenerator); | ||
_get(Object.getPrototypeOf(ActionsGenerator.prototype), "constructor", this).call(this); | ||
} | ||
actionNames.forEach(function (actionName) { | ||
// This is a function so we can later bind this to ActionCreator | ||
actions[actionName] = function (x) { | ||
for (var _len2 = arguments.length, a = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
a[_key2 - 1] = arguments[_key2]; | ||
} | ||
_inherits(ActionsGenerator, ActionsClass); | ||
this.dispatch(a.length ? [x].concat(a) : x); | ||
}; | ||
_prototypeProperties(ActionsGenerator, null, { | ||
generateActions: { | ||
value: function generateActions() { | ||
for (var _len = arguments.length, actionNames = Array(_len), _key = 0; _key < _len; _key++) { | ||
actionNames[_key] = arguments[_key]; | ||
} | ||
actionNames.forEach(function (actionName) { | ||
// This is a function so we can later bind this to ActionCreator | ||
actions[actionName] = function (x) { | ||
for (var _len2 = arguments.length, a = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
a[_key2 - 1] = arguments[_key2]; | ||
} | ||
this.dispatch(a.length ? [x].concat(a) : x); | ||
}; | ||
}); | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
}; | ||
return ActionsGenerator; | ||
})(ActionsClass); | ||
new ActionsGenerator(); | ||
@@ -331,9 +359,13 @@ | ||
// Wrap the action so we can provide a dispatch method | ||
var newAction = new ActionCreator(_this, actionName, actions[action], obj); | ||
var newAction = new ActionCreator(_this5, actionName, actions[action], obj); | ||
// Set all the properties on action | ||
obj[action] = newAction[ACTION_HANDLER]; | ||
obj[action].defer = function (x) { | ||
return setTimeout(function () { | ||
return newAction[ACTION_HANDLER](x); | ||
obj[action].defer = function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
setTimeout(function () { | ||
return newAction[ACTION_HANDLER].apply(null, args); | ||
}); | ||
@@ -340,0 +372,0 @@ }; |
{ | ||
"name": "alt", | ||
"version": "0.13.1", | ||
"version": "0.13.2", | ||
"description": "A flux implementation", | ||
@@ -5,0 +5,0 @@ "main": "dist/alt.js", |
@@ -457,3 +457,3 @@ # alt | ||
```js | ||
var ListenerMixin = require('alt/ListenerMixin') | ||
var ListenerMixin = require('alt/mixins/ListenerMixin') | ||
@@ -460,0 +460,0 @@ var LocationComponent = React.createClass({ |
@@ -14,3 +14,3 @@ "use strict"; | ||
this.generateActions("callInternalMethod", "shortHandBinary", "getInstanceInside", "dontEmit", "moreActions2", "moreActions3", "resetRecycled"); | ||
this.generateActions("callInternalMethod", "shortHandBinary", "getInstanceInside", "dontEmit", "moreActions2", "moreActions3", "resetRecycled", "asyncStoreAction"); | ||
this.generateActions("anotherAction"); | ||
@@ -80,5 +80,7 @@ } | ||
this.bindAction(myActions.dontEmit, this.dontEmitEvent); | ||
this.bindAction(myActions.asyncStoreAction, this.doStoreAsync); | ||
this.name = "first"; | ||
this.calledInternal = false; | ||
this.dontEmitEventCalled = false; | ||
this.async = false; | ||
@@ -97,2 +99,14 @@ this._dispatcher = this.dispatcher; | ||
}, { | ||
doStoreAsync: { | ||
value: function doStoreAsync() { | ||
var _this39 = this; | ||
setTimeout(function () { | ||
_this39.async = true; | ||
_this39.getInstance().emitChange(); | ||
}); | ||
return false; | ||
}, | ||
writable: true, | ||
configurable: true | ||
}, | ||
onUpdateName: { | ||
@@ -136,3 +150,3 @@ value: function onUpdateName(name) { | ||
function SecondStore() { | ||
var _this37 = this; | ||
var _this39 = this; | ||
to5Runtime.classCallCheck(this, SecondStore); | ||
@@ -151,3 +165,3 @@ | ||
this.on("init", function () { | ||
_this37.recycled = true; | ||
_this39.recycled = true; | ||
}); | ||
@@ -246,3 +260,3 @@ } | ||
var LifeCycleStore = function LifeCycleStore() { | ||
var _this37 = this; | ||
var _this39 = this; | ||
to5Runtime.classCallCheck(this, LifeCycleStore); | ||
@@ -256,12 +270,12 @@ | ||
this.on("init", function () { | ||
_this37.init = true; | ||
_this39.init = true; | ||
}); | ||
this.on("bootstrap", function () { | ||
_this37.bootstrapped = true; | ||
_this39.bootstrapped = true; | ||
}); | ||
this.on("snapshot", function () { | ||
_this37.snapshotted = true; | ||
_this39.snapshotted = true; | ||
}); | ||
this.on("rollback", function () { | ||
_this37.rollback = true; | ||
_this39.rollback = true; | ||
}); | ||
@@ -318,3 +332,3 @@ }; | ||
/* istanbul ignore next */ | ||
module.exports = { | ||
var tests = { | ||
beforeEach: function beforeEach() { | ||
@@ -474,3 +488,3 @@ alt.recycle(); | ||
"variadic actions": function variadicActions() { | ||
"letiadic actions": function letiadicActions(done) { | ||
myActions.updateTwo(4, 2); | ||
@@ -486,2 +500,10 @@ assert.equal(secondStore.getState().foo, 6, "im able to pass two params into an action"); | ||
assert.equal(secondStore.getState().foo[1], 0, "shorthand for multiple elements pass through goes as array"); | ||
myActions.shortHandBinary.defer(2, 1); | ||
setTimeout(function () { | ||
assert.equal(secondStore.getState().foo[0], 2, "shorthand for defer multiple elements pass through goes as array"); | ||
assert.equal(secondStore.getState().foo[1], 1, "shorthand for defer multiple elements pass through goes as array"); | ||
done(); | ||
}); | ||
}, | ||
@@ -651,3 +673,2 @@ | ||
try { | ||
var waiter; | ||
(function () { | ||
@@ -660,3 +681,4 @@ var WaitPlease = function WaitPlease() { | ||
waiter = alt.createActions(WaitPlease); | ||
var waiter = alt.createActions(WaitPlease); | ||
var WaitsForNobody = (function () { | ||
@@ -770,6 +792,6 @@ function WaitsForNobody() { | ||
try { | ||
var MyStore = (function () { | ||
var _MyStore = (function () { | ||
return function MyStore() {}; | ||
})(); | ||
alt.createStore(MyStore); | ||
alt.createStore(_MyStore); | ||
assert.equal(true, false, "I was able to create a store with the same name"); | ||
@@ -811,3 +833,3 @@ } catch (e) { | ||
myActions.resetRecycled(); | ||
assert.equal(secondStore.getState().recycled, false, "recycle var was reset due to action"); | ||
assert.equal(secondStore.getState().recycled, false, "recycle let was reset due to action"); | ||
alt.recycle(); | ||
@@ -973,4 +995,35 @@ assert.equal(secondStore.getState().recycled, true, "init lifecycle method was called by recycling"); | ||
assert.equal(state.b, 1, "both actions were called"); | ||
}, | ||
"dispatching from alt instance": function dispatchingFromAltInstance() { | ||
var inst = new AltInstance(); | ||
var called = false; | ||
var listen = function (x) { | ||
assert.equal(x.action, inst.getActions("myActions").updateName, "the action provided is correct"); | ||
assert.equal(x.data, "yo", "i can dispatch instances on my own"); | ||
called = true; | ||
}; | ||
var id = inst.dispatcher.register(listen); | ||
inst.dispatch(inst.getActions("myActions").updateName, "yo"); | ||
inst.dispatcher.unregister(id); | ||
assert.equal(called, true, "listener was called"); | ||
}, | ||
"emit change method works from the store": function emitChangeMethodWorksFromTheStore(done) { | ||
assert.equal(myStore.getState().async, false, "store async is false"); | ||
var listener = function () { | ||
assert.equal(myStore.getState().async, true, "store async is true"); | ||
myStore.unlisten(listener); | ||
done(); | ||
}; | ||
myStore.listen(listener); | ||
myActions.asyncStoreAction(); | ||
} | ||
}; | ||
module.exports = tests; | ||
require('6to5/runtime') | ||
var Alt = require('../dist/alt-with-runtime') | ||
var assert = require('assert') | ||
let Alt = require('../dist/alt-with-runtime') | ||
let assert = require('assert') | ||
var alt = new Alt() | ||
let alt = new Alt() | ||
@@ -17,3 +17,4 @@ class MyActions { | ||
'moreActions3', | ||
'resetRecycled' | ||
'resetRecycled', | ||
'asyncStoreAction' | ||
) | ||
@@ -49,3 +50,3 @@ this.generateActions('anotherAction') | ||
var myActions = {} | ||
let myActions = {} | ||
alt.createActions(MyActions, myActions) | ||
@@ -63,5 +64,7 @@ | ||
this.bindAction(myActions.dontEmit, this.dontEmitEvent) | ||
this.bindAction(myActions.asyncStoreAction, this.doStoreAsync) | ||
this.name = 'first' | ||
this.calledInternal = false | ||
this.dontEmitEventCalled = false | ||
this.async = false | ||
@@ -71,2 +74,10 @@ this._dispatcher = this.dispatcher | ||
doStoreAsync() { | ||
setTimeout(() => { | ||
this.async = true | ||
this.getInstance().emitChange() | ||
}) | ||
return false | ||
} | ||
onUpdateName(name) { | ||
@@ -94,3 +105,3 @@ this.name = name | ||
var myStore = alt.createStore(MyStore) | ||
let myStore = alt.createStore(MyStore) | ||
@@ -162,3 +173,3 @@ class SecondStore { | ||
var secondStore = alt.createStore(SecondStore, 'AltSecondStore') | ||
let secondStore = alt.createStore(SecondStore, 'AltSecondStore') | ||
@@ -187,3 +198,3 @@ class LifeCycleStore { | ||
var lifecycleStore = alt.createStore(LifeCycleStore) | ||
let lifecycleStore = alt.createStore(LifeCycleStore) | ||
@@ -200,8 +211,8 @@ // Alt instances... | ||
var altInstance = new AltInstance() | ||
let altInstance = new AltInstance() | ||
// Really confusing set of instances | ||
var alt1 = new Alt() | ||
var alt2 = new Alt() | ||
let alt1 = new Alt() | ||
let alt2 = new Alt() | ||
@@ -213,4 +224,4 @@ function NameActions() { } | ||
var nameActions1 = alt1.createActions(NameActions) | ||
var nameActions2 = alt2.createActions(NameActions) | ||
let nameActions1 = alt1.createActions(NameActions) | ||
let nameActions2 = alt2.createActions(NameActions) | ||
@@ -227,8 +238,8 @@ function NameStore() { | ||
var nameStore1 = alt1.createStore(NameStore) | ||
var nameStore2 = alt2.createStore(NameStore) | ||
let nameStore1 = alt1.createStore(NameStore) | ||
let nameStore2 = alt2.createStore(NameStore) | ||
/* istanbul ignore next */ | ||
module.exports = { | ||
let tests = { | ||
beforeEach() { | ||
@@ -253,4 +264,4 @@ alt.recycle() | ||
'store methods'() { | ||
var storePrototype = Object.getPrototypeOf(myStore) | ||
var assertMethods = ['constructor', 'emitChange', 'listen', 'unlisten', 'getState'] | ||
let storePrototype = Object.getPrototypeOf(myStore) | ||
let assertMethods = ['constructor', 'emitChange', 'listen', 'unlisten', 'getState'] | ||
assert.deepEqual(Object.getOwnPropertyNames(storePrototype), assertMethods, 'methods exist for store') | ||
@@ -280,6 +291,6 @@ assert.equal(typeof myStore.addListener, 'undefined', 'event emitter methods not present') | ||
'snapshots and bootstrapping'() { | ||
var initialSnapshot = alt.takeSnapshot() | ||
let initialSnapshot = alt.takeSnapshot() | ||
assert.equal(lifecycleStore.getState().snapshotted, true, 'takeSnapshot was called and the life cycle event was triggered') | ||
var bootstrapReturnValue = alt.bootstrap(initialSnapshot) | ||
let bootstrapReturnValue = alt.bootstrap(initialSnapshot) | ||
assert.equal(bootstrapReturnValue, undefined, 'bootstrap returns nothing') | ||
@@ -310,3 +321,3 @@ assert.equal(lifecycleStore.getState().bootstrapped, true, 'bootstrap was called and the life cycle event was triggered') | ||
'internal actions'() { | ||
var internalActions = myActions.justTestingInternalActions() | ||
let internalActions = myActions.justTestingInternalActions() | ||
assert.equal(typeof internalActions.updateThree, 'function', 'actions (below) are available internally through this.actions') | ||
@@ -325,3 +336,3 @@ assert.equal(typeof internalActions.updateName, 'function', 'actions (above) are available internally through this.actions') | ||
'calling actions'() { | ||
var actionReturnType = myActions.updateName('bear') | ||
let actionReturnType = myActions.updateName('bear') | ||
assert.equal(actionReturnType, undefined, 'action returns nothing') | ||
@@ -341,3 +352,3 @@ | ||
myActions.updateName('bear') | ||
var snapshot = alt.takeSnapshot() | ||
let snapshot = alt.takeSnapshot() | ||
assert.equal(typeof snapshot, 'string', 'a snapshot json is returned') | ||
@@ -353,3 +364,3 @@ assert.equal(JSON.parse(snapshot).MyStore.name, 'bear', 'the state is current') | ||
'mutation'() { | ||
var state = myStore.getState() | ||
let state = myStore.getState() | ||
state.name = 'foobar' | ||
@@ -361,3 +372,3 @@ assert.equal(state.name, 'foobar', 'mutated returned state') | ||
'rolling back'() { | ||
var rollbackValue = alt.rollback() | ||
let rollbackValue = alt.rollback() | ||
assert.equal(rollbackValue, undefined, 'rollback returns nothing') | ||
@@ -370,3 +381,3 @@ | ||
'store listening'() { | ||
var mooseChecker = (x) => { | ||
let mooseChecker = (x) => { | ||
assert.equal(x.name, 'moose', 'listener for store works') | ||
@@ -396,3 +407,3 @@ assert.equal(myStore.getState().name, 'moose', 'new store state present') | ||
'variadic actions'() { | ||
'letiadic actions'(done) { | ||
myActions.updateTwo(4, 2) | ||
@@ -408,2 +419,10 @@ assert.equal(secondStore.getState().foo, 6, 'im able to pass two params into an action') | ||
assert.equal(secondStore.getState().foo[1], 0, 'shorthand for multiple elements pass through goes as array') | ||
myActions.shortHandBinary.defer(2, 1) | ||
setTimeout(() => { | ||
assert.equal(secondStore.getState().foo[0], 2, 'shorthand for defer multiple elements pass through goes as array') | ||
assert.equal(secondStore.getState().foo[1], 1, 'shorthand for defer multiple elements pass through goes as array') | ||
done() | ||
}) | ||
}, | ||
@@ -523,3 +542,3 @@ | ||
} | ||
var waiter = alt.createActions(WaitPlease) | ||
let waiter = alt.createActions(WaitPlease) | ||
@@ -598,3 +617,3 @@ class WaitsForNobody { | ||
try { | ||
var MyStore = (function () { | ||
let MyStore = (function () { | ||
return function MyStore() { } | ||
@@ -612,3 +631,3 @@ }()) | ||
try { | ||
var mystore = (function () { | ||
let mystore = (function () { | ||
return function mystore() { } | ||
@@ -640,3 +659,3 @@ }()) | ||
myActions.resetRecycled() | ||
assert.equal(secondStore.getState().recycled, false, 'recycle var was reset due to action') | ||
assert.equal(secondStore.getState().recycled, false, 'recycle let was reset due to action') | ||
alt.recycle() | ||
@@ -648,3 +667,3 @@ assert.equal(secondStore.getState().recycled, true, 'init lifecycle method was called by recycling') | ||
myActions.updateName('goat') | ||
var flushed = JSON.parse(alt.flush()) | ||
let flushed = JSON.parse(alt.flush()) | ||
assert.equal(myStore.getState().name, 'first', 'flush is a lot like recycle') | ||
@@ -685,6 +704,6 @@ assert.equal(flushed.MyStore.name, 'goat', 'except that flush returns the state before recycling') | ||
var myActionsFromInst = altInstance.getActions('myActions') | ||
let myActionsFromInst = altInstance.getActions('myActions') | ||
assert.equal(typeof myActionsFromInst, 'object', 'the actions exist') | ||
var myActionsFail = altInstance.getActions('ActionsThatDontExist') | ||
let myActionsFail = altInstance.getActions('ActionsThatDontExist') | ||
assert.equal(typeof myActionsFail, 'undefined', 'undefined actions') | ||
@@ -708,3 +727,3 @@ | ||
'actions with the same name'() { | ||
var alt = new Alt() | ||
let alt = new Alt() | ||
@@ -714,3 +733,3 @@ function UserActions() { | ||
} | ||
var ua = alt.createActions(UserActions) | ||
let ua = alt.createActions(UserActions) | ||
@@ -720,3 +739,3 @@ function LinkActions() { | ||
} | ||
var la = alt.createActions(LinkActions) | ||
let la = alt.createActions(LinkActions) | ||
@@ -739,3 +758,3 @@ function Store() { | ||
var store = alt.createStore(Store) | ||
let store = alt.createStore(Store) | ||
@@ -745,3 +764,3 @@ ua.update() | ||
var state = store.getState() | ||
let state = store.getState() | ||
@@ -753,5 +772,5 @@ assert.equal(state.a, 1, 'both actions were called') | ||
'actions with the same name and same class name'() { | ||
var alt = new Alt() | ||
let alt = new Alt() | ||
var ua = (function () { | ||
let ua = (function () { | ||
function a() { this.generateActions('update') } | ||
@@ -761,3 +780,3 @@ return alt.createActions(a) | ||
var la = (function () { | ||
let la = (function () { | ||
function a() { this.generateActions('update') } | ||
@@ -785,3 +804,3 @@ return alt.createActions(a) | ||
var store = alt.createStore(Store) | ||
let store = alt.createStore(Store) | ||
@@ -791,7 +810,38 @@ ua.update() | ||
var state = store.getState() | ||
let state = store.getState() | ||
assert.equal(state.a, 1, 'both actions were called') | ||
assert.equal(state.b, 1, 'both actions were called') | ||
}, | ||
'dispatching from alt instance'() { | ||
let inst = new AltInstance() | ||
let called = false | ||
let listen = (x) => { | ||
assert.equal(x.action, inst.getActions('myActions').updateName, 'the action provided is correct') | ||
assert.equal(x.data, 'yo', 'i can dispatch instances on my own') | ||
called = true | ||
} | ||
let id = inst.dispatcher.register(listen) | ||
inst.dispatch(inst.getActions('myActions').updateName, 'yo') | ||
inst.dispatcher.unregister(id) | ||
assert.equal(called, true, 'listener was called') | ||
}, | ||
'emit change method works from the store'(done) { | ||
assert.equal(myStore.getState().async, false, 'store async is false') | ||
let listener = () => { | ||
assert.equal(myStore.getState().async, true, 'store async is true') | ||
myStore.unlisten(listener) | ||
done() | ||
} | ||
myStore.listen(listener) | ||
myActions.asyncStoreAction() | ||
} | ||
} | ||
export default tests |
115406
2317