Comparing version 0.16.2 to 0.17.0-alpha1
909
dist/alt.js
@@ -386,3 +386,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Alt = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
/** | ||
* Copyright (c) 2014, Facebook, Inc. | ||
* Copyright (c) 2014-2015, Facebook, Inc. | ||
* All rights reserved. | ||
@@ -735,8 +735,2 @@ * | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; | ||
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; }; })(); | ||
Object.defineProperty(exports, '__esModule', { | ||
@@ -746,9 +740,24 @@ value: true | ||
var _import = require('./symbols/symbols'); | ||
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; }; })(); | ||
var Sym = _interopRequireWildcard(_import); | ||
exports['default'] = makeAction; | ||
var ACTION_HANDLER = Sym.ACTION_HANDLER; | ||
var ACTION_UID = Sym.ACTION_UID; | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _esSymbol = require('es-symbol'); | ||
var _esSymbol2 = _interopRequireDefault(_esSymbol); | ||
var _symbolsSymbols = require('../symbols/symbols'); | ||
var Sym = _interopRequireWildcard(_symbolsSymbols); | ||
var _utilsAltUtils = require('../utils/AltUtils'); | ||
var utils = _interopRequireWildcard(_utilsAltUtils); | ||
var AltAction = (function () { | ||
@@ -758,6 +767,6 @@ function AltAction(alt, name, action, actions, actionDetails) { | ||
this[ACTION_UID] = name; | ||
this[ACTION_HANDLER] = action.bind(this); | ||
this[Sym.ACTION_UID] = name; | ||
this[Sym.ACTION_HANDLER] = action.bind(this); | ||
this.actions = actions; | ||
this.actionDetails = actionDetails; | ||
this.actions = actions; | ||
this.alt = alt; | ||
@@ -769,3 +778,3 @@ } | ||
value: function dispatch(data) { | ||
this.alt.dispatch(this[ACTION_UID], data, this.actionDetails); | ||
this.alt.dispatch(this[Sym.ACTION_UID], data, this.actionDetails); | ||
} | ||
@@ -777,14 +786,45 @@ }]); | ||
exports['default'] = AltAction; | ||
module.exports = exports['default']; | ||
function makeAction(alt, namespace, name, implementation, obj) { | ||
// make sure each Symbol is unique | ||
var actionId = utils.uid(alt[Sym.ACTIONS_REGISTRY], '' + namespace + '.' + name); | ||
alt[Sym.ACTIONS_REGISTRY][actionId] = 1; | ||
var actionSymbol = _esSymbol2['default']['for']('alt/' + actionId); | ||
},{"./symbols/symbols":9}],8:[function(require,module,exports){ | ||
'use strict'; | ||
var data = { | ||
namespace: namespace, | ||
name: name, | ||
id: actionId, | ||
symbol: actionSymbol | ||
}; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
// Wrap the action so we can provide a dispatch method | ||
var newAction = new AltAction(alt, actionSymbol, implementation, obj, data); | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; | ||
// the action itself | ||
var action = newAction[Sym.ACTION_HANDLER]; | ||
action.defer = function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
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; }; })(); | ||
setTimeout(function () { | ||
newAction[Sym.ACTION_HANDLER].apply(null, args); | ||
}); | ||
}; | ||
action[Sym.ACTION_KEY] = actionSymbol; | ||
action.data = data; | ||
// ensure each reference is unique in the namespace | ||
var container = alt.actions[namespace]; | ||
var id = utils.uid(container, name); | ||
container[id] = action; | ||
return action; | ||
} | ||
module.exports = exports['default']; | ||
},{"../symbols/symbols":11,"../utils/AltUtils":12,"es-symbol":1}],8:[function(require,module,exports){ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
@@ -794,26 +834,28 @@ value: true | ||
var _EventEmitter = require('eventemitter3'); | ||
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; }; })(); | ||
var _EventEmitter2 = _interopRequireWildcard(_EventEmitter); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
var _assign = require('object-assign'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _assign2 = _interopRequireWildcard(_assign); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _Symbol = require('es-symbol'); | ||
var _eventemitter3 = require('eventemitter3'); | ||
var _Symbol2 = _interopRequireWildcard(_Symbol); | ||
var _eventemitter32 = _interopRequireDefault(_eventemitter3); | ||
var _import = require('./symbols/symbols'); | ||
var _objectAssign = require('object-assign'); | ||
var Sym = _interopRequireWildcard(_import); | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
var ALL_LISTENERS = Sym.ALL_LISTENERS; | ||
var LIFECYCLE = Sym.LIFECYCLE; | ||
var LISTENERS = Sym.LISTENERS; | ||
var PUBLIC_METHODS = Sym.PUBLIC_METHODS; | ||
var STATE_CONTAINER = Sym.STATE_CONTAINER; | ||
var _esSymbol = require('es-symbol'); | ||
var _esSymbol2 = _interopRequireDefault(_esSymbol); | ||
var _symbolsSymbols = require('../symbols/symbols'); | ||
var Sym = _interopRequireWildcard(_symbolsSymbols); | ||
// event emitter instance | ||
var EE = _Symbol2['default'](); | ||
var EE = _esSymbol2['default'](); | ||
@@ -826,30 +868,27 @@ var AltStore = (function () { | ||
this[EE] = new _EventEmitter2['default'](); | ||
this[LIFECYCLE] = {}; | ||
this[STATE_CONTAINER] = state || model; | ||
this[EE] = new _eventemitter32['default'](); | ||
this[Sym.LIFECYCLE] = model[Sym.LIFECYCLE]; | ||
this[Sym.STATE_CONTAINER] = state || model; | ||
this._storeName = model._storeName; | ||
this.boundListeners = model[ALL_LISTENERS]; | ||
this.boundListeners = model[Sym.ALL_LISTENERS]; | ||
this.StoreModel = StoreModel; | ||
if (typeof this.StoreModel === 'object') { | ||
this.StoreModel.state = _assign2['default']({}, StoreModel.state); | ||
this.StoreModel.state = _objectAssign2['default']({}, StoreModel.state); | ||
} | ||
_assign2['default'](this[LIFECYCLE], model[LIFECYCLE]); | ||
_assign2['default'](this, model[PUBLIC_METHODS]); | ||
_objectAssign2['default'](this, model[Sym.PUBLIC_METHODS]); | ||
// Register dispatcher | ||
this.dispatchToken = alt.dispatcher.register(function (payload) { | ||
if (model[LIFECYCLE].beforeEach) { | ||
model[LIFECYCLE].beforeEach(payload, _this[STATE_CONTAINER]); | ||
} | ||
_this[Sym.LIFECYCLE].emit('beforeEach', payload, _this[Sym.STATE_CONTAINER]); | ||
if (model[LISTENERS][payload.action]) { | ||
if (model[Sym.LISTENERS][payload.action]) { | ||
var result = false; | ||
try { | ||
result = model[LISTENERS][payload.action](payload.data); | ||
result = model[Sym.LISTENERS][payload.action](payload.data); | ||
} catch (e) { | ||
if (_this[LIFECYCLE].error) { | ||
_this[LIFECYCLE].error(e, payload, _this[STATE_CONTAINER]); | ||
if (model[Sym.HANDLING_ERRORS]) { | ||
_this[Sym.LIFECYCLE].emit('error', e, payload, _this[Sym.STATE_CONTAINER]); | ||
} else { | ||
@@ -865,10 +904,6 @@ throw e; | ||
if (model[LIFECYCLE].afterEach) { | ||
model[LIFECYCLE].afterEach(payload, _this[STATE_CONTAINER]); | ||
} | ||
_this[Sym.LIFECYCLE].emit('afterEach', payload, _this[Sym.STATE_CONTAINER]); | ||
}); | ||
if (this[LIFECYCLE].init) { | ||
this[LIFECYCLE].init(); | ||
} | ||
this[Sym.LIFECYCLE].emit('init'); | ||
} | ||
@@ -884,3 +919,3 @@ | ||
value: function emitChange() { | ||
this[EE].emit('change', this[STATE_CONTAINER]); | ||
this[EE].emit('change', this[Sym.STATE_CONTAINER]); | ||
} | ||
@@ -900,5 +935,3 @@ }, { | ||
value: function unlisten(cb) { | ||
if (this[LIFECYCLE].unlisten) { | ||
this[LIFECYCLE].unlisten(); | ||
} | ||
this[Sym.LIFECYCLE].emit('unlisten'); | ||
this[EE].removeListener('change', cb); | ||
@@ -909,3 +942,3 @@ } | ||
value: function getState() { | ||
return this.StoreModel.config.getState.call(this, this[STATE_CONTAINER]); | ||
return this.StoreModel.config.getState.call(this, this[Sym.STATE_CONTAINER]); | ||
} | ||
@@ -920,7 +953,5 @@ }]); | ||
},{"./symbols/symbols":9,"es-symbol":1,"eventemitter3":2,"object-assign":6}],9:[function(require,module,exports){ | ||
},{"../symbols/symbols":11,"es-symbol":1,"eventemitter3":2,"object-assign":6}],9:[function(require,module,exports){ | ||
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
@@ -930,223 +961,75 @@ value: true | ||
var _Symbol = require('es-symbol'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
var _Symbol2 = _interopRequireWildcard(_Symbol); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
// action creator handler | ||
var ACTION_HANDLER = _Symbol2['default'](); | ||
var _esSymbol = require('es-symbol'); | ||
exports.ACTION_HANDLER = ACTION_HANDLER; | ||
// the action's uid symbol for listening | ||
var ACTION_KEY = _Symbol2['default'](); | ||
var _esSymbol2 = _interopRequireDefault(_esSymbol); | ||
exports.ACTION_KEY = ACTION_KEY; | ||
// per instance registry of actions | ||
var ACTIONS_REGISTRY = _Symbol2['default'](); | ||
var _symbolsSymbols = require('../symbols/symbols'); | ||
exports.ACTIONS_REGISTRY = ACTIONS_REGISTRY; | ||
// the action's name | ||
var ACTION_UID = _Symbol2['default'](); | ||
var Sym = _interopRequireWildcard(_symbolsSymbols); | ||
exports.ACTION_UID = ACTION_UID; | ||
// store all of a store's listeners | ||
var ALL_LISTENERS = _Symbol2['default'](); | ||
exports.ALL_LISTENERS = ALL_LISTENERS; | ||
// initial snapshot | ||
var INIT_SNAPSHOT = _Symbol2['default'](); | ||
exports.INIT_SNAPSHOT = INIT_SNAPSHOT; | ||
// last snapshot | ||
var LAST_SNAPSHOT = _Symbol2['default'](); | ||
exports.LAST_SNAPSHOT = LAST_SNAPSHOT; | ||
// all lifecycle listeners | ||
var LIFECYCLE = _Symbol2['default'](); | ||
exports.LIFECYCLE = LIFECYCLE; | ||
// store action listeners | ||
var LISTENERS = _Symbol2['default'](); | ||
exports.LISTENERS = LISTENERS; | ||
// public methods | ||
var PUBLIC_METHODS = _Symbol2['default'](); | ||
exports.PUBLIC_METHODS = PUBLIC_METHODS; | ||
// contains all state | ||
var STATE_CONTAINER = _Symbol2['default'](); | ||
exports.STATE_CONTAINER = STATE_CONTAINER; | ||
},{"es-symbol":1}],10:[function(require,module,exports){ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.getInternalMethods = getInternalMethods; | ||
exports.warn = warn; | ||
exports.uid = uid; | ||
exports.formatAsConstant = formatAsConstant; | ||
exports.dispatchIdentity = dispatchIdentity; | ||
/* istanbul ignore next */ | ||
function NoopClass() {} | ||
var builtIns = Object.getOwnPropertyNames(NoopClass); | ||
var builtInProto = Object.getOwnPropertyNames(NoopClass.prototype); | ||
function getInternalMethods(obj, isProto) { | ||
var excluded = isProto ? builtInProto : builtIns; | ||
return Object.getOwnPropertyNames(obj).reduce(function (value, m) { | ||
if (excluded.indexOf(m) !== -1) { | ||
return value; | ||
var StoreMixin = { | ||
waitFor: function waitFor() { | ||
for (var _len = arguments.length, sources = Array(_len), _key = 0; _key < _len; _key++) { | ||
sources[_key] = arguments[_key]; | ||
} | ||
value[m] = obj[m]; | ||
return value; | ||
}, {}); | ||
} | ||
function warn(msg) { | ||
/* istanbul ignore else */ | ||
if (typeof console !== 'undefined') { | ||
console.warn(new ReferenceError(msg)); | ||
} | ||
} | ||
function uid(container, name) { | ||
var count = 0; | ||
var key = name; | ||
while (Object.hasOwnProperty.call(container, key)) { | ||
key = name + String(++count); | ||
} | ||
return key; | ||
} | ||
function formatAsConstant(name) { | ||
return name.replace(/[a-z]([A-Z])/g, function (i) { | ||
return '' + i[0] + '_' + i[1].toLowerCase(); | ||
}).toUpperCase(); | ||
} | ||
function dispatchIdentity(x) { | ||
for (var _len = arguments.length, a = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
a[_key - 1] = arguments[_key]; | ||
} | ||
this.dispatch(a.length ? [x].concat(a) : x); | ||
} | ||
},{}],11:[function(require,module,exports){ | ||
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.setAppState = setAppState; | ||
exports.snapshot = snapshot; | ||
exports.saveInitialSnapshot = saveInitialSnapshot; | ||
exports.filterSnapshots = filterSnapshots; | ||
var _assign = require('object-assign'); | ||
var _assign2 = _interopRequireWildcard(_assign); | ||
var _import = require('../symbols/symbols'); | ||
var Sym = _interopRequireWildcard(_import); | ||
var INIT_SNAPSHOT = Sym.INIT_SNAPSHOT; | ||
var LAST_SNAPSHOT = Sym.LAST_SNAPSHOT; | ||
var LIFECYCLE = Sym.LIFECYCLE; | ||
var STATE_CONTAINER = Sym.STATE_CONTAINER; | ||
function setAppState(instance, data, onStore) { | ||
var obj = instance.deserialize(data); | ||
Object.keys(obj).forEach(function (key) { | ||
var store = instance.stores[key]; | ||
if (store) { | ||
var config = store.StoreModel.config; | ||
if (config.onDeserialize) { | ||
obj[key] = config.onDeserialize(obj[key]) || obj[key]; | ||
} | ||
_assign2['default'](store[STATE_CONTAINER], obj[key]); | ||
onStore(store); | ||
if (!sources.length) { | ||
throw new ReferenceError('Dispatch tokens not provided'); | ||
} | ||
}); | ||
} | ||
function snapshot(instance) { | ||
var storeNames = arguments[1] === undefined ? [] : arguments[1]; | ||
var stores = storeNames.length ? storeNames : Object.keys(instance.stores); | ||
return stores.reduce(function (obj, storeHandle) { | ||
var storeName = storeHandle.displayName || storeHandle; | ||
var store = instance.stores[storeName]; | ||
var config = store.StoreModel.config; | ||
if (store[LIFECYCLE].snapshot) { | ||
store[LIFECYCLE].snapshot(); | ||
var sourcesArray = sources; | ||
if (sources.length === 1) { | ||
sourcesArray = Array.isArray(sources[0]) ? sources[0] : sources; | ||
} | ||
var customSnapshot = config.onSerialize && config.onSerialize(store[STATE_CONTAINER]); | ||
obj[storeName] = customSnapshot ? customSnapshot : store.getState(); | ||
return obj; | ||
}, {}); | ||
} | ||
function saveInitialSnapshot(instance, key) { | ||
var state = instance.deserialize(instance.serialize(instance.stores[key][STATE_CONTAINER])); | ||
instance[INIT_SNAPSHOT][key] = state; | ||
instance[LAST_SNAPSHOT][key] = state; | ||
} | ||
var tokens = sourcesArray.map(function (source) { | ||
return source.dispatchToken || source; | ||
}); | ||
function filterSnapshots(instance, state, stores) { | ||
return stores.reduce(function (obj, store) { | ||
var storeName = store.displayName || store; | ||
if (!state[storeName]) { | ||
throw new ReferenceError('' + storeName + ' is not a valid store'); | ||
} | ||
obj[storeName] = state[storeName]; | ||
return obj; | ||
}, {}); | ||
} | ||
this.dispatcher.waitFor(tokens); | ||
}, | ||
},{"../symbols/symbols":9,"object-assign":6}],12:[function(require,module,exports){ | ||
'use strict'; | ||
exportAsync: function exportAsync(asyncMethods) { | ||
var _this = this; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
var toExport = Object.keys(asyncMethods).reduce(function (publicMethods, methodName) { | ||
var asyncSpec = asyncMethods[methodName]; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var validHandlers = ['success', 'error', 'loading']; | ||
validHandlers.forEach(function (handler) { | ||
if (asyncSpec[handler] && !asyncSpec[handler][Sym.ACTION_KEY]) { | ||
throw new Error('' + handler + ' handler must be an action function'); | ||
} | ||
}); | ||
var _Symbol = require('es-symbol'); | ||
publicMethods[methodName] = function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
var _Symbol2 = _interopRequireWildcard(_Symbol); | ||
var state = _this.getInstance().getState(); | ||
var value = asyncSpec.cache.apply(asyncSpec, [state].concat(args)); | ||
var _ACTION_KEY$ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS = require('../symbols/symbols'); | ||
// if we don't have it in cache then fetch it | ||
if (!value) { | ||
if (asyncSpec.loading) asyncSpec.loading(); | ||
asyncSpec.fetch.apply(asyncSpec, [state].concat(args)).then(asyncSpec.success)['catch'](asyncSpec.error); | ||
} else { | ||
// otherwise emit the change now | ||
_this.emitChange(); | ||
} | ||
}; | ||
var StoreMixinEssentials = { | ||
waitFor: function waitFor(sources) { | ||
if (!sources) { | ||
throw new ReferenceError('Dispatch tokens not provided'); | ||
} | ||
return publicMethods; | ||
}, {}); | ||
var sourcesArray = sources; | ||
if (arguments.length === 1) { | ||
sourcesArray = Array.isArray(sourcesArray) ? sourcesArray : [sourcesArray]; | ||
} else { | ||
sourcesArray = Array.prototype.slice.call(arguments); | ||
} | ||
var tokens = sourcesArray.map(function (source) { | ||
return source.dispatchToken || source; | ||
}); | ||
this.dispatcher.waitFor(tokens); | ||
this.exportPublicMethods(toExport); | ||
}, | ||
exportPublicMethods: function exportPublicMethods(methods) { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -1158,3 +1041,3 @@ Object.keys(methods).forEach(function (methodName) { | ||
_this[_ACTION_KEY$ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS.PUBLIC_METHODS][methodName] = methods[methodName]; | ||
_this2[Sym.PUBLIC_METHODS][methodName] = methods[methodName]; | ||
}); | ||
@@ -1165,9 +1048,9 @@ }, | ||
this.getInstance().emitChange(); | ||
} | ||
}; | ||
}, | ||
exports.StoreMixinEssentials = StoreMixinEssentials; | ||
var StoreMixinListeners = { | ||
on: function on(lifecycleEvent, handler) { | ||
this[_ACTION_KEY$ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS.LIFECYCLE][lifecycleEvent] = handler.bind(this); | ||
if (lifecycleEvent === 'error') { | ||
this[Sym.HANDLING_ERRORS] = true; | ||
} | ||
this[Sym.LIFECYCLE].on(lifecycleEvent, handler.bind(this)); | ||
}, | ||
@@ -1184,13 +1067,13 @@ | ||
if (handler.length > 1) { | ||
throw new TypeError('Action handler in store ' + this._storeName + ' for ' + ('' + (symbol[_ACTION_KEY$ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS.ACTION_KEY] || symbol).toString() + ' was defined with 2 ') + 'parameters. Only a single parameter is passed through the ' + 'dispatcher, did you mean to pass in an Object instead?'); | ||
throw new TypeError('Action handler in store ' + this._storeName + ' for ' + ('' + (symbol[Sym.ACTION_KEY] || symbol).toString() + ' was defined with ') + 'two parameters. Only a single parameter is passed through the ' + 'dispatcher, did you mean to pass in an Object instead?'); | ||
} | ||
// You can pass in the constant or the function itself | ||
var key = symbol[_ACTION_KEY$ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS.ACTION_KEY] ? symbol[_ACTION_KEY$ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS.ACTION_KEY] : symbol; | ||
this[_ACTION_KEY$ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS.LISTENERS][key] = handler.bind(this); | ||
this[_ACTION_KEY$ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS.ALL_LISTENERS].push(_Symbol2['default'].keyFor(key)); | ||
var key = symbol[Sym.ACTION_KEY] ? symbol[Sym.ACTION_KEY] : symbol; | ||
this[Sym.LISTENERS][key] = handler.bind(this); | ||
this[Sym.ALL_LISTENERS].push(_esSymbol2['default'].keyFor(key)); | ||
}, | ||
bindActions: function bindActions(actions) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -1205,15 +1088,15 @@ Object.keys(actions).forEach(function (action) { | ||
if (_this2[action] && _this2[assumedEventHandler]) { | ||
if (_this3[action] && _this3[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 (_this2[action]) { | ||
} else if (_this3[action]) { | ||
// action | ||
handler = _this2[action]; | ||
} else if (_this2[assumedEventHandler]) { | ||
handler = _this3[action]; | ||
} else if (_this3[assumedEventHandler]) { | ||
// onAction | ||
handler = _this2[assumedEventHandler]; | ||
handler = _this3[assumedEventHandler]; | ||
} | ||
if (handler) { | ||
_this2.bindAction(symbol, handler); | ||
_this3.bindAction(symbol, handler); | ||
} | ||
@@ -1224,10 +1107,10 @@ }); | ||
bindListeners: function bindListeners(obj) { | ||
var _this3 = this; | ||
var _this4 = this; | ||
Object.keys(obj).forEach(function (methodName) { | ||
var symbol = obj[methodName]; | ||
var listener = _this3[methodName]; | ||
var listener = _this4[methodName]; | ||
if (!listener) { | ||
throw new ReferenceError('' + methodName + ' defined but does not exist in ' + _this3._storeName); | ||
throw new ReferenceError('' + methodName + ' defined but does not exist in ' + _this4._storeName); | ||
} | ||
@@ -1237,29 +1120,26 @@ | ||
symbol.forEach(function (action) { | ||
_this3.bindAction(action, listener); | ||
_this4.bindAction(action, listener); | ||
}); | ||
} else { | ||
_this3.bindAction(symbol, listener); | ||
_this4.bindAction(symbol, listener); | ||
} | ||
}); | ||
} | ||
}; | ||
exports.StoreMixinListeners = StoreMixinListeners; | ||
},{"../symbols/symbols":9,"es-symbol":1}],13:[function(require,module,exports){ | ||
exports['default'] = StoreMixin; | ||
module.exports = exports['default']; | ||
},{"../symbols/symbols":11,"es-symbol":1}],10:[function(require,module,exports){ | ||
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var _bind = Function.prototype.bind; | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { desc = parent = getter = undefined; _again = false; var object = _x, | ||
property = _x2, | ||
receiver = _x3; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
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) { 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; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.createStoreConfig = createStoreConfig; | ||
@@ -1270,16 +1150,34 @@ exports.transformStore = transformStore; | ||
var _assign = require('object-assign'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
var _assign2 = _interopRequireWildcard(_assign); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _AltStore = require('../AltStore'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _AltStore2 = _interopRequireWildcard(_AltStore); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } | ||
var _getInternalMethods = require('./AltUtils'); | ||
var _objectAssign = require('object-assign'); | ||
var _StoreMixinEssentials$StoreMixinListeners = require('./StoreMixins'); | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
var _ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS$STATE_CONTAINER = require('../symbols/symbols'); | ||
var _eventemitter3 = require('eventemitter3'); | ||
var _eventemitter32 = _interopRequireDefault(_eventemitter3); | ||
var _symbolsSymbols = require('../symbols/symbols'); | ||
var Sym = _interopRequireWildcard(_symbolsSymbols); | ||
var _utilsAltUtils = require('../utils/AltUtils'); | ||
var utils = _interopRequireWildcard(_utilsAltUtils); | ||
var _AltStore = require('./AltStore'); | ||
var _AltStore2 = _interopRequireDefault(_AltStore); | ||
var _StoreMixin = require('./StoreMixin'); | ||
var _StoreMixin2 = _interopRequireDefault(_StoreMixin); | ||
function doSetState(store, storeInstance, state) { | ||
@@ -1292,5 +1190,5 @@ if (!state) { | ||
var nextState = typeof state === 'function' ? state(storeInstance[_ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS$STATE_CONTAINER.STATE_CONTAINER]) : state; | ||
var nextState = typeof state === 'function' ? state(storeInstance[Sym.STATE_CONTAINER]) : state; | ||
storeInstance[_ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS$STATE_CONTAINER.STATE_CONTAINER] = config.setState.call(store, storeInstance[_ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS$STATE_CONTAINER.STATE_CONTAINER], nextState); | ||
storeInstance[Sym.STATE_CONTAINER] = config.setState.call(store, storeInstance[Sym.STATE_CONTAINER], nextState); | ||
@@ -1302,4 +1200,17 @@ if (!store.alt.dispatcher.isDispatching()) { | ||
function createPrototype(proto, alt, key, extras) { | ||
proto[Sym.ALL_LISTENERS] = []; | ||
proto[Sym.LIFECYCLE] = new _eventemitter32['default'](); | ||
proto[Sym.LISTENERS] = {}; | ||
proto[Sym.PUBLIC_METHODS] = {}; | ||
return _objectAssign2['default'](proto, _StoreMixin2['default'], { | ||
_storeName: key, | ||
alt: alt, | ||
dispatcher: alt.dispatcher | ||
}, extras); | ||
} | ||
function createStoreConfig(globalConfig, StoreModel) { | ||
StoreModel.config = _assign2['default']({ | ||
StoreModel.config = _objectAssign2['default']({ | ||
getState: function getState(state) { | ||
@@ -1311,3 +1222,3 @@ return Object.keys(state).reduce(function (obj, key) { | ||
}, | ||
setState: _assign2['default'] | ||
setState: _objectAssign2['default'] | ||
}, globalConfig, StoreModel.config); | ||
@@ -1325,11 +1236,3 @@ } | ||
var StoreProto = {}; | ||
StoreProto[_ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS$STATE_CONTAINER.ALL_LISTENERS] = []; | ||
StoreProto[_ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS$STATE_CONTAINER.LIFECYCLE] = {}; | ||
StoreProto[_ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS$STATE_CONTAINER.LISTENERS] = {}; | ||
_assign2['default'](StoreProto, { | ||
_storeName: key, | ||
alt: alt, | ||
dispatcher: alt.dispatcher, | ||
var StoreProto = createPrototype({}, alt, key, _objectAssign2['default']({ | ||
getInstance: function getInstance() { | ||
@@ -1341,3 +1244,3 @@ return storeInstance; | ||
} | ||
}, _StoreMixinEssentials$StoreMixinListeners.StoreMixinListeners, _StoreMixinEssentials$StoreMixinListeners.StoreMixinEssentials, StoreModel); | ||
}, StoreModel)); | ||
@@ -1347,3 +1250,3 @@ // bind the store listeners | ||
if (StoreProto.bindListeners) { | ||
_StoreMixinEssentials$StoreMixinListeners.StoreMixinListeners.bindListeners.call(StoreProto, StoreProto.bindListeners); | ||
_StoreMixin2['default'].bindListeners.call(StoreProto, StoreProto.bindListeners); | ||
} | ||
@@ -1355,3 +1258,3 @@ | ||
Object.keys(StoreProto.lifecycle).forEach(function (event) { | ||
_StoreMixinEssentials$StoreMixinListeners.StoreMixinListeners.on.call(StoreProto, event, StoreProto.lifecycle[event]); | ||
_StoreMixin2['default'].on.call(StoreProto, event, StoreProto.lifecycle[event]); | ||
}); | ||
@@ -1361,3 +1264,3 @@ } | ||
// create the instance and assign the public methods to the instance | ||
storeInstance = _assign2['default'](new _AltStore2['default'](alt, StoreProto, StoreProto.state, StoreModel), StoreProto.publicMethods, { displayName: key }); | ||
storeInstance = _objectAssign2['default'](new _AltStore2['default'](alt, StoreProto, StoreProto.state, StoreModel), StoreProto.publicMethods, { displayName: key }); | ||
@@ -1395,6 +1298,3 @@ return storeInstance; | ||
_assign2['default'](Store.prototype, _StoreMixinEssentials$StoreMixinListeners.StoreMixinListeners, _StoreMixinEssentials$StoreMixinListeners.StoreMixinEssentials, { | ||
_storeName: key, | ||
alt: alt, | ||
dispatcher: alt.dispatcher, | ||
createPrototype(Store.prototype, alt, key, { | ||
getInstance: function getInstance() { | ||
@@ -1408,119 +1308,258 @@ return storeInstance; | ||
Store.prototype[_ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS$STATE_CONTAINER.ALL_LISTENERS] = []; | ||
Store.prototype[_ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS$STATE_CONTAINER.LIFECYCLE] = {}; | ||
Store.prototype[_ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS$STATE_CONTAINER.LISTENERS] = {}; | ||
Store.prototype[_ALL_LISTENERS$LIFECYCLE$LISTENERS$PUBLIC_METHODS$STATE_CONTAINER.PUBLIC_METHODS] = {}; | ||
var store = new (_bind.apply(Store, [null].concat(argsForClass)))(); | ||
storeInstance = _assign2['default'](new _AltStore2['default'](alt, store, store[alt.config.stateKey] || store[config.stateKey] || null, StoreModel), _getInternalMethods.getInternalMethods(StoreModel), { displayName: key }); | ||
if (config.bindListeners) { | ||
store.bindListeners(config.bindListeners); | ||
} | ||
if (config.datasource) { | ||
store.exportAsync(config.datasource); | ||
} | ||
storeInstance = _objectAssign2['default'](new _AltStore2['default'](alt, store, store[alt.config.stateKey] || store[config.stateKey] || null, StoreModel), utils.getInternalMethods(StoreModel), config.publicMethods, { displayName: key }); | ||
return storeInstance; | ||
} | ||
},{"../AltStore":8,"../symbols/symbols":9,"./AltUtils":10,"./StoreMixins":12,"object-assign":6}],14:[function(require,module,exports){ | ||
},{"../symbols/symbols":11,"../utils/AltUtils":12,"./AltStore":8,"./StoreMixin":9,"eventemitter3":2,"object-assign":6}],11:[function(require,module,exports){ | ||
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports['default'] = makeAction; | ||
var _import = require('../symbols/symbols'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var Sym = _interopRequireWildcard(_import); | ||
var _esSymbol = require('es-symbol'); | ||
var _Symbol = require('es-symbol'); | ||
var _esSymbol2 = _interopRequireDefault(_esSymbol); | ||
var _Symbol2 = _interopRequireWildcard(_Symbol); | ||
// action creator handler | ||
var ACTION_HANDLER = _esSymbol2['default'](); | ||
var _AltAction = require('../AltAction'); | ||
exports.ACTION_HANDLER = ACTION_HANDLER; | ||
// the action's uid symbol for listening | ||
var ACTION_KEY = _esSymbol2['default'](); | ||
var _AltAction2 = _interopRequireWildcard(_AltAction); | ||
exports.ACTION_KEY = ACTION_KEY; | ||
// per instance registry of actions | ||
var ACTIONS_REGISTRY = _esSymbol2['default'](); | ||
var _uid = require('./AltUtils'); | ||
exports.ACTIONS_REGISTRY = ACTIONS_REGISTRY; | ||
// the action's name | ||
var ACTION_UID = _esSymbol2['default'](); | ||
var ACTION_KEY = Sym.ACTION_KEY; | ||
var ACTION_HANDLER = Sym.ACTION_HANDLER; | ||
var ACTIONS_REGISTRY = Sym.ACTIONS_REGISTRY; | ||
exports.ACTION_UID = ACTION_UID; | ||
// store all of a store's listeners | ||
var ALL_LISTENERS = _esSymbol2['default'](); | ||
function makeAction(alt, namespace, name, implementation, obj) { | ||
// make sure each Symbol is unique | ||
var actionId = _uid.uid(alt[ACTIONS_REGISTRY], '' + namespace + '.' + name); | ||
alt[ACTIONS_REGISTRY][actionId] = 1; | ||
var actionSymbol = _Symbol2['default']['for']('alt/' + actionId); | ||
exports.ALL_LISTENERS = ALL_LISTENERS; | ||
// are we handling our own errors | ||
var HANDLING_ERRORS = _esSymbol2['default'](); | ||
var data = { | ||
namespace: namespace, | ||
name: name, | ||
id: actionId, | ||
symbol: actionSymbol | ||
}; | ||
exports.HANDLING_ERRORS = HANDLING_ERRORS; | ||
// initial snapshot | ||
var INIT_SNAPSHOT = _esSymbol2['default'](); | ||
// Wrap the action so we can provide a dispatch method | ||
var newAction = new _AltAction2['default'](alt, actionSymbol, implementation, obj, data); | ||
exports.INIT_SNAPSHOT = INIT_SNAPSHOT; | ||
// last snapshot | ||
var LAST_SNAPSHOT = _esSymbol2['default'](); | ||
// the action itself | ||
var action = newAction[ACTION_HANDLER]; | ||
action.defer = function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
exports.LAST_SNAPSHOT = LAST_SNAPSHOT; | ||
// all lifecycle listeners | ||
var LIFECYCLE = _esSymbol2['default'](); | ||
exports.LIFECYCLE = LIFECYCLE; | ||
// store action listeners | ||
var LISTENERS = _esSymbol2['default'](); | ||
exports.LISTENERS = LISTENERS; | ||
// public methods | ||
var PUBLIC_METHODS = _esSymbol2['default'](); | ||
exports.PUBLIC_METHODS = PUBLIC_METHODS; | ||
// contains all state | ||
var STATE_CONTAINER = _esSymbol2['default'](); | ||
exports.STATE_CONTAINER = STATE_CONTAINER; | ||
},{"es-symbol":1}],12:[function(require,module,exports){ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.getInternalMethods = getInternalMethods; | ||
exports.warn = warn; | ||
exports.uid = uid; | ||
exports.formatAsConstant = formatAsConstant; | ||
exports.dispatchIdentity = dispatchIdentity; | ||
/* istanbul ignore next */ | ||
function NoopClass() {} | ||
var builtIns = Object.getOwnPropertyNames(NoopClass); | ||
var builtInProto = Object.getOwnPropertyNames(NoopClass.prototype); | ||
function getInternalMethods(Obj, isProto) { | ||
var excluded = isProto ? builtInProto : builtIns; | ||
var obj = isProto ? Obj.prototype : Obj; | ||
return Object.getOwnPropertyNames(obj).reduce(function (value, m) { | ||
if (excluded.indexOf(m) !== -1) { | ||
return value; | ||
} | ||
setTimeout(function () { | ||
newAction[ACTION_HANDLER].apply(null, args); | ||
}); | ||
}; | ||
action[ACTION_KEY] = actionSymbol; | ||
action.data = data; | ||
value[m] = obj[m]; | ||
return value; | ||
}, {}); | ||
} | ||
// ensure each reference is unique in the namespace | ||
var container = alt.actions[namespace]; | ||
var id = _uid.uid(container, name); | ||
container[id] = action; | ||
function warn(msg) { | ||
/* istanbul ignore else */ | ||
if (typeof console !== 'undefined') { | ||
console.warn(new ReferenceError(msg)); | ||
} | ||
} | ||
return action; | ||
function uid(container, name) { | ||
var count = 0; | ||
var key = name; | ||
while (Object.hasOwnProperty.call(container, key)) { | ||
key = name + String(++count); | ||
} | ||
return key; | ||
} | ||
module.exports = exports['default']; | ||
function formatAsConstant(name) { | ||
return name.replace(/[a-z]([A-Z])/g, function (i) { | ||
return '' + i[0] + '_' + i[1].toLowerCase(); | ||
}).toUpperCase(); | ||
} | ||
},{"../AltAction":7,"../symbols/symbols":9,"./AltUtils":10,"es-symbol":1}],15:[function(require,module,exports){ | ||
function dispatchIdentity(x) { | ||
for (var _len = arguments.length, a = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
a[_key - 1] = arguments[_key]; | ||
} | ||
this.dispatch(a.length ? [x].concat(a) : x); | ||
} | ||
},{}],13:[function(require,module,exports){ | ||
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.setAppState = setAppState; | ||
exports.snapshot = snapshot; | ||
exports.saveInitialSnapshot = saveInitialSnapshot; | ||
exports.filterSnapshots = filterSnapshots; | ||
var _bind = Function.prototype.bind; | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
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) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
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 _objectAssign = require('object-assign'); | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
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; }; })(); | ||
var _symbolsSymbols = require('../symbols/symbols'); | ||
var Sym = _interopRequireWildcard(_symbolsSymbols); | ||
function setAppState(instance, data, onStore) { | ||
var obj = instance.deserialize(data); | ||
Object.keys(obj).forEach(function (key) { | ||
var store = instance.stores[key]; | ||
if (store) { | ||
var config = store.StoreModel.config; | ||
if (config.onDeserialize) { | ||
obj[key] = config.onDeserialize(obj[key]) || obj[key]; | ||
} | ||
_objectAssign2['default'](store[Sym.STATE_CONTAINER], obj[key]); | ||
onStore(store); | ||
} | ||
}); | ||
} | ||
function snapshot(instance) { | ||
var storeNames = arguments[1] === undefined ? [] : arguments[1]; | ||
var stores = storeNames.length ? storeNames : Object.keys(instance.stores); | ||
return stores.reduce(function (obj, storeHandle) { | ||
var storeName = storeHandle.displayName || storeHandle; | ||
var store = instance.stores[storeName]; | ||
var config = store.StoreModel.config; | ||
store[Sym.LIFECYCLE].emit('snapshot'); | ||
var customSnapshot = config.onSerialize && config.onSerialize(store[Sym.STATE_CONTAINER]); | ||
obj[storeName] = customSnapshot ? customSnapshot : store.getState(); | ||
return obj; | ||
}, {}); | ||
} | ||
function saveInitialSnapshot(instance, key) { | ||
var state = instance.deserialize(instance.serialize(instance.stores[key][Sym.STATE_CONTAINER])); | ||
instance[Sym.INIT_SNAPSHOT][key] = state; | ||
instance[Sym.LAST_SNAPSHOT][key] = state; | ||
} | ||
function filterSnapshots(instance, state, stores) { | ||
return stores.reduce(function (obj, store) { | ||
var storeName = store.displayName || store; | ||
if (!state[storeName]) { | ||
throw new ReferenceError('' + storeName + ' is not a valid store'); | ||
} | ||
obj[storeName] = state[storeName]; | ||
return obj; | ||
}, {}); | ||
} | ||
},{"../symbols/symbols":11,"object-assign":6}],14:[function(require,module,exports){ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var _bind = Function.prototype.bind; | ||
var _assign = require('object-assign'); | ||
var _get = function get(_x3, _x4, _x5) { var _again = true; _function: while (_again) { desc = parent = getter = undefined; _again = false; var object = _x3, | ||
property = _x4, | ||
receiver = _x5; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x3 = parent; _x4 = property; _x5 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
var _assign2 = _interopRequireWildcard(_assign); | ||
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; }; })(); | ||
var _Dispatcher = require('flux'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
var _makeAction = require('./utils/makeAction'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _makeAction2 = _interopRequireWildcard(_makeAction); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } | ||
var _filterSnapshots$saveInitialSnapshot$setAppState$snapshot = require('./utils/StateFunctions'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore = require('./utils/StoreUtils'); | ||
var _objectAssign = require('object-assign'); | ||
var _ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE = require('./symbols/symbols'); | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
var _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn = require('./utils/AltUtils'); | ||
var _flux = require('flux'); | ||
var _utilsStateFunctions = require('./utils/StateFunctions'); | ||
var StateFunctions = _interopRequireWildcard(_utilsStateFunctions); | ||
var _symbolsSymbols = require('./symbols/symbols'); | ||
var Sym = _interopRequireWildcard(_symbolsSymbols); | ||
var _store = require('./store'); | ||
var store = _interopRequireWildcard(_store); | ||
var _utilsAltUtils = require('./utils/AltUtils'); | ||
var utils = _interopRequireWildcard(_utilsAltUtils); | ||
var _actions = require('./actions'); | ||
var _actions2 = _interopRequireDefault(_actions); | ||
var Alt = (function () { | ||
@@ -1535,9 +1574,9 @@ function Alt() { | ||
this.deserialize = config.deserialize || JSON.parse; | ||
this.dispatcher = config.dispatcher || new _Dispatcher.Dispatcher(); | ||
this.dispatcher = config.dispatcher || new _flux.Dispatcher(); | ||
this.actions = { global: {} }; | ||
this.stores = {}; | ||
this.storeTransforms = config.storeTransforms || []; | ||
this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.ACTIONS_REGISTRY] = {}; | ||
this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.INIT_SNAPSHOT] = {}; | ||
this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LAST_SNAPSHOT] = {}; | ||
this[Sym.ACTIONS_REGISTRY] = {}; | ||
this[Sym.INIT_SNAPSHOT] = {}; | ||
this[Sym.LAST_SNAPSHOT] = {}; | ||
} | ||
@@ -1558,6 +1597,6 @@ | ||
var key = StoreModel.displayName || ''; | ||
_createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreConfig(this.config, StoreModel); | ||
var Store = _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.transformStore(this.storeTransforms, StoreModel); | ||
store.createStoreConfig(this.config, StoreModel); | ||
var Store = store.transformStore(this.storeTransforms, StoreModel); | ||
return typeof Store === 'object' ? _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreFromObject(this, Store, key) : _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreFromClass.apply(undefined, [this, Store, key].concat(args)); | ||
return typeof Store === 'object' ? store.createStoreFromObject(this, Store, key) : store.createStoreFromClass.apply(store, [this, Store, key].concat(args)); | ||
} | ||
@@ -1572,19 +1611,19 @@ }, { | ||
var key = iden || StoreModel.displayName || StoreModel.name || ''; | ||
_createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreConfig(this.config, StoreModel); | ||
var Store = _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.transformStore(this.storeTransforms, StoreModel); | ||
store.createStoreConfig(this.config, StoreModel); | ||
var Store = store.transformStore(this.storeTransforms, StoreModel); | ||
if (this.stores[key] || !key) { | ||
if (this.stores[key]) { | ||
_dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.warn('A store named ' + key + ' already exists, double check your store ' + 'names or pass in your own custom identifier for each store'); | ||
utils.warn('A store named ' + key + ' already exists, double check your store ' + 'names or pass in your own custom identifier for each store'); | ||
} else { | ||
_dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.warn('Store name was not specified'); | ||
utils.warn('Store name was not specified'); | ||
} | ||
key = _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.uid(this.stores, key); | ||
key = utils.uid(this.stores, key); | ||
} | ||
var storeInstance = typeof Store === 'object' ? _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreFromObject(this, Store, key) : _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreFromClass.apply(undefined, [this, Store, key].concat(args)); | ||
var storeInstance = typeof Store === 'object' ? store.createStoreFromObject(this, Store, key) : store.createStoreFromClass.apply(store, [this, Store, key].concat(args)); | ||
this.stores[key] = storeInstance; | ||
_filterSnapshots$saveInitialSnapshot$setAppState$snapshot.saveInitialSnapshot(this, key); | ||
StateFunctions.saveInitialSnapshot(this, key); | ||
@@ -1602,3 +1641,3 @@ return storeInstance; | ||
return this.createActions(actionNames.reduce(function (obj, action) { | ||
obj[action] = _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.dispatchIdentity; | ||
obj[action] = utils.dispatchIdentity; | ||
return obj; | ||
@@ -1610,3 +1649,3 @@ }, actions)); | ||
value: function createAction(name, implementation, obj) { | ||
return _makeAction2['default'](this, 'global', name, implementation, obj); | ||
return _actions2['default'](this, 'global', name, implementation, obj); | ||
} | ||
@@ -1616,3 +1655,3 @@ }, { | ||
value: function createActions(ActionsClass) { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -1626,7 +1665,7 @@ for (var _len4 = arguments.length, argsForConstructor = Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) { | ||
var actions = {}; | ||
var key = _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.uid(this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.ACTIONS_REGISTRY], ActionsClass.displayName || ActionsClass.name || 'Unknown'); | ||
var key = utils.uid(this[Sym.ACTIONS_REGISTRY], ActionsClass.displayName || ActionsClass.name || 'Unknown'); | ||
if (typeof ActionsClass === 'function') { | ||
(function () { | ||
_assign2['default'](actions, _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.getInternalMethods(ActionsClass.prototype, true)); | ||
_objectAssign2['default'](actions, utils.getInternalMethods(ActionsClass, true)); | ||
@@ -1654,3 +1693,3 @@ var ActionsGenerator = (function (_ActionsClass) { | ||
actionNames.forEach(function (actionName) { | ||
actions[actionName] = _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.dispatchIdentity; | ||
actions[actionName] = utils.dispatchIdentity; | ||
}); | ||
@@ -1663,6 +1702,6 @@ } | ||
_assign2['default'](actions, new (_bind.apply(ActionsGenerator, [null].concat(argsForConstructor)))()); | ||
_objectAssign2['default'](actions, new (_bind.apply(ActionsGenerator, [null].concat(argsForConstructor)))()); | ||
})(); | ||
} else { | ||
_assign2['default'](actions, ActionsClass); | ||
_objectAssign2['default'](actions, ActionsClass); | ||
} | ||
@@ -1678,7 +1717,7 @@ | ||
// create the action | ||
obj[action] = _makeAction2['default'](_this, key, action, actions[action], obj); | ||
obj[action] = _actions2['default'](_this2, key, action, actions[action], obj); | ||
// generate a constant | ||
var constant = _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.formatAsConstant(action); | ||
obj[constant] = obj[action][_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.ACTION_KEY]; | ||
var constant = utils.formatAsConstant(action); | ||
obj[constant] = obj[action][Sym.ACTION_KEY]; | ||
@@ -1695,4 +1734,4 @@ return obj; | ||
var state = _filterSnapshots$saveInitialSnapshot$setAppState$snapshot.snapshot(this, storeNames); | ||
_assign2['default'](this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LAST_SNAPSHOT], state); | ||
var state = StateFunctions.snapshot(this, storeNames); | ||
_objectAssign2['default'](this[Sym.LAST_SNAPSHOT], state); | ||
return this.serialize(state); | ||
@@ -1703,7 +1742,5 @@ } | ||
value: function rollback() { | ||
_filterSnapshots$saveInitialSnapshot$setAppState$snapshot.setAppState(this, this.serialize(this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LAST_SNAPSHOT]), function (store) { | ||
if (store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].rollback) { | ||
store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].rollback(); | ||
} | ||
store.emitChange(); | ||
StateFunctions.setAppState(this, this.serialize(this[Sym.LAST_SNAPSHOT]), function (storeInst) { | ||
storeInst[Sym.LIFECYCLE].emit('rollback'); | ||
storeInst.emitChange(); | ||
}); | ||
@@ -1718,9 +1755,7 @@ } | ||
var initialSnapshot = storeNames.length ? _filterSnapshots$saveInitialSnapshot$setAppState$snapshot.filterSnapshots(this, this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.INIT_SNAPSHOT], storeNames) : this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.INIT_SNAPSHOT]; | ||
var initialSnapshot = storeNames.length ? StateFunctions.filterSnapshots(this, this[Sym.INIT_SNAPSHOT], storeNames) : this[Sym.INIT_SNAPSHOT]; | ||
_filterSnapshots$saveInitialSnapshot$setAppState$snapshot.setAppState(this, this.serialize(initialSnapshot), function (store) { | ||
if (store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].init) { | ||
store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].init(); | ||
} | ||
store.emitChange(); | ||
StateFunctions.setAppState(this, this.serialize(initialSnapshot), function (storeInst) { | ||
storeInst[Sym.LIFECYCLE].emit('init'); | ||
storeInst.emitChange(); | ||
}); | ||
@@ -1731,3 +1766,3 @@ } | ||
value: function flush() { | ||
var state = this.serialize(_filterSnapshots$saveInitialSnapshot$setAppState$snapshot.snapshot(this)); | ||
var state = this.serialize(StateFunctions.snapshot(this)); | ||
this.recycle(); | ||
@@ -1739,7 +1774,5 @@ return state; | ||
value: function bootstrap(data) { | ||
_filterSnapshots$saveInitialSnapshot$setAppState$snapshot.setAppState(this, data, function (store) { | ||
if (store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].bootstrap) { | ||
store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].bootstrap(); | ||
} | ||
store.emitChange(); | ||
StateFunctions.setAppState(this, data, function (storeInst) { | ||
storeInst[Sym.LIFECYCLE].emit('bootstrap'); | ||
storeInst.emitChange(); | ||
}); | ||
@@ -1749,8 +1782,8 @@ } | ||
key: 'prepare', | ||
value: function prepare(store, payload) { | ||
value: function prepare(storeInst, payload) { | ||
var data = {}; | ||
if (!store._storeName) { | ||
if (!storeInst.displayName) { | ||
throw new ReferenceError('Store provided does not have a name'); | ||
} | ||
data[store._storeName] = payload; | ||
data[storeInst.displayName] = payload; | ||
return this.serialize(data); | ||
@@ -1797,3 +1830,3 @@ } | ||
},{"./symbols/symbols":9,"./utils/AltUtils":10,"./utils/StateFunctions":11,"./utils/StoreUtils":13,"./utils/makeAction":14,"flux":3,"object-assign":6}]},{},[15])(15) | ||
},{"./actions":7,"./store":10,"./symbols/symbols":11,"./utils/AltUtils":12,"./utils/StateFunctions":13,"flux":3,"object-assign":6}]},{},[14])(14) | ||
}); |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
@@ -9,55 +7,57 @@ value: true | ||
var _Alt = require('./'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _Alt2 = _interopRequireWildcard(_Alt); | ||
var _ = require('./'); | ||
var _ActionListeners = require('../utils/ActionListeners'); | ||
var _2 = _interopRequireDefault(_); | ||
var _ActionListeners2 = _interopRequireWildcard(_ActionListeners); | ||
var _utilsActionListeners = require('../utils/ActionListeners'); | ||
var _AltManager = require('../utils/AltManager'); | ||
var _utilsActionListeners2 = _interopRequireDefault(_utilsActionListeners); | ||
var _AltManager2 = _interopRequireWildcard(_AltManager); | ||
var _utilsAltManager = require('../utils/AltManager'); | ||
var _DispatcherRecorder = require('../utils/DispatcherRecorder'); | ||
var _utilsAltManager2 = _interopRequireDefault(_utilsAltManager); | ||
var _DispatcherRecorder2 = _interopRequireWildcard(_DispatcherRecorder); | ||
var _utilsDispatcherRecorder = require('../utils/DispatcherRecorder'); | ||
var _atomic = require('../utils/atomic'); | ||
var _utilsDispatcherRecorder2 = _interopRequireDefault(_utilsDispatcherRecorder); | ||
var _atomic2 = _interopRequireWildcard(_atomic); | ||
var _utilsAtomic = require('../utils/atomic'); | ||
var _connectToStores = require('../utils/connectToStores'); | ||
var _utilsAtomic2 = _interopRequireDefault(_utilsAtomic); | ||
var _connectToStores2 = _interopRequireWildcard(_connectToStores); | ||
var _utilsConnectToStores = require('../utils/connectToStores'); | ||
var _chromeDebug = require('../utils/chromeDebug'); | ||
var _utilsConnectToStores2 = _interopRequireDefault(_utilsConnectToStores); | ||
var _chromeDebug2 = _interopRequireWildcard(_chromeDebug); | ||
var _utilsChromeDebug = require('../utils/chromeDebug'); | ||
var _makeFinalStore = require('../utils/makeFinalStore'); | ||
var _utilsChromeDebug2 = _interopRequireDefault(_utilsChromeDebug); | ||
var _makeFinalStore2 = _interopRequireWildcard(_makeFinalStore); | ||
var _utilsMakeFinalStore = require('../utils/makeFinalStore'); | ||
var _withAltContext = require('../utils/withAltContext'); | ||
var _utilsMakeFinalStore2 = _interopRequireDefault(_utilsMakeFinalStore); | ||
var _withAltContext2 = _interopRequireWildcard(_withAltContext); | ||
var _utilsWithAltContext = require('../utils/withAltContext'); | ||
var _utilsWithAltContext2 = _interopRequireDefault(_utilsWithAltContext); | ||
var _AltContainer = require('../../AltContainer'); | ||
var _AltContainer2 = _interopRequireWildcard(_AltContainer); | ||
var _AltContainer2 = _interopRequireDefault(_AltContainer); | ||
_Alt2['default'].addons = { | ||
ActionListeners: _ActionListeners2['default'], | ||
_2['default'].addons = { | ||
ActionListeners: _utilsActionListeners2['default'], | ||
AltContainer: _AltContainer2['default'], | ||
AltManager: _AltManager2['default'], | ||
DispatcherRecorder: _DispatcherRecorder2['default'], | ||
atomic: _atomic2['default'], | ||
chromeDebug: _chromeDebug2['default'], | ||
connectToStores: _connectToStores2['default'], | ||
makeFinalStore: _makeFinalStore2['default'], | ||
withAltContext: _withAltContext2['default'] | ||
AltManager: _utilsAltManager2['default'], | ||
DispatcherRecorder: _utilsDispatcherRecorder2['default'], | ||
atomic: _utilsAtomic2['default'], | ||
chromeDebug: _utilsChromeDebug2['default'], | ||
connectToStores: _utilsConnectToStores2['default'], | ||
makeFinalStore: _utilsMakeFinalStore2['default'], | ||
withAltContext: _utilsWithAltContext2['default'] | ||
}; | ||
exports['default'] = _Alt2['default']; | ||
exports['default'] = _2['default']; | ||
module.exports = exports['default']; |
135
lib/index.js
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var _bind = Function.prototype.bind; | ||
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) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
var _get = function get(_x3, _x4, _x5) { var _again = true; _function: while (_again) { desc = parent = getter = undefined; _again = false; var object = _x3, | ||
property = _x4, | ||
receiver = _x5; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x3 = parent; _x4 = property; _x5 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
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 _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; }; })(); | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } | ||
var _assign = require('object-assign'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _assign2 = _interopRequireWildcard(_assign); | ||
var _objectAssign = require('object-assign'); | ||
var _Dispatcher = require('flux'); | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
var _makeAction = require('./utils/makeAction'); | ||
var _flux = require('flux'); | ||
var _makeAction2 = _interopRequireWildcard(_makeAction); | ||
var _utilsStateFunctions = require('./utils/StateFunctions'); | ||
var _filterSnapshots$saveInitialSnapshot$setAppState$snapshot = require('./utils/StateFunctions'); | ||
var StateFunctions = _interopRequireWildcard(_utilsStateFunctions); | ||
var _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore = require('./utils/StoreUtils'); | ||
var _symbolsSymbols = require('./symbols/symbols'); | ||
var _ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE = require('./symbols/symbols'); | ||
var Sym = _interopRequireWildcard(_symbolsSymbols); | ||
var _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn = require('./utils/AltUtils'); | ||
var _store = require('./store'); | ||
var store = _interopRequireWildcard(_store); | ||
var _utilsAltUtils = require('./utils/AltUtils'); | ||
var utils = _interopRequireWildcard(_utilsAltUtils); | ||
var _actions = require('./actions'); | ||
var _actions2 = _interopRequireDefault(_actions); | ||
var Alt = (function () { | ||
@@ -46,9 +57,9 @@ function Alt() { | ||
this.deserialize = config.deserialize || JSON.parse; | ||
this.dispatcher = config.dispatcher || new _Dispatcher.Dispatcher(); | ||
this.dispatcher = config.dispatcher || new _flux.Dispatcher(); | ||
this.actions = { global: {} }; | ||
this.stores = {}; | ||
this.storeTransforms = config.storeTransforms || []; | ||
this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.ACTIONS_REGISTRY] = {}; | ||
this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.INIT_SNAPSHOT] = {}; | ||
this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LAST_SNAPSHOT] = {}; | ||
this[Sym.ACTIONS_REGISTRY] = {}; | ||
this[Sym.INIT_SNAPSHOT] = {}; | ||
this[Sym.LAST_SNAPSHOT] = {}; | ||
} | ||
@@ -69,6 +80,6 @@ | ||
var key = StoreModel.displayName || ''; | ||
_createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreConfig(this.config, StoreModel); | ||
var Store = _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.transformStore(this.storeTransforms, StoreModel); | ||
store.createStoreConfig(this.config, StoreModel); | ||
var Store = store.transformStore(this.storeTransforms, StoreModel); | ||
return typeof Store === 'object' ? _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreFromObject(this, Store, key) : _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreFromClass.apply(undefined, [this, Store, key].concat(args)); | ||
return typeof Store === 'object' ? store.createStoreFromObject(this, Store, key) : store.createStoreFromClass.apply(store, [this, Store, key].concat(args)); | ||
} | ||
@@ -83,19 +94,19 @@ }, { | ||
var key = iden || StoreModel.displayName || StoreModel.name || ''; | ||
_createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreConfig(this.config, StoreModel); | ||
var Store = _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.transformStore(this.storeTransforms, StoreModel); | ||
store.createStoreConfig(this.config, StoreModel); | ||
var Store = store.transformStore(this.storeTransforms, StoreModel); | ||
if (this.stores[key] || !key) { | ||
if (this.stores[key]) { | ||
_dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.warn('A store named ' + key + ' already exists, double check your store ' + 'names or pass in your own custom identifier for each store'); | ||
utils.warn('A store named ' + key + ' already exists, double check your store ' + 'names or pass in your own custom identifier for each store'); | ||
} else { | ||
_dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.warn('Store name was not specified'); | ||
utils.warn('Store name was not specified'); | ||
} | ||
key = _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.uid(this.stores, key); | ||
key = utils.uid(this.stores, key); | ||
} | ||
var storeInstance = typeof Store === 'object' ? _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreFromObject(this, Store, key) : _createStoreConfig$createStoreFromObject$createStoreFromClass$transformStore.createStoreFromClass.apply(undefined, [this, Store, key].concat(args)); | ||
var storeInstance = typeof Store === 'object' ? store.createStoreFromObject(this, Store, key) : store.createStoreFromClass.apply(store, [this, Store, key].concat(args)); | ||
this.stores[key] = storeInstance; | ||
_filterSnapshots$saveInitialSnapshot$setAppState$snapshot.saveInitialSnapshot(this, key); | ||
StateFunctions.saveInitialSnapshot(this, key); | ||
@@ -113,3 +124,3 @@ return storeInstance; | ||
return this.createActions(actionNames.reduce(function (obj, action) { | ||
obj[action] = _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.dispatchIdentity; | ||
obj[action] = utils.dispatchIdentity; | ||
return obj; | ||
@@ -121,3 +132,3 @@ }, actions)); | ||
value: function createAction(name, implementation, obj) { | ||
return _makeAction2['default'](this, 'global', name, implementation, obj); | ||
return _actions2['default'](this, 'global', name, implementation, obj); | ||
} | ||
@@ -127,3 +138,3 @@ }, { | ||
value: function createActions(ActionsClass) { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -137,7 +148,7 @@ for (var _len4 = arguments.length, argsForConstructor = Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) { | ||
var actions = {}; | ||
var key = _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.uid(this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.ACTIONS_REGISTRY], ActionsClass.displayName || ActionsClass.name || 'Unknown'); | ||
var key = utils.uid(this[Sym.ACTIONS_REGISTRY], ActionsClass.displayName || ActionsClass.name || 'Unknown'); | ||
if (typeof ActionsClass === 'function') { | ||
(function () { | ||
_assign2['default'](actions, _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.getInternalMethods(ActionsClass.prototype, true)); | ||
_objectAssign2['default'](actions, utils.getInternalMethods(ActionsClass, true)); | ||
@@ -165,3 +176,3 @@ var ActionsGenerator = (function (_ActionsClass) { | ||
actionNames.forEach(function (actionName) { | ||
actions[actionName] = _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.dispatchIdentity; | ||
actions[actionName] = utils.dispatchIdentity; | ||
}); | ||
@@ -174,6 +185,6 @@ } | ||
_assign2['default'](actions, new (_bind.apply(ActionsGenerator, [null].concat(argsForConstructor)))()); | ||
_objectAssign2['default'](actions, new (_bind.apply(ActionsGenerator, [null].concat(argsForConstructor)))()); | ||
})(); | ||
} else { | ||
_assign2['default'](actions, ActionsClass); | ||
_objectAssign2['default'](actions, ActionsClass); | ||
} | ||
@@ -189,7 +200,7 @@ | ||
// create the action | ||
obj[action] = _makeAction2['default'](_this, key, action, actions[action], obj); | ||
obj[action] = _actions2['default'](_this2, key, action, actions[action], obj); | ||
// generate a constant | ||
var constant = _dispatchIdentity$formatAsConstant$getInternalMethods$uid$warn.formatAsConstant(action); | ||
obj[constant] = obj[action][_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.ACTION_KEY]; | ||
var constant = utils.formatAsConstant(action); | ||
obj[constant] = obj[action][Sym.ACTION_KEY]; | ||
@@ -206,4 +217,4 @@ return obj; | ||
var state = _filterSnapshots$saveInitialSnapshot$setAppState$snapshot.snapshot(this, storeNames); | ||
_assign2['default'](this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LAST_SNAPSHOT], state); | ||
var state = StateFunctions.snapshot(this, storeNames); | ||
_objectAssign2['default'](this[Sym.LAST_SNAPSHOT], state); | ||
return this.serialize(state); | ||
@@ -214,7 +225,5 @@ } | ||
value: function rollback() { | ||
_filterSnapshots$saveInitialSnapshot$setAppState$snapshot.setAppState(this, this.serialize(this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LAST_SNAPSHOT]), function (store) { | ||
if (store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].rollback) { | ||
store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].rollback(); | ||
} | ||
store.emitChange(); | ||
StateFunctions.setAppState(this, this.serialize(this[Sym.LAST_SNAPSHOT]), function (storeInst) { | ||
storeInst[Sym.LIFECYCLE].emit('rollback'); | ||
storeInst.emitChange(); | ||
}); | ||
@@ -229,9 +238,7 @@ } | ||
var initialSnapshot = storeNames.length ? _filterSnapshots$saveInitialSnapshot$setAppState$snapshot.filterSnapshots(this, this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.INIT_SNAPSHOT], storeNames) : this[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.INIT_SNAPSHOT]; | ||
var initialSnapshot = storeNames.length ? StateFunctions.filterSnapshots(this, this[Sym.INIT_SNAPSHOT], storeNames) : this[Sym.INIT_SNAPSHOT]; | ||
_filterSnapshots$saveInitialSnapshot$setAppState$snapshot.setAppState(this, this.serialize(initialSnapshot), function (store) { | ||
if (store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].init) { | ||
store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].init(); | ||
} | ||
store.emitChange(); | ||
StateFunctions.setAppState(this, this.serialize(initialSnapshot), function (storeInst) { | ||
storeInst[Sym.LIFECYCLE].emit('init'); | ||
storeInst.emitChange(); | ||
}); | ||
@@ -242,3 +249,3 @@ } | ||
value: function flush() { | ||
var state = this.serialize(_filterSnapshots$saveInitialSnapshot$setAppState$snapshot.snapshot(this)); | ||
var state = this.serialize(StateFunctions.snapshot(this)); | ||
this.recycle(); | ||
@@ -250,7 +257,5 @@ return state; | ||
value: function bootstrap(data) { | ||
_filterSnapshots$saveInitialSnapshot$setAppState$snapshot.setAppState(this, data, function (store) { | ||
if (store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].bootstrap) { | ||
store[_ACTION_KEY$ACTIONS_REGISTRY$INIT_SNAPSHOT$LAST_SNAPSHOT$LIFECYCLE.LIFECYCLE].bootstrap(); | ||
} | ||
store.emitChange(); | ||
StateFunctions.setAppState(this, data, function (storeInst) { | ||
storeInst[Sym.LIFECYCLE].emit('bootstrap'); | ||
storeInst.emitChange(); | ||
}); | ||
@@ -260,8 +265,8 @@ } | ||
key: 'prepare', | ||
value: function prepare(store, payload) { | ||
value: function prepare(storeInst, payload) { | ||
var data = {}; | ||
if (!store._storeName) { | ||
if (!storeInst.displayName) { | ||
throw new ReferenceError('Store provided does not have a name'); | ||
} | ||
data[store._storeName] = payload; | ||
data[storeInst.displayName] = payload; | ||
return this.serialize(data); | ||
@@ -268,0 +273,0 @@ } |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
@@ -9,48 +7,54 @@ value: true | ||
var _Symbol = require('es-symbol'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _Symbol2 = _interopRequireWildcard(_Symbol); | ||
var _esSymbol = require('es-symbol'); | ||
var _esSymbol2 = _interopRequireDefault(_esSymbol); | ||
// action creator handler | ||
var ACTION_HANDLER = _Symbol2['default'](); | ||
var ACTION_HANDLER = _esSymbol2['default'](); | ||
exports.ACTION_HANDLER = ACTION_HANDLER; | ||
// the action's uid symbol for listening | ||
var ACTION_KEY = _Symbol2['default'](); | ||
var ACTION_KEY = _esSymbol2['default'](); | ||
exports.ACTION_KEY = ACTION_KEY; | ||
// per instance registry of actions | ||
var ACTIONS_REGISTRY = _Symbol2['default'](); | ||
var ACTIONS_REGISTRY = _esSymbol2['default'](); | ||
exports.ACTIONS_REGISTRY = ACTIONS_REGISTRY; | ||
// the action's name | ||
var ACTION_UID = _Symbol2['default'](); | ||
var ACTION_UID = _esSymbol2['default'](); | ||
exports.ACTION_UID = ACTION_UID; | ||
// store all of a store's listeners | ||
var ALL_LISTENERS = _Symbol2['default'](); | ||
var ALL_LISTENERS = _esSymbol2['default'](); | ||
exports.ALL_LISTENERS = ALL_LISTENERS; | ||
// are we handling our own errors | ||
var HANDLING_ERRORS = _esSymbol2['default'](); | ||
exports.HANDLING_ERRORS = HANDLING_ERRORS; | ||
// initial snapshot | ||
var INIT_SNAPSHOT = _Symbol2['default'](); | ||
var INIT_SNAPSHOT = _esSymbol2['default'](); | ||
exports.INIT_SNAPSHOT = INIT_SNAPSHOT; | ||
// last snapshot | ||
var LAST_SNAPSHOT = _Symbol2['default'](); | ||
var LAST_SNAPSHOT = _esSymbol2['default'](); | ||
exports.LAST_SNAPSHOT = LAST_SNAPSHOT; | ||
// all lifecycle listeners | ||
var LIFECYCLE = _Symbol2['default'](); | ||
var LIFECYCLE = _esSymbol2['default'](); | ||
exports.LIFECYCLE = LIFECYCLE; | ||
// store action listeners | ||
var LISTENERS = _Symbol2['default'](); | ||
var LISTENERS = _esSymbol2['default'](); | ||
exports.LISTENERS = LISTENERS; | ||
// public methods | ||
var PUBLIC_METHODS = _Symbol2['default'](); | ||
var PUBLIC_METHODS = _esSymbol2['default'](); | ||
exports.PUBLIC_METHODS = PUBLIC_METHODS; | ||
// contains all state | ||
var STATE_CONTAINER = _Symbol2['default'](); | ||
var STATE_CONTAINER = _esSymbol2['default'](); | ||
exports.STATE_CONTAINER = STATE_CONTAINER; |
@@ -17,4 +17,5 @@ 'use strict'; | ||
function getInternalMethods(obj, isProto) { | ||
function getInternalMethods(Obj, isProto) { | ||
var excluded = isProto ? builtInProto : builtIns; | ||
var obj = isProto ? Obj.prototype : Obj; | ||
return Object.getOwnPropertyNames(obj).reduce(function (value, m) { | ||
@@ -21,0 +22,0 @@ if (excluded.indexOf(m) !== -1) { |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
@@ -13,15 +11,14 @@ value: true | ||
var _assign = require('object-assign'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } | ||
var _assign2 = _interopRequireWildcard(_assign); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _import = require('../symbols/symbols'); | ||
var _objectAssign = require('object-assign'); | ||
var Sym = _interopRequireWildcard(_import); | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
var INIT_SNAPSHOT = Sym.INIT_SNAPSHOT; | ||
var LAST_SNAPSHOT = Sym.LAST_SNAPSHOT; | ||
var LIFECYCLE = Sym.LIFECYCLE; | ||
var STATE_CONTAINER = Sym.STATE_CONTAINER; | ||
var _symbolsSymbols = require('../symbols/symbols'); | ||
var Sym = _interopRequireWildcard(_symbolsSymbols); | ||
function setAppState(instance, data, onStore) { | ||
@@ -37,3 +34,3 @@ var obj = instance.deserialize(data); | ||
} | ||
_assign2['default'](store[STATE_CONTAINER], obj[key]); | ||
_objectAssign2['default'](store[Sym.STATE_CONTAINER], obj[key]); | ||
onStore(store); | ||
@@ -53,6 +50,4 @@ } | ||
if (store[LIFECYCLE].snapshot) { | ||
store[LIFECYCLE].snapshot(); | ||
} | ||
var customSnapshot = config.onSerialize && config.onSerialize(store[STATE_CONTAINER]); | ||
store[Sym.LIFECYCLE].emit('snapshot'); | ||
var customSnapshot = config.onSerialize && config.onSerialize(store[Sym.STATE_CONTAINER]); | ||
obj[storeName] = customSnapshot ? customSnapshot : store.getState(); | ||
@@ -64,5 +59,5 @@ return obj; | ||
function saveInitialSnapshot(instance, key) { | ||
var state = instance.deserialize(instance.serialize(instance.stores[key][STATE_CONTAINER])); | ||
instance[INIT_SNAPSHOT][key] = state; | ||
instance[LAST_SNAPSHOT][key] = state; | ||
var state = instance.deserialize(instance.serialize(instance.stores[key][Sym.STATE_CONTAINER])); | ||
instance[Sym.INIT_SNAPSHOT][key] = state; | ||
instance[Sym.LAST_SNAPSHOT][key] = state; | ||
} | ||
@@ -69,0 +64,0 @@ |
{ | ||
"name": "alt", | ||
"version": "0.16.2", | ||
"version": "0.17.0-alpha1", | ||
"description": "A flux implementation", | ||
@@ -13,4 +13,4 @@ "main": "lib", | ||
"devDependencies": { | ||
"babel": "^5.1.11", | ||
"babel-core": "^5.1.11", | ||
"babel": "^5.2.13", | ||
"babel-core": "^5.2.13", | ||
"babelify": "^6.0.2", | ||
@@ -49,3 +49,3 @@ "browserify": "^9.0.3", | ||
"build-test": "babel src/alt --out-dir lib -r --stage 0 && babel src/utils --out-dir utils -r --stage 0", | ||
"coverage": "npm run build-test && istanbul cover node_modules/mocha/bin/_mocha -- -u exports -R spec --require ./test/babel --require babel-core/external-helpers test", | ||
"coverage": "npm run build-test && istanbul cover node_modules/mocha/bin/_mocha -- -u exports -R spec --require ./test/babel test", | ||
"clean": "rimraf lib && rimraf utils", | ||
@@ -56,5 +56,6 @@ "lint": "eslint src components", | ||
"pretest": "npm run clean && npm run build-test", | ||
"size": "npm run build-alt; browserify flux.js > flux-build.js; uglifyjs -m -c 'comparisons=false,keep_fargs=true,unsafe=true,unsafe_comps=true,warnings=false' flux-build.js > flux-build.min.js", | ||
"test": "npm run tests-node", | ||
"test-browser": "browserify test/browser/index.js -t babelify --outfile test/browser/tests.js", | ||
"tests-node": "mocha -u exports -R spec --require ./test/babel --require babel-core/external-helpers test" | ||
"tests-node": "mocha -u exports -R spec --require ./test/babel test" | ||
}, | ||
@@ -61,0 +62,0 @@ "browserify-shim": { |
@@ -20,3 +20,3 @@ # alt | ||
* Extremely [flexible](#flexibility) and unopinionated in how you use flux. Create traditional singletons or use dependency injection. | ||
* It is [terse](https://github.com/goatslacker/alt#flux-minus-the-boilerplate). No boilerplate. | ||
* It is terse. No boilerplate. | ||
@@ -74,4 +74,26 @@ ### What does it look like? | ||
## Principles of Flux | ||
## In the Wild | ||
### Examples | ||
* [Airbnb Airpal](https://github.com/airbnb/airpal/tree/master/src/main/resources/assets) | ||
* [Alt Notify](https://github.com/sourcescript/alt-notify) | ||
* [Chrome Devtool](https://github.com/goatslacker/alt-devtool) | ||
* [Example Tests](https://github.com/jdlehman/alt-example-tests) | ||
* [Github Example](https://github.com/RookieOne/react-alt-github-example) | ||
* [Isomorphic Alt](https://github.com/patrickkim/iso-alt) | ||
* [React Router Example](https://github.com/lostpebble/alt-react-router-example) | ||
* [React Router Loopback](https://github.com/bkniffler/react-router-alt-loopback) | ||
* [React Weather](https://github.com/sapegin/react-weather) | ||
* [Shopping Cart](https://github.com/voronianski/flux-comparison/tree/master/alt) | ||
* [Todo](https://github.com/benstokoe/alt-todo) | ||
* [Typeahead](https://github.com/timtyrrell/alt-typeahead) | ||
### Boilerplates | ||
* [Isomorphic Flux Boilerplate](https://github.com/iam4x/isomorphic-flux-boilerplate) | ||
* [React + Webpack + Node](https://github.com/choonkending/react-webpack-node) | ||
## Pure Flux + More | ||
* Unidirectional data flow | ||
@@ -83,21 +105,4 @@ * Stores have no setters | ||
Read more about the [Principles of Flux](https://medium.com/@goatslacker/principles-of-flux-ea872bc20772). | ||
Read about the [Principles of Flux](https://medium.com/@goatslacker/principles-of-flux-ea872bc20772). | ||
## Flux minus the boilerplate | ||
* No [JS "constants"](https://github.com/facebook/flux/blob/master/examples/flux-chat/js/constants/ChatConstants.js). | ||
* No [static string tossing](https://github.com/facebook/flux/blob/master/examples/flux-chat/js/dispatcher/ChatAppDispatcher.js#L39). | ||
* No [massive switch statements](https://github.com/facebook/flux/blob/master/examples/flux-chat/js/stores/MessageStore.js#L111). | ||
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. | ||
This has the wonderful side effect of making the custom dispatcher logic unnecessary, thus removing the dispatcher from the equation. | ||
Make no mistake, there is still a single dispatcher through which actions flow on their merry way to the store, in fact, you still get the benefit of being able to hook into the dispatcher to listen to all the global events for debugging, fun, or misery. | ||
The dispatcher is just a part of alt and something you don't necessarily have to write custom code for. | ||
These removals make the code terse and easy to follow, there is less indirection and the learning curve to grok is much lower. | ||
Think I'm lying? [Check out an example](#differences-example). | ||
## Flux enhanced | ||
One really cool aspect of alt is that you can save snapshots of the entire application's state at any given point in time. | ||
@@ -113,9 +118,13 @@ This has many different use cases like: | ||
* [ActionListener](/src/utils/ActionListeners.js) lets you listen to individual actions without having to create a store. | ||
* [AltContainer](/components/AltContainer.js) a higher-order container component that is your swiss army knife for React. | ||
* [atomic](/src/utils/atomic.js) enables your stores for atomic transactions. | ||
* [connectToStores](/src/utils/connectToStores.js) a higher-order function that wraps your React components for store listening. | ||
* [decorators](/src/utils/decorators.js) a collection of useful ES7 decorators for working with alt. | ||
* [DispatchRecorder](/src/utils/DispatcherRecorder.js) lets you record all your dispatches and replay them back at a later time. | ||
* [ImmutableUtil](/src/utils/ImmutableUtil.js) makes working with immutable-js easy. | ||
* [IsomorphicRenderer](/src/utils/IsomorphicRenderer.js) a function that wraps your component to be isomorphic ready. | ||
* [TimeTravel](/src/utils/TimeTravel.js) enhances your stores so they are able to travel through different states in time. | ||
* [FinalStore](/src/utils/makeFinalStore.js) is a Store that you can listen to that only emits when all your other stores have received all their data. | ||
* [IsomorphicRenderer](/src/utils/IsomorphicRenderer.js) a function that wraps your component to be isomorphic ready. | ||
* [ActionListener](/src/utils/ActionListeners.js) lets you listen to individual actions without having to create a store. | ||
Last but not least, alt is meant to work with ES6. That is we're betting you'll be writing your stores and actions as classes. This part isn't necessary but you really should write some ES6 anyways because it's nice. | ||
## Topical Guide | ||
@@ -122,0 +131,0 @@ |
@@ -1,3 +0,4 @@ | ||
require('babel/register')({ | ||
require('babel-core/external-helpers') | ||
require('babel/register-without-polyfill')({ | ||
stage: 0 | ||
}) |
import { assert } from 'chai' | ||
import Alt from '../' | ||
import { createActions, createStore } from '../utils/decorators' | ||
import { createActions, createStore, bind, expose } from '../utils/decorators' | ||
@@ -54,3 +54,37 @@ const alt = new Alt() | ||
}, | ||
'decorating action listening and public methods'() { | ||
const TodoActions = alt.generateActions('addTodo') | ||
@createStore(alt) | ||
class TodoStore { | ||
static displayName = 'TodoStore' | ||
constructor() { | ||
this.todos = {} | ||
this.id = 0 | ||
} | ||
uid() { | ||
return this.id++ | ||
} | ||
@bind(TodoActions.addTodo) | ||
addTodo(todo) { | ||
this.todos[this.uid()] = todo | ||
} | ||
@expose | ||
getTodo(id) { | ||
return this.getState().todos[id] | ||
} | ||
} | ||
TodoActions.addTodo('hello') | ||
assert(TodoStore.getState().id === 1) | ||
assert.isFunction(TodoStore.getTodo) | ||
assert(TodoStore.getTodo(0) === 'hello') | ||
}, | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
import assign from 'object-assign' | ||
class ReactComponent { | ||
@@ -55,3 +57,3 @@ setState(state) { | ||
: {} | ||
component.props = Object.assign({}, defaultProps, props) | ||
component.props = assign({}, defaultProps, props) | ||
@@ -58,0 +60,0 @@ component.state = component.getInitialState |
@@ -504,7 +504,7 @@ import Alt from '../' | ||
assert.deepEqual(Object.keys(JSON.parse(snapshot)), ['MyStore', 'AltSecondStore'], 'the snapshot includes specified stores') | ||
assert.isFalse(Object.keys(JSON.parse(snapshot)).includes('LifeCycleStore'), 'the snapshot does not include unspecified stores') | ||
assert(Object.keys(JSON.parse(snapshot)).indexOf('LifeCycleStore') === -1, 'the snapshot does not include unspecified stores') | ||
const snapshot2 = alt.takeSnapshot(myStore, secondStore) | ||
assert.deepEqual(Object.keys(JSON.parse(snapshot2)), ['MyStore', 'AltSecondStore'], 'the snapshot includes specified stores') | ||
assert.isFalse(Object.keys(JSON.parse(snapshot2)).includes('LifeCycleStore'), 'the snapshot does not include unspecified stores') | ||
assert(Object.keys(JSON.parse(snapshot2)).indexOf('LifeCycleStore') === -1, 'the snapshot does not include unspecified stores') | ||
}, | ||
@@ -711,3 +711,3 @@ | ||
this.foo = 'bar' | ||
this.exportPublicMethods('foo') | ||
this.exportPublicMethods({ foo: 'foo' }) | ||
} | ||
@@ -749,3 +749,3 @@ } | ||
assert.throw(() => alt.createStore(MethodsAreUnary1), TypeError, /Action handler in store .* was defined with 2 parameters/) | ||
assert.throw(() => alt.createStore(MethodsAreUnary1), TypeError, /Action handler in store .* was defined with two parameters/) | ||
@@ -760,3 +760,3 @@ class MethodsAreUnary2 { | ||
assert.throw(() => alt.createStore(MethodsAreUnary2), TypeError, /Action handler in store .* was defined with 2 parameters/) | ||
assert.throw(() => alt.createStore(MethodsAreUnary2), TypeError, /Action handler in store .* was defined with two parameters/) | ||
}, | ||
@@ -763,0 +763,0 @@ |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
/** | ||
@@ -27,7 +28,7 @@ * ActionListeners(alt: AltInstance): ActionListenersInstance | ||
var _Symbol = require('es-symbol'); | ||
var _esSymbol = require('es-symbol'); | ||
var _Symbol2 = _interopRequireWildcard(_Symbol); | ||
var _esSymbol2 = _interopRequireDefault(_esSymbol); | ||
var ALT_LISTENERS = _Symbol2['default']('global dispatcher listeners'); | ||
var ALT_LISTENERS = _esSymbol2['default']('global dispatcher listeners'); | ||
@@ -34,0 +35,0 @@ function ActionListeners(alt) { |
'use strict'; | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; | ||
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; }; })(); | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
/** | ||
@@ -11,0 +12,0 @@ * AltManager(Alt: AltClass): undefined |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
var _get = function get(_x2, _x3, _x4) { var _again = true; _function: while (_again) { desc = parent = getter = undefined; _again = false; var object = _x2, | ||
property = _x3, | ||
receiver = _x4; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x2 = parent; _x3 = property; _x4 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
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) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
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; }; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } | ||
var _assign = require('object-assign'); | ||
var _objectAssign = require('object-assign'); | ||
var _assign2 = _interopRequireWildcard(_assign); | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
@@ -50,3 +52,3 @@ var noop = function noop() {}; | ||
_assign2['default'](DerivedStore.prototype, StorePrototype); | ||
_objectAssign2['default'](DerivedStore.prototype, StorePrototype); | ||
return new DerivedStore(); | ||
@@ -53,0 +55,0 @@ }, |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; | ||
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) { 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; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { desc = parent = getter = undefined; _again = false; var object = _x, | ||
property = _x2, | ||
receiver = _x3; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
exports['default'] = atomic; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } | ||
var _makeFinalStore = require('./makeFinalStore'); | ||
var _makeFinalStore2 = _interopRequireWildcard(_makeFinalStore); | ||
var _makeFinalStore2 = _interopRequireDefault(_makeFinalStore); | ||
@@ -20,0 +23,0 @@ function makeAtomicClass(alt, StoreModel) { |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
/** | ||
@@ -53,9 +54,9 @@ * 'Higher Order Component' that controls the props of a wrapped | ||
var _React = require('react'); | ||
var _react = require('react'); | ||
var _React2 = _interopRequireWildcard(_React); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _assign = require('object-assign'); | ||
var _objectAssign = require('object-assign'); | ||
var _assign2 = _interopRequireWildcard(_assign); | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
@@ -75,3 +76,3 @@ function connectToStores(Component) { | ||
// Wrapper Component. | ||
var StoreConnection = _React2['default'].createClass({ | ||
var StoreConnection = _react2['default'].createClass({ | ||
displayName: 'StoreConnection', | ||
@@ -104,3 +105,3 @@ | ||
render: function render() { | ||
return _React2['default'].createElement(Component, _assign2['default']({}, this.props, this.state)); | ||
return _react2['default'].createElement(Component, _objectAssign2['default']({}, this.props, this.state)); | ||
} | ||
@@ -107,0 +108,0 @@ }); |
@@ -1,4 +0,4 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
@@ -8,3 +8,22 @@ }); | ||
exports.createStore = createStore; | ||
exports.bind = bind; | ||
exports.expose = expose; | ||
exports.datasource = datasource; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _objectAssign = require('object-assign'); | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
/* istanbul ignore next */ | ||
function NoopClass() {} | ||
var builtInProto = Object.getOwnPropertyNames(NoopClass.prototype); | ||
function addMeta(description, decoration) { | ||
description.value.alt = description.value.alt || {}; | ||
_objectAssign2['default'](description.value.alt, decoration); | ||
return description; | ||
} | ||
function createActions(alt) { | ||
@@ -26,4 +45,50 @@ for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
return function (Store) { | ||
var proto = Store.prototype; | ||
var publicMethods = {}; | ||
var bindListeners = {}; | ||
Object.getOwnPropertyNames(proto).forEach(function (name) { | ||
if (builtInProto.indexOf(name) !== -1) return; | ||
var meta = proto[name].alt; | ||
if (!meta) { | ||
return; | ||
} | ||
/* istanbul ignore else */ | ||
if (meta.action) { | ||
bindListeners[name] = meta.action; | ||
} else if (meta.publicMethod) { | ||
publicMethods[name] = proto[name]; | ||
} | ||
}); | ||
Store.config = _objectAssign2['default']({ | ||
bindListeners: bindListeners, | ||
publicMethods: publicMethods | ||
}, Store.config); | ||
return alt.createStore.apply(alt, [Store, undefined].concat(args)); | ||
}; | ||
} | ||
function bind() { | ||
for (var _len3 = arguments.length, actionIds = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
actionIds[_key3] = arguments[_key3]; | ||
} | ||
return function (obj, name, description) { | ||
return addMeta(description, { action: actionIds }); | ||
}; | ||
} | ||
function expose(obj, name, description) { | ||
return addMeta(description, { publicMethod: true }); | ||
} | ||
function datasource(source) { | ||
return function (Store) { | ||
Store.config = _objectAssign2['default']({ datasource: source }, Store.config); | ||
return Store; | ||
}; | ||
} |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
/** | ||
@@ -36,5 +37,5 @@ * DispatcherRecorder(alt: AltInstance): DispatcherInstance | ||
var _Symbol = require('es-symbol'); | ||
var _esSymbol = require('es-symbol'); | ||
var _Symbol2 = _interopRequireWildcard(_Symbol); | ||
var _esSymbol2 = _interopRequireDefault(_esSymbol); | ||
@@ -129,3 +130,3 @@ function DispatcherRecorder(alt) { | ||
return { | ||
action: _Symbol2['default'].keyFor(event.action), | ||
action: _esSymbol2['default'].keyFor(event.action), | ||
data: event.data | ||
@@ -145,3 +146,3 @@ }; | ||
return { | ||
action: _Symbol2['default']['for'](event.action), | ||
action: _esSymbol2['default']['for'](event.action), | ||
data: event.data | ||
@@ -148,0 +149,0 @@ }; |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
@@ -9,6 +7,8 @@ value: true | ||
var _Immutable = require('immutable'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _Immutable2 = _interopRequireWildcard(_Immutable); | ||
var _immutable = require('immutable'); | ||
var _immutable2 = _interopRequireDefault(_immutable); | ||
function immutable(StoreModel) { | ||
@@ -32,3 +32,3 @@ StoreModel.config = { | ||
onDeserialize: function onDeserialize(data) { | ||
return _Immutable2['default'].fromJS(data); | ||
return _immutable2['default'].fromJS(data); | ||
} | ||
@@ -35,0 +35,0 @@ }; |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
@@ -9,2 +7,5 @@ value: true | ||
exports['default'] = IsomorphicRenderer; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
/** | ||
@@ -37,9 +38,9 @@ * IsomorphicRenderer(alt: AltInstance, App: ReactElement): mixed | ||
var _Iso = require('iso'); | ||
var _iso = require('iso'); | ||
var _Iso2 = _interopRequireWildcard(_Iso); | ||
var _iso2 = _interopRequireDefault(_iso); | ||
var _React = require('react'); | ||
var _react = require('react'); | ||
var _React2 = _interopRequireWildcard(_React); | ||
var _react2 = _interopRequireDefault(_react); | ||
@@ -51,4 +52,4 @@ function IsomorphicRenderer(alt, App) { | ||
return function () { | ||
var app = _React2['default'].renderToString(_React2['default'].createElement(App)); | ||
var markup = _Iso2['default'].render(app, alt.takeSnapshot()); | ||
var app = _react2['default'].renderToString(_react2['default'].createElement(App)); | ||
var markup = _iso2['default'].render(app, alt.takeSnapshot()); | ||
alt.flush(); | ||
@@ -58,6 +59,6 @@ return markup; | ||
} else { | ||
_Iso2['default'].bootstrap(function (state, _, node) { | ||
var app = _React2['default'].createElement(App); | ||
_iso2['default'].bootstrap(function (state, _, node) { | ||
var app = _react2['default'].createElement(App); | ||
alt.bootstrap(state); | ||
_React2['default'].render(app, node); | ||
_react2['default'].render(app, node); | ||
}); | ||
@@ -64,0 +65,0 @@ } |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: key == null || typeof Symbol == 'undefined' || key.constructor !== Symbol, configurable: true, writable: 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; }; })(); | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; | ||
var _get = function get(_x4, _x5, _x6) { var _again = true; _function: while (_again) { desc = parent = getter = undefined; _again = false; var object = _x4, | ||
property = _x5, | ||
receiver = _x6; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x4 = parent; _x5 = property; _x6 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
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) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
function _defineProperty(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } | ||
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; }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } | ||
var _assign = require('object-assign'); | ||
var _objectAssign = require('object-assign'); | ||
var _assign2 = _interopRequireWildcard(_assign); | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
var _makeFinalStore = require('./makeFinalStore'); | ||
var _makeFinalStore2 = _interopRequireWildcard(_makeFinalStore); | ||
var _makeFinalStore2 = _interopRequireDefault(_makeFinalStore); | ||
@@ -30,3 +32,3 @@ function timetravel(alt) { | ||
var history = _assign2['default']({ | ||
var history = _objectAssign2['default']({ | ||
max: 300 | ||
@@ -56,3 +58,3 @@ }, options); | ||
function TimeTravelStore() { | ||
var _this4 = this; | ||
var _this5 = this; | ||
@@ -69,7 +71,7 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
// capture the initial snapshot | ||
captureMoment(alt.serialize(_defineProperty({}, _this4._storeName, _this4))); | ||
captureMoment(alt.serialize(_defineProperty({}, _this5._storeName, _this5))); | ||
// capture subsequent shots | ||
payloadStore.listen(function (_) { | ||
return captureMoment(alt.takeSnapshot(_this4._storeName)); | ||
return captureMoment(alt.takeSnapshot(_this5._storeName)); | ||
}); | ||
@@ -76,0 +78,0 @@ }); |
'use strict'; | ||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; | ||
Object.defineProperty(exports, '__esModule', { | ||
@@ -10,11 +8,13 @@ value: true | ||
var _React = require('react'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _React2 = _interopRequireWildcard(_React); | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
function withAltContext(flux) { | ||
return function (Component) { | ||
return _React2['default'].createClass({ | ||
return _react2['default'].createClass({ | ||
childContextTypes: { | ||
flux: _React2['default'].PropTypes.object | ||
flux: _react2['default'].PropTypes.object | ||
}, | ||
@@ -27,3 +27,3 @@ | ||
render: function render() { | ||
return _React2['default'].createElement(Component, this.props); | ||
return _react2['default'].createElement(Component, this.props); | ||
} | ||
@@ -30,0 +30,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
550710
111
10808
837
3
8