microcosm
Advanced tools
Comparing version 12.9.0-beta4 to 12.9.0
@@ -10,3 +10,15 @@ 'use strict'; | ||
var $Symbol = isFunction(Symbol) ? Symbol : {}; | ||
var toStringTag = get$1($Symbol, 'toStringTag', '@@toStringTag'); | ||
var iteratorTag = get$1($Symbol, 'iterator', '@@iterator'); | ||
/** | ||
* Merge on object into the next, but only assign keys that are | ||
* defined in the base. | ||
*/ | ||
/** | ||
* Shallow copy an object | ||
@@ -59,4 +71,6 @@ */ | ||
*/ | ||
function isFunction(target) { | ||
return !!target && typeof target === 'function'; | ||
} | ||
function isBlank(value) { | ||
@@ -71,4 +85,2 @@ return value === '' || value === null || value === undefined; | ||
/* istanbul ignore next */ | ||
var $Symbol = typeof Symbol === 'function' ? Symbol : {}; | ||
var toStringTagSymbol = get$1($Symbol, 'toStringTag', '@@toStringTag'); | ||
@@ -88,3 +100,8 @@ | ||
/** | ||
* A couple of methods use identity functions. This avoids duplication. | ||
*/ | ||
/** | ||
* @fileoverview A key path is a list of property names that describe | ||
@@ -91,0 +108,0 @@ * a pathway through a nested javascript object. For example, |
@@ -204,2 +204,10 @@ 'use strict'; | ||
function renderMediator() { | ||
return React.createElement(PresenterMediator, { | ||
presenter: this, | ||
parentState: this.state, | ||
parentProps: this.props | ||
}); | ||
} | ||
/* istanbul ignore next */ | ||
@@ -216,5 +224,4 @@ var identity = function identity() {}; | ||
if (_this.render !== Presenter.prototype.render) { | ||
if (_this.render) { | ||
_this.defaultRender = _this.render; | ||
_this.render = Presenter.prototype.render; | ||
} else { | ||
@@ -224,2 +231,8 @@ _this.defaultRender = passChildren; | ||
// We need to wrap the children of this presenter in a | ||
// PresenterMediator component. This ensures that we can pass along | ||
// context in browsers that do not support static inheritence (IE10) | ||
// and allow overriding of lifecycle methods | ||
_this.render = renderMediator; | ||
// Autobind send so that context is maintained when passing send to children | ||
@@ -360,10 +373,2 @@ _this.send = _this.send.bind(_this); | ||
Presenter.prototype.render = function render() { | ||
return React.createElement(PresenterMediator, { | ||
presenter: this, | ||
parentState: this.state, | ||
parentProps: this.props | ||
}); | ||
}; | ||
return Presenter; | ||
@@ -370,0 +375,0 @@ }(React.PureComponent); |
# Changelog | ||
# 12.9.0 (beta) | ||
# 12.9.0 | ||
@@ -5,0 +5,0 @@ - Added new `repo.parallel` method. This returns an action that |
304
microcosm.js
@@ -60,2 +60,8 @@ 'use strict'; | ||
var $Symbol = isFunction(Symbol) ? Symbol : {}; | ||
var toStringTag = get($Symbol, 'toStringTag', '@@toStringTag'); | ||
var iteratorTag = get($Symbol, 'iterator', '@@iterator'); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
@@ -146,4 +152,2 @@ return typeof obj; | ||
*/ | ||
var uidStepper = 0; | ||
@@ -155,2 +159,18 @@ function uid(prefix) { | ||
/** | ||
* Merge on object into the next, but only assign keys that are | ||
* defined in the base. | ||
*/ | ||
function mergeSame(target, head) { | ||
var next = {}; | ||
for (var key in head) { | ||
if (key in target) { | ||
next[key] = head[key]; | ||
} | ||
} | ||
return next; | ||
} | ||
/** | ||
* Shallow copy an object | ||
@@ -301,5 +321,3 @@ */ | ||
/* istanbul ignore next */ | ||
var $Symbol = typeof Symbol === 'function' ? Symbol : {}; | ||
var toStringTagSymbol = get($Symbol, 'toStringTag', '@@toStringTag'); | ||
function toStringTag(value) { | ||
function getStringTag(value) { | ||
if (!value) { | ||
@@ -309,3 +327,3 @@ return ''; | ||
return value[toStringTagSymbol] || ''; | ||
return value[toStringTag] || ''; | ||
} | ||
@@ -318,3 +336,3 @@ | ||
function isGeneratorFn(value) { | ||
return toStringTag(value) === 'GeneratorFunction'; | ||
return getStringTag(value) === 'GeneratorFunction'; | ||
} | ||
@@ -347,2 +365,6 @@ | ||
/** | ||
* A couple of methods use identity functions. This avoids duplication. | ||
*/ | ||
/** | ||
* @fileoverview Emitter is an abstract class used by a few other | ||
@@ -633,6 +655,6 @@ * classes to communicate via events | ||
var onResolve = function onResolve() { | ||
outstanding -= 1; | ||
if (outstanding <= 0) { | ||
if (outstanding <= 1) { | ||
_this2.resolve(); | ||
} else { | ||
outstanding -= 1; | ||
} | ||
@@ -647,2 +669,4 @@ }; | ||
onResolve(); | ||
return this; | ||
@@ -782,2 +806,6 @@ }; | ||
Action.prototype.toString = function toString() { | ||
return this.command.toString(); | ||
}; | ||
Action.prototype.toJSON = function toJSON() { | ||
@@ -881,8 +909,5 @@ return { | ||
} | ||
// Strip out keys not managed by this repo. This prevents children from | ||
// accidentally having their keys reset by parents. | ||
var sanitary = repo.domains.sanitize(payload); | ||
action.resolve(sanitary); | ||
action.resolve(mergeSame(repo.state, payload)); | ||
}; | ||
@@ -1022,14 +1047,44 @@ } | ||
*/ | ||
// $FlowFixMe | ||
History.prototype[iteratorTag] = function () { | ||
var _this2 = this; | ||
var cursor = this.root; | ||
var iterator = { | ||
next: function next() { | ||
var next = cursor; | ||
if (next == null) { | ||
return { done: true }; | ||
} | ||
cursor = next == _this2.head ? null : cursor.next; | ||
// Ignore certain lifecycle actions that are only for | ||
// internal purposes | ||
if (next && (next.command === BIRTH || next.command === START || next.command === ADD_DOMAIN)) { | ||
return iterator.next(); | ||
} | ||
return { value: next, done: false }; | ||
} | ||
}; | ||
return iterator; | ||
}; | ||
History.prototype.map = function map(fn, scope) { | ||
// $FlowFixMe | ||
var iterator = this[iteratorTag](); | ||
var next = iterator.next(); | ||
var items = []; | ||
var cursor = this.root; | ||
while (cursor) { | ||
items.push(fn.call(scope, cursor)); | ||
while (!next.done) { | ||
items.push(fn.call(scope, next.value, items.length)); | ||
next = iterator.next(); | ||
} | ||
if (cursor == this.head) break; | ||
cursor = cursor.next; | ||
} | ||
return items; | ||
@@ -1045,3 +1100,3 @@ }; | ||
History.prototype.wait = function wait() { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -1053,5 +1108,5 @@ var group = new Action('GROUP'); | ||
return group.then(function () { | ||
if (_this2.releasing) { | ||
if (_this3.releasing) { | ||
return new Promise(function (resolve) { | ||
_this2.once('release', resolve); | ||
_this3.once('release', resolve); | ||
}); | ||
@@ -1217,2 +1272,3 @@ } | ||
* signal that the action should be removed. | ||
* @private | ||
*/ | ||
@@ -1306,2 +1362,6 @@ | ||
History.prototype.toString = function toString() { | ||
return this.toArray().join(', '); | ||
}; | ||
/** | ||
@@ -1324,68 +1384,2 @@ * Serialize history into JSON data | ||
var Archive = function () { | ||
function Archive() { | ||
classCallCheck(this, Archive); | ||
this.pool = {}; | ||
} | ||
/** | ||
* Create an initial snapshot for an action by setting it to that of its | ||
* parent. | ||
*/ | ||
Archive.prototype.create = function create(action) { | ||
this.set(action, this.get(action.parent)); | ||
}; | ||
/** | ||
* Access a prior snapshot for a given action | ||
*/ | ||
Archive.prototype.get = function get(action, fallback) { | ||
if (action && this.has(action)) { | ||
return this.pool[action.id]; | ||
} | ||
return fallback == null ? {} : fallback; | ||
}; | ||
/** | ||
* Does a snapshot exist for an action? | ||
*/ | ||
Archive.prototype.has = function has(action) { | ||
return typeof this.pool[action.id] !== 'undefined'; | ||
}; | ||
/** | ||
* Assign a new snapshot for an action | ||
*/ | ||
Archive.prototype.set = function set(action, snapshot) { | ||
this.pool[action.id] = snapshot; | ||
}; | ||
/** | ||
* Remove a snapshot for an action. | ||
*/ | ||
Archive.prototype.remove = function remove(action) { | ||
delete this.pool[action.id]; | ||
}; | ||
return Archive; | ||
}(); /** | ||
* @fileoverview Keeps track of prior action states according to an | ||
* action's id | ||
* | ||
*/ | ||
/** | ||
@@ -1412,3 +1406,3 @@ * @fileoverview Every Microcosm includes MetaDomain. It provides the | ||
MetaDomain.prototype.reset = function reset(oldState, newState) { | ||
var filtered = this.repo.domains.sanitize(newState); | ||
var filtered = mergeSame(oldState, newState); | ||
@@ -1424,3 +1418,3 @@ return merge(oldState, this.repo.getInitialState(), filtered); | ||
MetaDomain.prototype.patch = function patch(oldState, newState) { | ||
var filtered = this.repo.domains.sanitize(newState); | ||
var filtered = mergeSame(oldState, newState); | ||
@@ -1451,10 +1445,2 @@ return merge(oldState, filtered); | ||
var Registration = function Registration(key, domain, handler) { | ||
classCallCheck(this, Registration); | ||
this.key = key; | ||
this.domain = domain; | ||
this.handler = handler; | ||
}; | ||
var ALIASES = { | ||
@@ -1521,3 +1507,3 @@ inactive: 'inactive', | ||
return handler ? [new Registration([], this.repo, handler)] : []; | ||
return handler ? [{ key: [], source: this.repo, handler: handler }] : []; | ||
}; | ||
@@ -1542,3 +1528,3 @@ | ||
if (handler) { | ||
handlers.push(new Registration(key, domain, handler)); | ||
handlers.push({ key: key, source: domain, handler: handler }); | ||
} | ||
@@ -1581,46 +1567,2 @@ } | ||
DomainEngine.prototype.reduce = function reduce(fn, state, scope) { | ||
var next = state; | ||
// Important: start at 1 to avoid the meta domain | ||
for (var i = 1, len = this.domains.length; i < len; i++) { | ||
var _domains$i2 = this.domains[i], | ||
key = _domains$i2[0], | ||
domain = _domains$i2[1]; | ||
next = fn.call(scope, next, key, domain); | ||
} | ||
return next; | ||
}; | ||
DomainEngine.prototype.supportsKey = function supportsKey(key) { | ||
if (key in this.repo.state) { | ||
return true; | ||
} | ||
return this.domains.some(function (entry) { | ||
return getKeyString(entry[0]) === key; | ||
}); | ||
}; | ||
DomainEngine.prototype.sanitize = function sanitize(data) { | ||
var repo = this.repo; | ||
var parent = repo.parent; | ||
var next = {}; | ||
for (var key in data) { | ||
if (parent && parent.domains.supportsKey(key)) { | ||
continue; | ||
} | ||
if (this.supportsKey(key)) { | ||
next[key] = data[key]; | ||
} | ||
} | ||
return next; | ||
}; | ||
DomainEngine.prototype.dispatch = function dispatch(state, action) { | ||
@@ -1633,3 +1575,3 @@ var handlers = this.register(action); | ||
key = _handlers$i.key, | ||
domain = _handlers$i.domain, | ||
source = _handlers$i.source, | ||
handler = _handlers$i.handler; | ||
@@ -1639,3 +1581,3 @@ | ||
var last = get(result, key); | ||
var next = handler.call(domain, last, action.payload); | ||
var next = handler.call(source, last, action.payload); | ||
@@ -1649,19 +1591,33 @@ result = set(result, key, next); | ||
DomainEngine.prototype.deserialize = function deserialize(payload) { | ||
return this.reduce(function (memo, key, domain) { | ||
var next = payload; | ||
for (var i = 0; i < this.domains.length; i++) { | ||
var _domains$i2 = this.domains[i], | ||
key = _domains$i2[0], | ||
domain = _domains$i2[1]; | ||
if (domain.deserialize) { | ||
return set(memo, key, domain.deserialize(get(payload, key))); | ||
next = set(next, key, domain.deserialize(get(payload, key))); | ||
} | ||
} | ||
return memo; | ||
}, payload); | ||
return next; | ||
}; | ||
DomainEngine.prototype.serialize = function serialize(state, payload) { | ||
return this.reduce(function (memo, key, domain) { | ||
var next = payload; | ||
for (var i = 0; i < this.domains.length; i++) { | ||
var _domains$i3 = this.domains[i], | ||
key = _domains$i3[0], | ||
domain = _domains$i3[1]; | ||
if (domain.serialize) { | ||
return set(memo, key, domain.serialize(get(state, key))); | ||
next = set(next, key, domain.serialize(get(state, key))); | ||
} | ||
} | ||
return memo; | ||
}, payload); | ||
return next; | ||
}; | ||
@@ -1743,5 +1699,4 @@ | ||
Node.prototype.connect = function connect(node) { | ||
if (node !== this && this.edges.indexOf(node) < 0) { | ||
this.edges.push(node); | ||
} | ||
this.edges.push(node); | ||
}; | ||
@@ -1856,3 +1811,3 @@ | ||
for (var i = 0, len = keyPaths.length; i < len; i++) { | ||
for (var i = keyPaths.length - 1; i >= 0; i--) { | ||
this.addBranch(keyPaths[i], query); | ||
@@ -1915,3 +1870,3 @@ } | ||
if (!this.nodes[id]) { | ||
if (this.nodes.hasOwnProperty(id) === false) { | ||
this.nodes[id] = new Node(id, key, parent); | ||
@@ -1933,3 +1888,3 @@ } | ||
if (!this.queries[id]) { | ||
if (this.queries.hasOwnProperty(id) === false) { | ||
this.queries[id] = new Query(id, dependencies); | ||
@@ -2020,2 +1975,4 @@ } | ||
*/ | ||
function processGenerator(action, body, repo) { | ||
@@ -2232,3 +2189,3 @@ action.open(); | ||
_this.archive = new Archive(); | ||
_this.snapshots = {}; | ||
_this.domains = new DomainEngine(_this); | ||
@@ -2306,4 +2263,8 @@ _this.effects = new EffectEngine(_this); | ||
Microcosm.prototype.recall = function recall(action, fallback) { | ||
return this.archive.get(action, fallback); | ||
Microcosm.prototype.recall = function recall(action) { | ||
if (action && action.id in this.snapshots) { | ||
return this.snapshots[action.id]; | ||
} | ||
return this.initial; | ||
}; | ||
@@ -2318,3 +2279,3 @@ | ||
Microcosm.prototype.createSnapshot = function createSnapshot(action) { | ||
this.archive.create(action); | ||
this.snapshots[action.id] = this.recall(action.parent); | ||
}; | ||
@@ -2328,3 +2289,3 @@ | ||
Microcosm.prototype.updateSnapshot = function updateSnapshot(action) { | ||
var next = this.recall(action.parent, this.initial); | ||
var next = this.recall(action.parent); | ||
@@ -2339,5 +2300,3 @@ if (this.parent) { | ||
this.archive.set(action, next); | ||
this.state = next; | ||
this.state = this.snapshots[action.id] = next; | ||
}; | ||
@@ -2351,3 +2310,3 @@ | ||
Microcosm.prototype.removeSnapshot = function removeSnapshot(action) { | ||
this.archive.remove(action); | ||
delete this.snapshots[action.id]; | ||
}; | ||
@@ -2474,6 +2433,5 @@ | ||
var domain = this.domains.add(key, config, options); | ||
var initial = domain.getInitialState ? domain.getInitialState() : null; | ||
if (domain.getInitialState) { | ||
this.initial = set(this.initial, key, domain.getInitialState()); | ||
} | ||
this.initial = set(this.initial, key, initial); | ||
@@ -2480,0 +2438,0 @@ this.push(ADD_DOMAIN, domain); |
@@ -1,1 +0,1 @@ | ||
"use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}function t(r,t,n){for(var o=e(t),u=r,i=0,l=o.length;i<l&&null!=u;i++)u=u[o[i]];return null==u?n:u}function n(r){return""===r||null===r||void 0===r}function e(r){return Array.isArray(r)?r:n(r)?[]:"string"==typeof r?r.trim().split(p):[r]}function o(r){return"string"==typeof r?(""+r).split(s).map(e):r.every(Array.isArray)?r:r.map(e)}function u(r,t,n){return t.reduce(function(t,n){return i.set(t,n,i.get(r,n))},n||{})}Object.defineProperty(exports,"__esModule",{value:!0});var i=require("../microcosm.js"),l=r(i),a="function"==typeof Symbol?Symbol:{},f=t(a,"toStringTag","@@toStringTag"),p=".",s=",",c=function(){l.prototype.index=function(r,t){for(var n=arguments.length,e=Array(n>2?n-2:0),l=2;l<n;l++)e[l-2]=arguments[l];var a=this,f=o(t),p=null,s=null,c=null,y=function(){for(var r=arguments.length,t=Array(r),n=0;n<r;n++)t[n]=arguments[n];if(a.state!==p){var o=u(p=a.state,f,s);o!==s&&(s=o,c=e.reduce(function(r,t){return t.call(a,r,p)},s))}return t.reduce(function(r,t){return t.call(a,r,p)},c)};return this.indexes=i.set(this.indexes||{},r,y),y},l.prototype.lookup=function(r){var t=i.get(this.indexes,r);if(null==t){if(this.parent)return this.parent.lookup(r);throw new TypeError("Unable to find missing index "+r)}return t},l.prototype.compute=function(r){for(var t=arguments.length,n=Array(t>1?t-1:0),e=1;e<t;e++)n[e-1]=arguments[e];return this.lookup(r).apply(void 0,n)},l.prototype.memo=function(r){for(var t=arguments.length,n=Array(t>1?t-1:0),e=1;e<t;e++)n[e-1]=arguments[e];var o=this.lookup(r),u=null,i=null;return function(){var r=o();return r!==u&&(u=r,i=o.apply(void 0,n)),i}}};exports.default=c; | ||
"use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}function t(r,t,n){for(var e=o(t),u=r,i=0,l=e.length;i<l&&null!=u;i++)u=u[e[i]];return null==u?n:u}function n(r){return!!r&&"function"==typeof r}function e(r){return""===r||null===r||void 0===r}function o(r){return Array.isArray(r)?r:e(r)?[]:"string"==typeof r?r.trim().split(c):[r]}function u(r){return"string"==typeof r?(""+r).split(y).map(o):r.every(Array.isArray)?r:r.map(o)}function i(r,t,n){return t.reduce(function(t,n){return l.set(t,n,l.get(r,n))},n||{})}Object.defineProperty(exports,"__esModule",{value:!0});var l=require("../microcosm.js"),a=r(l),f=n(Symbol)?Symbol:{},p=t(f,"toStringTag","@@toStringTag"),s=t(f,"iterator","@@iterator"),c=".",y=",",d=function(){a.prototype.index=function(r,t){for(var n=arguments.length,e=Array(n>2?n-2:0),o=2;o<n;o++)e[o-2]=arguments[o];var a=this,f=u(t),p=null,s=null,c=null,y=function(){for(var r=arguments.length,t=Array(r),n=0;n<r;n++)t[n]=arguments[n];if(a.state!==p){var o=i(p=a.state,f,s);o!==s&&(s=o,c=e.reduce(function(r,t){return t.call(a,r,p)},s))}return t.reduce(function(r,t){return t.call(a,r,p)},c)};return this.indexes=l.set(this.indexes||{},r,y),y},a.prototype.lookup=function(r){var t=l.get(this.indexes,r);if(null==t){if(this.parent)return this.parent.lookup(r);throw new TypeError("Unable to find missing index "+r)}return t},a.prototype.compute=function(r){for(var t=arguments.length,n=Array(t>1?t-1:0),e=1;e<t;e++)n[e-1]=arguments[e];return this.lookup(r).apply(void 0,n)},a.prototype.memo=function(r){for(var t=arguments.length,n=Array(t>1?t-1:0),e=1;e<t;e++)n[e-1]=arguments[e];var o=this.lookup(r),u=null,i=null;return function(){var r=o();return r!==u&&(u=r,i=o.apply(void 0,n)),i}}};exports.default=d; |
@@ -1,1 +0,1 @@ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function e(t){return t&&"function"==typeof t.subscribe}function r(t){return t&&"function"==typeof t.call}function n(t,e,n){return r(t)?t.call(n,e.state,e):t}function o(){return this.props.children?i.Children.only(this.props.children):null}Object.defineProperty(exports,"__esModule",{value:!0});var i=t(require("react")),s=require("../microcosm.js"),p=t(s),u=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},a=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},c=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},h=function(t){function r(e,n){u(this,r);var o=c(this,t.call(this));return o.repo=e,o.scope=n,o.bindings={},o.subscriptions={},o.value={},o.repo.on("change",o.compute,o),o}return a(r,t),r.prototype.track=function(t,e){var r=this,n=this.subscriptions[t],o=e.subscribe(function(e){return r.set(t,e)});this.subscriptions[t]=o,n&&n.unsubscribe()},r.prototype.bind=function(t){this.bindings={};for(var r in t){var n=t[r];e(n)?this.track(r,n):this.bindings[r]=n}this.compute()},r.prototype.set=function(t,e){var r=s.set(this.value,t,e);this.value!==r&&(this.value=r,this._emit("change",this.value))},r.prototype.compute=function(){var t=this.value,e=t;for(var r in this.bindings){var o=n(this.bindings[r],this.repo,this.scope);e=s.set(e,r,o)}t!==e&&(this.value=e,this._emit("change",e))},r.prototype.teardown=function(){for(var t in this.subscriptions)this.subscriptions[t].unsubscribe();this.repo.off("change",this.compute,this)},r}(s.Emitter),d=function(){},f=function(t){function e(r,n){u(this,e);var i=c(this,t.call(this));return i.render!==e.prototype.render?(i.defaultRender=i.render,i.render=e.prototype.render):i.defaultRender=o,i.send=i.send.bind(i),i}return a(e,t),e.prototype._beginSetup=function(t){this.repo=t.repo,this.mediator=t,this.setup(this.repo,this.props,this.state),this.model=this.mediator.updateModel(this.props,this.state),this.ready(this.repo,this.props,this.state)},e.prototype._beginTeardown=function(){this.teardown(this.repo,this.props,this.state)},e.prototype._requestRepo=function(t){var e=this.props.repo||t,r=this.getRepo(e,this.props);return this.didFork=r!==e,r},e.prototype.setup=function(t,e,r){},e.prototype.ready=function(t,e,r){},e.prototype.update=function(t,e,r){},e.prototype.teardown=function(t,e,r){},e.prototype.intercept=function(){return{}},e.prototype.componentWillUpdate=function(t,e){this.model=this.mediator.updateModel(t,e),this.update(this.repo,t,e)},e.prototype.getRepo=function(t,e){return t?t.fork():new p},e.prototype.send=function(t){for(var e,r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return(e=this.mediator).send.apply(e,[t].concat(n))},e.prototype.getModel=function(t,e){return{}},e.prototype.render=function(){return i.createElement(l,{presenter:this,parentState:this.state,parentProps:this.props})},e}(i.PureComponent),l=function(t){function e(r,n){u(this,e);var o=c(this,t.call(this,r,n));return o.presenter=r.presenter,o.repo=o.presenter._requestRepo(n.repo),o.send=o.send.bind(o),o.state={repo:o.repo,send:o.send},o.model=new h(o.repo,o.presenter),o.model.on("change",o.updateState,o),o}return a(e,t),e.prototype.getChildContext=function(){return{repo:this.repo,send:this.send,parent:this}},e.prototype.componentWillMount=function(){this.presenter._beginSetup(this)},e.prototype.componentDidMount=function(){this.presenter.refs=this.refs},e.prototype.componentWillUnmount=function(){this.presenter.refs=this.refs,this.presenter.didFork&&this.repo.shutdown(),this.model.teardown(),this.presenter._beginTeardown()},e.prototype.render=function(){this.presenter.model=this.state;var t=this.presenter.view;return null!=t?i.createElement(t,s.merge(this.presenter.props,this.state)):this.presenter.defaultRender()},e.prototype.updateState=function(t){this.setState(t)},e.prototype.updateModel=function(t,e){var r=this.presenter.getModel(t,e);return this.model.bind(r),this.model.value},e.prototype.getParent=function(){return this.context.parent},e.prototype.getHandler=function(t){var e=this.presenter.intercept();return s.getRegistration(e,t,"resolve")},e.prototype.send=function(t){for(var e,r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];for(var i=s.tag(t),p=this;p;){var u=p.getHandler(i);if(u)return u.call.apply(u,[p.presenter,p.repo].concat(n));p=p.getParent()}return(e=this.repo).push.apply(e,arguments)},e}(i.PureComponent);l.contextTypes={repo:d,send:d,parent:d},l.childContextTypes={repo:d,send:d,parent:d},exports.default=f; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function e(t){return t&&"function"==typeof t.subscribe}function r(t){return t&&"function"==typeof t.call}function n(t,e,n){return r(t)?t.call(n,e.state,e):t}function o(){return this.props.children?s.Children.only(this.props.children):null}function i(){return s.createElement(y,{presenter:this,parentState:this.state,parentProps:this.props})}Object.defineProperty(exports,"__esModule",{value:!0});var s=t(require("react")),p=require("../microcosm.js"),u=t(p),a=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},c=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},h=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},f=function(t){function r(e,n){a(this,r);var o=h(this,t.call(this));return o.repo=e,o.scope=n,o.bindings={},o.subscriptions={},o.value={},o.repo.on("change",o.compute,o),o}return c(r,t),r.prototype.track=function(t,e){var r=this,n=this.subscriptions[t],o=e.subscribe(function(e){return r.set(t,e)});this.subscriptions[t]=o,n&&n.unsubscribe()},r.prototype.bind=function(t){this.bindings={};for(var r in t){var n=t[r];e(n)?this.track(r,n):this.bindings[r]=n}this.compute()},r.prototype.set=function(t,e){var r=p.set(this.value,t,e);this.value!==r&&(this.value=r,this._emit("change",this.value))},r.prototype.compute=function(){var t=this.value,e=t;for(var r in this.bindings){var o=n(this.bindings[r],this.repo,this.scope);e=p.set(e,r,o)}t!==e&&(this.value=e,this._emit("change",e))},r.prototype.teardown=function(){for(var t in this.subscriptions)this.subscriptions[t].unsubscribe();this.repo.off("change",this.compute,this)},r}(p.Emitter),d=function(){},l=function(t){function e(r,n){a(this,e);var s=h(this,t.call(this));return s.render?s.defaultRender=s.render:s.defaultRender=o,s.render=i,s.send=s.send.bind(s),s}return c(e,t),e.prototype._beginSetup=function(t){this.repo=t.repo,this.mediator=t,this.setup(this.repo,this.props,this.state),this.model=this.mediator.updateModel(this.props,this.state),this.ready(this.repo,this.props,this.state)},e.prototype._beginTeardown=function(){this.teardown(this.repo,this.props,this.state)},e.prototype._requestRepo=function(t){var e=this.props.repo||t,r=this.getRepo(e,this.props);return this.didFork=r!==e,r},e.prototype.setup=function(t,e,r){},e.prototype.ready=function(t,e,r){},e.prototype.update=function(t,e,r){},e.prototype.teardown=function(t,e,r){},e.prototype.intercept=function(){return{}},e.prototype.componentWillUpdate=function(t,e){this.model=this.mediator.updateModel(t,e),this.update(this.repo,t,e)},e.prototype.getRepo=function(t,e){return t?t.fork():new u},e.prototype.send=function(t){for(var e,r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return(e=this.mediator).send.apply(e,[t].concat(n))},e.prototype.getModel=function(t,e){return{}},e}(s.PureComponent),y=function(t){function e(r,n){a(this,e);var o=h(this,t.call(this,r,n));return o.presenter=r.presenter,o.repo=o.presenter._requestRepo(n.repo),o.send=o.send.bind(o),o.state={repo:o.repo,send:o.send},o.model=new f(o.repo,o.presenter),o.model.on("change",o.updateState,o),o}return c(e,t),e.prototype.getChildContext=function(){return{repo:this.repo,send:this.send,parent:this}},e.prototype.componentWillMount=function(){this.presenter._beginSetup(this)},e.prototype.componentDidMount=function(){this.presenter.refs=this.refs},e.prototype.componentWillUnmount=function(){this.presenter.refs=this.refs,this.presenter.didFork&&this.repo.shutdown(),this.model.teardown(),this.presenter._beginTeardown()},e.prototype.render=function(){this.presenter.model=this.state;var t=this.presenter.view;return null!=t?s.createElement(t,p.merge(this.presenter.props,this.state)):this.presenter.defaultRender()},e.prototype.updateState=function(t){this.setState(t)},e.prototype.updateModel=function(t,e){var r=this.presenter.getModel(t,e);return this.model.bind(r),this.model.value},e.prototype.getParent=function(){return this.context.parent},e.prototype.getHandler=function(t){var e=this.presenter.intercept();return p.getRegistration(e,t,"resolve")},e.prototype.send=function(t){for(var e,r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];for(var i=p.tag(t),s=this;s;){var u=s.getHandler(i);if(u)return u.call.apply(u,[s.presenter,s.repo].concat(n));s=s.getParent()}return(e=this.repo).push.apply(e,arguments)},e}(s.PureComponent);y.contextTypes={repo:d,send:d,parent:d},y.childContextTypes={repo:d,send:d,parent:d},exports.default=l; |
@@ -1,1 +0,1 @@ | ||
"use strict";function t(t){return Array.isArray(t)?t:f(t)?[]:"string"==typeof t?t.trim().split(x):[t]}function e(e){return"string"==typeof e?(""+e).split(z).map(t):e.every(Array.isArray)?e:e.map(t)}function n(t){return t.join(x)}function r(t){return t.map(n).join(z)}function i(t){return""+t+R++}function o(t){if(Array.isArray(t))return t.slice(0);if(!1===h(t))return{};var e={};for(var n in t)e[n]=t[n];return e}function s(){for(var t=null,e=null,n=arguments.length,r=Array(n),i=0;i<n;i++)r[i]=arguments[i];for(var s=0,a=r.length;s<a;s++){t=t||r[s],e=e||t;var p=r[s];for(var u in p)t[u]!==p[u]&&(t===e&&(t=o(e)),t[u]=p[u])}return t||{}}function a(e,n,r){for(var i=t(n),o=e,s=0,a=i.length;s<a&&null!=o;s++)o=o[i[s]];return null==o?r:o}function p(e,n,r){var i=t(n),s=i.length;if(s<=0)return r;if(a(e,i)===r)return e;for(var p=o(e),u=p,h=0;h<s;h++){var c=i[h],f=r;h<s-1&&(f=c in u?o(u[c]):{}),u[c]=f,u=u[c]}return p}function u(t){return(h(t)||c(t))&&c(t.then)}function h(t){return!(!t||"object"!==(void 0===t?"undefined":A(t)))}function c(t){return!!t&&"function"==typeof t}function f(t){return""===t||null===t||void 0===t}function l(t){return t?t[P]||"":""}function d(t){return"GeneratorFunction"===l(t)}function y(t,e,n){return c(t)?new t(e,n):Object.create(t)}function v(e,n,r,i){var o=t(n);return!1===c(r)?p(e,o,r):p(e,o,r(a(e,o,i)))}function g(t,e){if("string"==typeof t)return g(function(t){return t},t);if(!0===t.__tagged)return t;H+=1;var n=e||(t.name||L)+"."+H,r=t;return r.open=n+".open",r.loading=n+".loading",r.update=r.loading,r.done=n,r.resolve=r.done,r.error=n+".error",r.reject=r.error,r.cancel=n+".cancel",r.cancelled=t.cancel,r.toString=function(){return n},t.__tagged=!0,r}function m(t){return function(e){!0===t.batch?N(e,M):e()}}function b(t,e){return function(n,r){var i=t;if(e)try{i=r.deserialize(t)}catch(t){throw n.reject(t),t}var o=r.domains.sanitize(i);n.resolve(o)}}function _(t,e,n){var r=Y[n],i=t[e],o=e[n]||"";return h(i)?i[r]||i[n]:t[o]}function S(t,e,n){function r(e){var n=o.next(e);n.done?t.resolve(e):i(n.value)}function i(e){return Array.isArray(e)?i(n.parallel(e)):(e.onDone(r),e.onCancel(t.cancel,t),e.onError(t.reject,t),e)}t.open();var o=e(n);return r(),t}function w(t,e,n,r){if("string"==typeof e)return t.resolve.apply(t,n);var i=e.apply(null,n);return u(i)?(t.open.apply(t,n),i.then(function(e){return global.setTimeout(function(){return t.resolve(e)},0)},function(e){return global.setTimeout(function(){return t.reject(e)},0)}),t):d(i)?S(t,i,r):c(i)?(i(t,r),t):t.resolve(i)}function O(t){var e=global.__MICROCOSM_DEVTOOLS_GLOBAL_HOOK__;e&&(e.emit("init",t),t.history.setLimit(1/0))}Object.defineProperty(exports,"__esModule",{value:!0});var x=".",z=",",A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},k=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},j=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),E=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},I=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},R=0,D="function"==typeof Symbol?Symbol:{},P=a(D,"toStringTag","@@toStringTag"),q=function(){function t(){k(this,t),this._events=[]}return t.prototype.on=function(t,e,n){var r={event:t,fn:e,scope:n,once:!1};return this._events.push(r),this},t.prototype.once=function(t,e,n){var r={event:t,fn:e,scope:n,once:!0};return this._events.push(r),this},t.prototype.off=function(t,e,n){for(var r=null==e,i=0;i<this._events.length;){var o=this._events[i];o.event===t&&(r||o.fn===e&&o.scope===n)?this._events.splice(i,1):i+=1}return this},t.prototype.removeAllListeners=function(){this._events.length=0},t.prototype._emit=function(t){for(var e=0,n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];for(;e<this._events.length;){var o=this._events[e];o.event===t&&(o.fn.apply(o.scope||this,r),o.once)?this._events.splice(e,1):e+=1}return this},t.prototype._removeScope=function(t){for(var e=0;e<this._events.length;)t!==this._events[e].scope?e+=1:this._events.splice(e,1)},t}(),H=0,L="_action",T={inactive:!1,open:!1,update:!1,resolve:!0,reject:!0,cancel:!0},C=function(t){function e(n,r){k(this,e);var o=I(this,t.call(this));return o.id=i("action"),o.command=g(n),o.status="inactive",o.payload=void 0,o.disabled=!1,o.complete=!1,o.parent=null,o.next=null,o.timestamp=Date.now(),o.children=[],o.revisions=[],r&&o.setState(r),o}return E(e,t),e.prototype.onOpen=function(t,e){return this._callOrSubscribeOnce("open",t,e),this},e.prototype.onUpdate=function(t,e){return t&&this.on("update",t,e),this},e.prototype.onDone=function(t,e){return this._callOrSubscribeOnce("resolve",t,e),this},e.prototype.onError=function(t,e){return this._callOrSubscribeOnce("reject",t,e),this},e.prototype.onCancel=function(t,e){return this._callOrSubscribeOnce("cancel",t,e),this},e.prototype.is=function(t){return this.command[this.status]===this.command[t]},e.prototype.toggle=function(t){return this.disabled=!this.disabled,t||this._emit("change",this),this},e.prototype.link=function(t){var e=this,n=t.length,r=function(){(n-=1)<=0&&e.resolve()};return t.forEach(function(t){t.onDone(r),t.onCancel(r),t.onError(e.reject)}),this},e.prototype.then=function(t,e){var n=this;return new Promise(function(t,e){n.onDone(t),n.onError(e)}).then(t,e)},e.prototype.isDisconnected=function(){return!this.parent},e.prototype.prune=function(){this.parent&&(this.parent.parent=null)},e.prototype.lead=function(t){this.next=t,t&&this.adopt(t)},e.prototype.adopt=function(t){this.children.indexOf(t)<0&&this.children.push(t),t.parent=this},e.prototype.remove=function(){this.parent&&this.parent.abandon(this),this.removeAllListeners()},e.prototype.abandon=function(t){var e=this.children.indexOf(t);e>=0&&(this.children.splice(e,1),t.parent=null),this.next===t&&this.lead(t.next)},e.prototype._callOrSubscribeOnce=function(t,e,n){e&&(this.is(t)?e.call(n,this.payload):this.once(t,e,n))},e.prototype.setState=function(t,e){return this.complete?this:(this.status=t,this.complete=T[t],arguments.length>1&&(this.payload=e),this.revisions.push({status:this.status,payload:this.payload,timestamp:Date.now()}),this._emit("change",this),this._emit(t,this.payload),this)},e.prototype.toJSON=function(){return{id:this.id,status:this.status,type:this.type,payload:this.payload,disabled:this.disabled,children:this.children,revisions:this.revisions,next:this.next&&this.next.id}},j(e,[{key:"type",get:function(){return this.command[this.status]||""}},{key:"open",get:function(){return this.setState.bind(this,"open")}},{key:"update",get:function(){return this.setState.bind(this,"update")}},{key:"resolve",get:function(){return this.setState.bind(this,"resolve")}},{key:"reject",get:function(){return this.setState.bind(this,"reject")}},{key:"cancel",get:function(){return this.setState.bind(this,"cancel")}}]),e}(q),N=global.requestIdleCallback||function(t){return setTimeout(t,4)},M={timeout:36},G=function(t,e){return b(t,e)},J=function(t,e){return b(t,e)},K=function(){},B=function(){},U=function(t){return t},Q={maxHistory:1,batch:!1,updater:m},F=function(t){function e(n){k(this,e);var r=I(this,t.call(this)),i=s(Q,n);return r.size=0,r.setLimit(i.maxHistory),r.updater=i.updater(i),r.releasing=!1,r.release=function(){return r.closeRelease()},r.begin(),r}return E(e,t),e.prototype.checkout=function(t){var e=this.sharedRoot(t);this.head=t||this.head;for(var n=this.head;n&&n!==e;){var r=n.parent;r&&r.lead(n),n=r}return this.setSize(),this.reconcile(e),this},e.prototype.toggle=function(t){var e=[].concat(t);e.forEach(function(t){return t.toggle(!0)});var n=void 0,r=1/0,i=this.toArray();e.forEach(function(t){var e=i.indexOf(t);e>=0&&e<r&&(r=e,n=t)}),n&&this.reconcile(n)},e.prototype.toArray=function(){return this.map(function(t){return t})},e.prototype.map=function(t,e){for(var n=[],r=this.root;r&&(n.push(t.call(e,r)),r!=this.head);)r=r.next;return n},e.prototype.wait=function(){var t=this,e=new C("GROUP");return e.link(this.toArray()),e.then(function(){if(t.releasing)return new Promise(function(e){t.once("release",e)})})},e.prototype.then=function(t,e){return this.wait().then(t,e)},e.prototype.begin=function(){this.root=this.head=this.append(B,"resolve")},e.prototype.append=function(t,e){var n=new C(t,e);return this.head?this.head.lead(n):(new C(K,"resolve").adopt(n),this.root=n),this.head=n,this.size+=1,this._emit("append",n),n.on("change",this.reconcile,this),n},e.prototype.remove=function(t){if(!t.isDisconnected()){var e=t.parent,n=t.next,r=this.isActive(t);this.clean(t),this.size<=0?this.begin():(t===this.head&&e?n=this.head=e:t===this.root&&n&&(this.root=n),n&&r&&!t.disabled&&this.reconcile(n))}},e.prototype.clean=function(t){this.size-=1,this._emit("remove",t),t.remove()},e.prototype.reconcile=function(t){for(var e=t;e&&(this._emit("update",e),e!==this.head);)e=e.next;this.archive(),this._emit("reconcile",t),this.queueRelease()},e.prototype.queueRelease=function(){!1===this.releasing&&(this.releasing=!0,this.updater(this.release))},e.prototype.closeRelease=function(){this.releasing=!1,this._emit("release")},e.prototype.archive=function(){for(var t=this.size,e=this.root;t>this.limit&&e.complete;)t-=1,this._emit("remove",e.parent),e.next&&(e=e.next);e.prune(),this.root=e,this.size=t},e.prototype.setSize=function(){for(var t=this.head,e=1;t&&t!==this.root;)t=t.parent,e+=1;this.size=e},e.prototype.setLimit=function(t){this.limit=Math.max(0,t)},e.prototype.isActive=function(t){for(var e=t;e;){if(e===this.head)return!0;e=e.next}return!1},e.prototype.sharedRoot=function(t){for(var e=t;e;){if(this.isActive(e))return e;e=e.parent}return this.head},e.prototype.toJSON=function(){return{head:this.head.id,root:this.root.id,size:this.size,tree:this.root}},e}(q),V=function(){function t(){k(this,t),this.pool={}}return t.prototype.create=function(t){this.set(t,this.get(t.parent))},t.prototype.get=function(t,e){return t&&this.has(t)?this.pool[t.id]:null==e?{}:e},t.prototype.has=function(t){return void 0!==this.pool[t.id]},t.prototype.set=function(t,e){this.pool[t.id]=e},t.prototype.remove=function(t){delete this.pool[t.id]},t}(),W=function(){function t(){k(this,t)}return t.prototype.setup=function(t){this.repo=t},t.prototype.reset=function(t,e){var n=this.repo.domains.sanitize(e);return s(t,this.repo.getInitialState(),n)},t.prototype.patch=function(t,e){return s(t,this.repo.domains.sanitize(e))},t.prototype.addDomain=function(t){return s(this.repo.getInitialState(),t)},t.prototype.register=function(){var t;return t={},t[G.toString()]=this.reset,t[J.toString()]=this.patch,t[U.toString()]=this.addDomain,t},t}(),X=function t(e,n,r){k(this,t),this.key=e,this.domain=n,this.handler=r},Y={inactive:"inactive",open:"open",update:"loading",loading:"update",done:"resolve",resolve:"done",reject:"error",error:"reject",cancel:"cancelled",cancelled:"cancel"},Z=function(){function e(t){k(this,e),this.repo=t,this.registry={},this.domains=[],this.add([],W)}return e.prototype.getRepoHandlers=function(t){var e=t.command,n=t.status,r=_(this.repo.register(),e,n);return r?[new X([],this.repo,r)]:[]},e.prototype.getHandlers=function(t){for(var e=this.getRepoHandlers(t),n=t.command,r=t.status,i=0,o=this.domains.length;i<o;i++){var s=this.domains[i],a=s[0],p=s[1];if(p.register){var u=_(p.register(),n,r);u&&e.push(new X(a,p,u))}}return e},e.prototype.register=function(t){var e=t.type;return this.registry[e]||(this.registry[e]=this.getHandlers(t)),this.registry[e]},e.prototype.add=function(e,n,r){var i=y(n,r,this.repo),o=t(e);return this.domains.push([o,i]),this.registry={},i.setup&&i.setup(this.repo,r),i.teardown&&this.repo.on("teardown",i.teardown,i),i},e.prototype.reduce=function(t,e,n){for(var r=e,i=1,o=this.domains.length;i<o;i++){var s=this.domains[i],a=s[0],p=s[1];r=t.call(n,r,a,p)}return r},e.prototype.supportsKey=function(t){return t in this.repo.state||this.domains.some(function(e){return n(e[0])===t})},e.prototype.sanitize=function(t){var e=this.repo.parent,n={};for(var r in t)e&&e.domains.supportsKey(r)||this.supportsKey(r)&&(n[r]=t[r]);return n},e.prototype.dispatch=function(t,e){for(var n=this.register(e),r=t,i=0,o=n.length;i<o;i++){var s=n[i],u=s.key,h=s.domain,c=s.handler,f=a(r,u);r=p(r,u,c.call(h,f,e.payload))}return r},e.prototype.deserialize=function(t){return this.reduce(function(e,n,r){return r.deserialize?p(e,n,r.deserialize(a(t,n))):e},t)},e.prototype.serialize=function(t,e){return this.reduce(function(e,n,r){return r.serialize?p(e,n,r.serialize(a(t,n))):e},e)},e}(),$=function(){function t(e){k(this,t),this.repo=e,this.effects=[]}return t.prototype.add=function(t,e){var n=y(t,e,this.repo);return n.setup&&n.setup(this.repo,e),n.teardown&&this.repo.on("teardown",n.teardown,n),this.effects.push(n),n},t.prototype.dispatch=function(t){for(var e=t.command,n=t.payload,r=t.status,i=0,o=this.effects.length;i<o;i++){var s=this.effects[i];if(s.register){var a=_(s.register(),e,r);a&&a.call(s,this.repo,n)}}},t}(),tt=function(){function t(e,n,r){k(this,t),this.id=e,this.key=n,this.edges=[],this.parent=r||null,r&&r.connect(this)}return t.getId=function(t,e){return e&&e.id?e.id+"."+t:t},t.prototype.connect=function(t){t!==this&&this.edges.indexOf(t)<0&&this.edges.push(t)},t.prototype.disconnect=function(t){var e=this.edges.indexOf(t);~e&&this.edges.splice(e,1)},t.prototype.isAlone=function(){return this.edges.length<=0},t.prototype.orphan=function(){this.parent&&this.parent.disconnect(this)},t}(),et=function(t){function e(n,r){k(this,e);var i=I(this,t.call(this));return i.id=n,i.keyPaths=r,i}return E(e,t),e.getId=function(t){return"query:"+r(t)},e.prototype.trigger=function(t){for(var e=["change"],n=0,r=this.keyPaths.length;n<r;n++)e[n+1]=a(t,this.keyPaths[n]);this._emit.apply(this,e)},e.prototype.isAlone=function(){return this._events.length<=0},e}(q),nt="",rt=function(){function t(e){k(this,t),this.snapshot=e,this.nodes={},this.queries={}}return t.prototype.on=function(t,n,r){for(var i=e(t),o=this.addQuery(i),s=0,a=i.length;s<a;s++)this.addBranch(i[s],o);return o.on("change",n,r),o},t.prototype.off=function(t,n,r){var i=e(t),o=et.getId(i),s=this.queries[o];s&&(s.off("change",n,r),s.isAlone()&&this.prune(s))},t.prototype.update=function(t){var e=this.snapshot;if(this.snapshot=t,this.nodes[nt])for(var n=this.scan(this.nodes[nt],e,t,[]),r=0;r<n.length;r++)n[r].trigger(t)},t.prototype.addNode=function(t,e){var n=tt.getId(t,e);return this.nodes[n]||(this.nodes[n]=new tt(n,t,e)),this.nodes[n]},t.prototype.addQuery=function(t){var e=et.getId(t);return this.queries[e]||(this.queries[e]=new et(e,t)),this.queries[e]},t.prototype.prune=function(t){for(var e=t.keyPaths.map(n),r=0,i=e.length;r<i;r++){var o=this.nodes[e[r]];o.disconnect(t);do{if(!o.isAlone())break;o.orphan(),delete this.nodes[o.id],o=o.parent}while(o)}delete this.queries[t.id]},t.prototype.addBranch=function(t,e){for(var n=this.addNode(nt,null),r=0,i=t.length;r<i;r++)n=this.addNode(t[r],n);n.connect(e)},t.prototype.scan=function(t,e,n,r){if(e!==n)for(var i=t.edges,o=0,s=i.length;o<s;o++){var a=i[o];if(a instanceof et&&r.indexOf(a)<0)r.push(a);else if(a instanceof tt){var p=null==e?e:e[a.key],u=null==n?n:n[a.key];this.scan(a,p,u,r)}}return r},t}(),it={maxHistory:0,parent:null,batch:!1,debug:!1},ot=function(t){function e(n,r,i){k(this,e);var o=I(this,t.call(this)),a=s(it,o.constructor.defaults,n||{});return o.parent=a.parent,o.initial=o.parent?o.parent.initial:o.getInitialState(),o.state=o.parent?o.parent.state:o.initial,o.history=o.parent?o.parent.history:new F(a),o.archive=new V,o.domains=new Z(o),o.effects=new $(o),o.changes=new rt(o.state),o.history.on("append",o.createSnapshot,o),o.history.on("update",o.updateSnapshot,o),o.history.on("remove",o.removeSnapshot,o),o.history.on("reconcile",o.dispatchEffect,o),o.history.on("release",o.release,o),o.setup(a),r&&o.reset(r,i),a.debug&&O(o),o}return E(e,t),e.prototype.setup=function(t){},e.prototype.teardown=function(){},e.prototype.getInitialState=function(){return null==this.initial?{}:this.initial},e.prototype.recall=function(t,e){return this.archive.get(t,e)},e.prototype.createSnapshot=function(t){this.archive.create(t)},e.prototype.updateSnapshot=function(t){var e=this.recall(t.parent,this.initial);this.parent&&(e=s(e,this.parent.recall(t))),t.disabled||(e=this.domains.dispatch(e,t)),this.archive.set(t,e),this.state=e},e.prototype.removeSnapshot=function(t){this.archive.remove(t)},e.prototype.dispatchEffect=function(t){this.effects.dispatch(t)},e.prototype.release=function(){this.changes.update(this.state)},e.prototype.on=function(t,e,n){var r=t.split(":",2),i=r[0],o=r[1];switch(i){case"change":this.changes.on(o||"",e,n);break;default:q.prototype.on.apply(this,arguments)}return this},e.prototype.off=function(t,e,n){var r=t.split(":",2),i=r[0],o=r[1];switch(i){case"change":this.changes.off(o||"",e,n);break;default:q.prototype.off.apply(this,arguments)}return this},e.prototype.append=function(t,e){return this.history.append(t,e)},e.prototype.push=function(t){for(var e=this.append(t),n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return w(e,t,r,this),e},e.prototype.prepare=function(t){for(var e=this,n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return function(){for(var n=arguments.length,i=Array(n),o=0;o<n;o++)i[o]=arguments[o];return e.push.apply(e,[t].concat(r,i))}},e.prototype.addDomain=function(t,e,n){var r=this.domains.add(t,e,n);return r.getInitialState&&(this.initial=p(this.initial,t,r.getInitialState())),this.push(U,r),r},e.prototype.addEffect=function(t,e){return this.effects.add(t,e)},e.prototype.reset=function(t,e){return this.push(G,t,e)},e.prototype.patch=function(t,e){return this.push(J,t,e)},e.prototype.register=function(){return{}},e.prototype.deserialize=function(t){var e=t;return this.parent?e=this.parent.deserialize(t):"string"==typeof e&&(e=JSON.parse(e)),this.domains.deserialize(e)},e.prototype.serialize=function(){var t=this.parent?this.parent.serialize():{};return this.domains.serialize(this.state,t)},e.prototype.toJSON=function(){return this.serialize()},e.prototype.checkout=function(t){return this.history.checkout(t),this},e.prototype.fork=function(){return new e({parent:this})},e.prototype.shutdown=function(){this.teardown(),this._emit("teardown",this),this.history._removeScope(this),this.removeAllListeners()},e.prototype.parallel=function(t){return this.append("GROUP").link(t)},e}(q);exports.default=ot,exports.Microcosm=ot,exports.Action=C,exports.History=F,exports.Emitter=q,exports.tag=g,exports.get=a,exports.set=p,exports.update=v,exports.merge=s,exports.getRegistration=_; | ||
"use strict";function t(t){return Array.isArray(t)?t:f(t)?[]:"string"==typeof t?t.trim().split(A):[t]}function e(e){return"string"==typeof e?(""+e).split(k).map(t):e.every(Array.isArray)?e:e.map(t)}function n(t){return t.join(A)}function r(t){return t.map(n).join(k)}function i(t){return""+t+H++}function o(t,e){var n={};for(var r in e)r in t&&(n[r]=e[r]);return n}function s(t){if(Array.isArray(t))return t.slice(0);if(!1===c(t))return{};var e={};for(var n in t)e[n]=t[n];return e}function a(){for(var t=null,e=null,n=arguments.length,r=Array(n),i=0;i<n;i++)r[i]=arguments[i];for(var o=0,a=r.length;o<a;o++){t=t||r[o],e=e||t;var h=r[o];for(var u in h)t[u]!==h[u]&&(t===e&&(t=s(e)),t[u]=h[u])}return t||{}}function h(e,n,r){for(var i=t(n),o=e,s=0,a=i.length;s<a&&null!=o;s++)o=o[i[s]];return null==o?r:o}function u(e,n,r){var i=t(n),o=i.length;if(o<=0)return r;if(h(e,i)===r)return e;for(var a=s(e),u=a,p=0;p<o;p++){var c=i[p],l=r;p<o-1&&(l=c in u?s(u[c]):{}),u[c]=l,u=u[c]}return a}function p(t){return(c(t)||l(t))&&l(t.then)}function c(t){return!(!t||"object"!==(void 0===t?"undefined":P(t)))}function l(t){return!!t&&"function"==typeof t}function f(t){return""===t||null===t||void 0===t}function d(t){return t?t[j]||"":""}function y(t){return"GeneratorFunction"===d(t)}function v(t,e,n){return l(t)?new t(e,n):Object.create(t)}function g(e,n,r,i){var o=t(n);return!1===l(r)?u(e,o,r):u(e,o,r(h(e,o,i)))}function m(t,e){if("string"==typeof t)return m(function(t){return t},t);if(!0===t.__tagged)return t;T+=1;var n=e||(t.name||C)+"."+T,r=t;return r.open=n+".open",r.loading=n+".loading",r.update=r.loading,r.done=n,r.resolve=r.done,r.error=n+".error",r.reject=r.error,r.cancel=n+".cancel",r.cancelled=t.cancel,r.toString=function(){return n},t.__tagged=!0,r}function b(t){return function(e){!0===t.batch?G(e,J):e()}}function S(t,e){return function(n,r){var i=t;if(e)try{i=r.deserialize(t)}catch(t){throw n.reject(t),t}n.resolve(o(r.state,i))}}function _(t,e,n){var r=Y[n],i=t[e],o=e[n]||"";return c(i)?i[r]||i[n]:t[o]}function w(t,e,n){function r(e){var n=o.next(e);n.done?t.resolve(e):i(n.value)}function i(e){return Array.isArray(e)?i(n.parallel(e)):(e.onDone(r),e.onCancel(t.cancel,t),e.onError(t.reject,t),e)}t.open();var o=e(n);return r(),t}function x(t,e,n,r){if("string"==typeof e)return t.resolve.apply(t,n);var i=e.apply(null,n);return p(i)?(t.open.apply(t,n),i.then(function(e){return global.setTimeout(function(){return t.resolve(e)},0)},function(e){return global.setTimeout(function(){return t.reject(e)},0)}),t):y(i)?w(t,i,r):l(i)?(i(t,r),t):t.resolve(i)}function O(t){var e=global.__MICROCOSM_DEVTOOLS_GLOBAL_HOOK__;e&&(e.emit("init",t),t.history.setLimit(1/0))}Object.defineProperty(exports,"__esModule",{value:!0});var A=".",k=",",z=l(Symbol)?Symbol:{},j=h(z,"toStringTag","@@toStringTag"),E=h(z,"iterator","@@iterator"),P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},I=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},R=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),D=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},q=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},H=0,L=function(){function t(){I(this,t),this._events=[]}return t.prototype.on=function(t,e,n){var r={event:t,fn:e,scope:n,once:!1};return this._events.push(r),this},t.prototype.once=function(t,e,n){var r={event:t,fn:e,scope:n,once:!0};return this._events.push(r),this},t.prototype.off=function(t,e,n){for(var r=null==e,i=0;i<this._events.length;){var o=this._events[i];o.event===t&&(r||o.fn===e&&o.scope===n)?this._events.splice(i,1):i+=1}return this},t.prototype.removeAllListeners=function(){this._events.length=0},t.prototype._emit=function(t){for(var e=0,n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];for(;e<this._events.length;){var o=this._events[e];o.event===t&&(o.fn.apply(o.scope||this,r),o.once)?this._events.splice(e,1):e+=1}return this},t.prototype._removeScope=function(t){for(var e=0;e<this._events.length;)t!==this._events[e].scope?e+=1:this._events.splice(e,1)},t}(),T=0,C="_action",N={inactive:!1,open:!1,update:!1,resolve:!0,reject:!0,cancel:!0},M=function(t){function e(n,r){I(this,e);var o=q(this,t.call(this));return o.id=i("action"),o.command=m(n),o.status="inactive",o.payload=void 0,o.disabled=!1,o.complete=!1,o.parent=null,o.next=null,o.timestamp=Date.now(),o.children=[],o.revisions=[],r&&o.setState(r),o}return D(e,t),e.prototype.onOpen=function(t,e){return this._callOrSubscribeOnce("open",t,e),this},e.prototype.onUpdate=function(t,e){return t&&this.on("update",t,e),this},e.prototype.onDone=function(t,e){return this._callOrSubscribeOnce("resolve",t,e),this},e.prototype.onError=function(t,e){return this._callOrSubscribeOnce("reject",t,e),this},e.prototype.onCancel=function(t,e){return this._callOrSubscribeOnce("cancel",t,e),this},e.prototype.is=function(t){return this.command[this.status]===this.command[t]},e.prototype.toggle=function(t){return this.disabled=!this.disabled,t||this._emit("change",this),this},e.prototype.link=function(t){var e=this,n=t.length,r=function(){n<=1?e.resolve():n-=1};return t.forEach(function(t){t.onDone(r),t.onCancel(r),t.onError(e.reject)}),r(),this},e.prototype.then=function(t,e){var n=this;return new Promise(function(t,e){n.onDone(t),n.onError(e)}).then(t,e)},e.prototype.isDisconnected=function(){return!this.parent},e.prototype.prune=function(){this.parent&&(this.parent.parent=null)},e.prototype.lead=function(t){this.next=t,t&&this.adopt(t)},e.prototype.adopt=function(t){this.children.indexOf(t)<0&&this.children.push(t),t.parent=this},e.prototype.remove=function(){this.parent&&this.parent.abandon(this),this.removeAllListeners()},e.prototype.abandon=function(t){var e=this.children.indexOf(t);e>=0&&(this.children.splice(e,1),t.parent=null),this.next===t&&this.lead(t.next)},e.prototype._callOrSubscribeOnce=function(t,e,n){e&&(this.is(t)?e.call(n,this.payload):this.once(t,e,n))},e.prototype.setState=function(t,e){return this.complete?this:(this.status=t,this.complete=N[t],arguments.length>1&&(this.payload=e),this.revisions.push({status:this.status,payload:this.payload,timestamp:Date.now()}),this._emit("change",this),this._emit(t,this.payload),this)},e.prototype.toString=function(){return this.command.toString()},e.prototype.toJSON=function(){return{id:this.id,status:this.status,type:this.type,payload:this.payload,disabled:this.disabled,children:this.children,revisions:this.revisions,next:this.next&&this.next.id}},R(e,[{key:"type",get:function(){return this.command[this.status]||""}},{key:"open",get:function(){return this.setState.bind(this,"open")}},{key:"update",get:function(){return this.setState.bind(this,"update")}},{key:"resolve",get:function(){return this.setState.bind(this,"resolve")}},{key:"reject",get:function(){return this.setState.bind(this,"reject")}},{key:"cancel",get:function(){return this.setState.bind(this,"cancel")}}]),e}(L),G=global.requestIdleCallback||function(t){return setTimeout(t,4)},J={timeout:36},B=function(t,e){return S(t,e)},U=function(t,e){return S(t,e)},Q=function(){},F=function(){},K=function(t){return t},V={maxHistory:1,batch:!1,updater:b},W=function(t){function e(n){I(this,e);var r=q(this,t.call(this)),i=a(V,n);return r.size=0,r.setLimit(i.maxHistory),r.updater=i.updater(i),r.releasing=!1,r.release=function(){return r.closeRelease()},r.begin(),r}return D(e,t),e.prototype.checkout=function(t){var e=this.sharedRoot(t);this.head=t||this.head;for(var n=this.head;n&&n!==e;){var r=n.parent;r&&r.lead(n),n=r}return this.setSize(),this.reconcile(e),this},e.prototype.toggle=function(t){var e=[].concat(t);e.forEach(function(t){return t.toggle(!0)});var n=void 0,r=1/0,i=this.toArray();e.forEach(function(t){var e=i.indexOf(t);e>=0&&e<r&&(r=e,n=t)}),n&&this.reconcile(n)},e.prototype.toArray=function(){return this.map(function(t){return t})},e.prototype[E]=function(){var t=this,e=this.root,n={next:function(){var r=e;return null==r?{done:!0}:(e=r==t.head?null:e.next,!r||r.command!==Q&&r.command!==F&&r.command!==K?{value:r,done:!1}:n.next())}};return n},e.prototype.map=function(t,e){for(var n=this[E](),r=n.next(),i=[];!r.done;)i.push(t.call(e,r.value,i.length)),r=n.next();return i},e.prototype.wait=function(){var t=this,e=new M("GROUP");return e.link(this.toArray()),e.then(function(){if(t.releasing)return new Promise(function(e){t.once("release",e)})})},e.prototype.then=function(t,e){return this.wait().then(t,e)},e.prototype.begin=function(){this.root=this.head=this.append(F,"resolve")},e.prototype.append=function(t,e){var n=new M(t,e);return this.head?this.head.lead(n):(new M(Q,"resolve").adopt(n),this.root=n),this.head=n,this.size+=1,this._emit("append",n),n.on("change",this.reconcile,this),n},e.prototype.remove=function(t){if(!t.isDisconnected()){var e=t.parent,n=t.next,r=this.isActive(t);this.clean(t),this.size<=0?this.begin():(t===this.head&&e?n=this.head=e:t===this.root&&n&&(this.root=n),n&&r&&!t.disabled&&this.reconcile(n))}},e.prototype.clean=function(t){this.size-=1,this._emit("remove",t),t.remove()},e.prototype.reconcile=function(t){for(var e=t;e&&(this._emit("update",e),e!==this.head);)e=e.next;this.archive(),this._emit("reconcile",t),this.queueRelease()},e.prototype.queueRelease=function(){!1===this.releasing&&(this.releasing=!0,this.updater(this.release))},e.prototype.closeRelease=function(){this.releasing=!1,this._emit("release")},e.prototype.archive=function(){for(var t=this.size,e=this.root;t>this.limit&&e.complete;)t-=1,this._emit("remove",e.parent),e.next&&(e=e.next);e.prune(),this.root=e,this.size=t},e.prototype.setSize=function(){for(var t=this.head,e=1;t&&t!==this.root;)t=t.parent,e+=1;this.size=e},e.prototype.setLimit=function(t){this.limit=Math.max(0,t)},e.prototype.isActive=function(t){for(var e=t;e;){if(e===this.head)return!0;e=e.next}return!1},e.prototype.sharedRoot=function(t){for(var e=t;e;){if(this.isActive(e))return e;e=e.parent}return this.head},e.prototype.toString=function(){return this.toArray().join(", ")},e.prototype.toJSON=function(){return{head:this.head.id,root:this.root.id,size:this.size,tree:this.root}},e}(L),X=function(){function t(){I(this,t)}return t.prototype.setup=function(t){this.repo=t},t.prototype.reset=function(t,e){var n=o(t,e);return a(t,this.repo.getInitialState(),n)},t.prototype.patch=function(t,e){return a(t,o(t,e))},t.prototype.addDomain=function(t){return a(this.repo.getInitialState(),t)},t.prototype.register=function(){var t;return t={},t[B.toString()]=this.reset,t[U.toString()]=this.patch,t[K.toString()]=this.addDomain,t},t}(),Y={inactive:"inactive",open:"open",update:"loading",loading:"update",done:"resolve",resolve:"done",reject:"error",error:"reject",cancel:"cancelled",cancelled:"cancel"},Z=function(){function e(t){I(this,e),this.repo=t,this.registry={},this.domains=[],this.add([],X)}return e.prototype.getRepoHandlers=function(t){var e=t.command,n=t.status,r=_(this.repo.register(),e,n);return r?[{key:[],source:this.repo,handler:r}]:[]},e.prototype.getHandlers=function(t){for(var e=this.getRepoHandlers(t),n=t.command,r=t.status,i=0,o=this.domains.length;i<o;i++){var s=this.domains[i],a=s[0],h=s[1];if(h.register){var u=_(h.register(),n,r);u&&e.push({key:a,source:h,handler:u})}}return e},e.prototype.register=function(t){var e=t.type;return this.registry[e]||(this.registry[e]=this.getHandlers(t)),this.registry[e]},e.prototype.add=function(e,n,r){var i=v(n,r,this.repo),o=t(e);return this.domains.push([o,i]),this.registry={},i.setup&&i.setup(this.repo,r),i.teardown&&this.repo.on("teardown",i.teardown,i),i},e.prototype.dispatch=function(t,e){for(var n=this.register(e),r=t,i=0,o=n.length;i<o;i++){var s=n[i],a=s.key,p=s.source,c=s.handler,l=h(r,a);r=u(r,a,c.call(p,l,e.payload))}return r},e.prototype.deserialize=function(t){for(var e=t,n=0;n<this.domains.length;n++){var r=this.domains[n],i=r[0],o=r[1];o.deserialize&&(e=u(e,i,o.deserialize(h(t,i))))}return e},e.prototype.serialize=function(t,e){for(var n=e,r=0;r<this.domains.length;r++){var i=this.domains[r],o=i[0],s=i[1];s.serialize&&(n=u(n,o,s.serialize(h(t,o))))}return n},e}(),$=function(){function t(e){I(this,t),this.repo=e,this.effects=[]}return t.prototype.add=function(t,e){var n=v(t,e,this.repo);return n.setup&&n.setup(this.repo,e),n.teardown&&this.repo.on("teardown",n.teardown,n),this.effects.push(n),n},t.prototype.dispatch=function(t){for(var e=t.command,n=t.payload,r=t.status,i=0,o=this.effects.length;i<o;i++){var s=this.effects[i];if(s.register){var a=_(s.register(),e,r);a&&a.call(s,this.repo,n)}}},t}(),tt=function(){function t(e,n,r){I(this,t),this.id=e,this.key=n,this.edges=[],this.parent=r||null,r&&r.connect(this)}return t.getId=function(t,e){return e&&e.id?e.id+"."+t:t},t.prototype.connect=function(t){this.edges.push(t)},t.prototype.disconnect=function(t){var e=this.edges.indexOf(t);~e&&this.edges.splice(e,1)},t.prototype.isAlone=function(){return this.edges.length<=0},t.prototype.orphan=function(){this.parent&&this.parent.disconnect(this)},t}(),et=function(t){function e(n,r){I(this,e);var i=q(this,t.call(this));return i.id=n,i.keyPaths=r,i}return D(e,t),e.getId=function(t){return"query:"+r(t)},e.prototype.trigger=function(t){for(var e=["change"],n=0,r=this.keyPaths.length;n<r;n++)e[n+1]=h(t,this.keyPaths[n]);this._emit.apply(this,e)},e.prototype.isAlone=function(){return this._events.length<=0},e}(L),nt="",rt=function(){function t(e){I(this,t),this.snapshot=e,this.nodes={},this.queries={}}return t.prototype.on=function(t,n,r){for(var i=e(t),o=this.addQuery(i),s=i.length-1;s>=0;s--)this.addBranch(i[s],o);return o.on("change",n,r),o},t.prototype.off=function(t,n,r){var i=e(t),o=et.getId(i),s=this.queries[o];s&&(s.off("change",n,r),s.isAlone()&&this.prune(s))},t.prototype.update=function(t){var e=this.snapshot;if(this.snapshot=t,this.nodes[nt])for(var n=this.scan(this.nodes[nt],e,t,[]),r=0;r<n.length;r++)n[r].trigger(t)},t.prototype.addNode=function(t,e){var n=tt.getId(t,e);return!1===this.nodes.hasOwnProperty(n)&&(this.nodes[n]=new tt(n,t,e)),this.nodes[n]},t.prototype.addQuery=function(t){var e=et.getId(t);return!1===this.queries.hasOwnProperty(e)&&(this.queries[e]=new et(e,t)),this.queries[e]},t.prototype.prune=function(t){for(var e=t.keyPaths.map(n),r=0,i=e.length;r<i;r++){var o=this.nodes[e[r]];o.disconnect(t);do{if(!o.isAlone())break;o.orphan(),delete this.nodes[o.id],o=o.parent}while(o)}delete this.queries[t.id]},t.prototype.addBranch=function(t,e){for(var n=this.addNode(nt,null),r=0,i=t.length;r<i;r++)n=this.addNode(t[r],n);n.connect(e)},t.prototype.scan=function(t,e,n,r){if(e!==n)for(var i=t.edges,o=0,s=i.length;o<s;o++){var a=i[o];if(a instanceof et&&r.indexOf(a)<0)r.push(a);else if(a instanceof tt){var h=null==e?e:e[a.key],u=null==n?n:n[a.key];this.scan(a,h,u,r)}}return r},t}(),it={maxHistory:0,parent:null,batch:!1,debug:!1},ot=function(t){function e(n,r,i){I(this,e);var o=q(this,t.call(this)),s=a(it,o.constructor.defaults,n||{});return o.parent=s.parent,o.initial=o.parent?o.parent.initial:o.getInitialState(),o.state=o.parent?o.parent.state:o.initial,o.history=o.parent?o.parent.history:new W(s),o.snapshots={},o.domains=new Z(o),o.effects=new $(o),o.changes=new rt(o.state),o.history.on("append",o.createSnapshot,o),o.history.on("update",o.updateSnapshot,o),o.history.on("remove",o.removeSnapshot,o),o.history.on("reconcile",o.dispatchEffect,o),o.history.on("release",o.release,o),o.setup(s),r&&o.reset(r,i),s.debug&&O(o),o}return D(e,t),e.prototype.setup=function(t){},e.prototype.teardown=function(){},e.prototype.getInitialState=function(){return null==this.initial?{}:this.initial},e.prototype.recall=function(t){return t&&t.id in this.snapshots?this.snapshots[t.id]:this.initial},e.prototype.createSnapshot=function(t){this.snapshots[t.id]=this.recall(t.parent)},e.prototype.updateSnapshot=function(t){var e=this.recall(t.parent);this.parent&&(e=a(e,this.parent.recall(t))),t.disabled||(e=this.domains.dispatch(e,t)),this.state=this.snapshots[t.id]=e},e.prototype.removeSnapshot=function(t){delete this.snapshots[t.id]},e.prototype.dispatchEffect=function(t){this.effects.dispatch(t)},e.prototype.release=function(){this.changes.update(this.state)},e.prototype.on=function(t,e,n){var r=t.split(":",2),i=r[0],o=r[1];switch(i){case"change":this.changes.on(o||"",e,n);break;default:L.prototype.on.apply(this,arguments)}return this},e.prototype.off=function(t,e,n){var r=t.split(":",2),i=r[0],o=r[1];switch(i){case"change":this.changes.off(o||"",e,n);break;default:L.prototype.off.apply(this,arguments)}return this},e.prototype.append=function(t,e){return this.history.append(t,e)},e.prototype.push=function(t){for(var e=this.append(t),n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return x(e,t,r,this),e},e.prototype.prepare=function(t){for(var e=this,n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return function(){for(var n=arguments.length,i=Array(n),o=0;o<n;o++)i[o]=arguments[o];return e.push.apply(e,[t].concat(r,i))}},e.prototype.addDomain=function(t,e,n){var r=this.domains.add(t,e,n),i=r.getInitialState?r.getInitialState():null;return this.initial=u(this.initial,t,i),this.push(K,r),r},e.prototype.addEffect=function(t,e){return this.effects.add(t,e)},e.prototype.reset=function(t,e){return this.push(B,t,e)},e.prototype.patch=function(t,e){return this.push(U,t,e)},e.prototype.register=function(){return{}},e.prototype.deserialize=function(t){var e=t;return this.parent?e=this.parent.deserialize(t):"string"==typeof e&&(e=JSON.parse(e)),this.domains.deserialize(e)},e.prototype.serialize=function(){var t=this.parent?this.parent.serialize():{};return this.domains.serialize(this.state,t)},e.prototype.toJSON=function(){return this.serialize()},e.prototype.checkout=function(t){return this.history.checkout(t),this},e.prototype.fork=function(){return new e({parent:this})},e.prototype.shutdown=function(){this.teardown(),this._emit("teardown",this),this.history._removeScope(this),this.removeAllListeners()},e.prototype.parallel=function(t){return this.append("GROUP").link(t)},e}(L);exports.default=ot,exports.Microcosm=ot,exports.Action=M,exports.History=W,exports.Emitter=L,exports.tag=m,exports.get=h,exports.set=u,exports.update=g,exports.merge=a,exports.getRegistration=_; |
{ | ||
"name": "microcosm", | ||
"version": "12.9.0-beta4", | ||
"version": "12.9.0", | ||
"description": "Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.", | ||
@@ -5,0 +5,0 @@ "main": "microcosm.js", |
{ | ||
"name": "microcosm", | ||
"version": "12.9.0-beta4", | ||
"version": "12.9.0", | ||
"description": "Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.", | ||
@@ -5,0 +5,0 @@ "main": "microcosm.js", |
@@ -10,3 +10,15 @@ 'use strict'; | ||
var $Symbol = isFunction(Symbol) ? Symbol : {}; | ||
var toStringTag = get$1($Symbol, 'toStringTag', '@@toStringTag'); | ||
var iteratorTag = get$1($Symbol, 'iterator', '@@iterator'); | ||
/** | ||
* Merge on object into the next, but only assign keys that are | ||
* defined in the base. | ||
*/ | ||
/** | ||
* Shallow copy an object | ||
@@ -59,4 +71,6 @@ */ | ||
*/ | ||
function isFunction(target) { | ||
return !!target && typeof target === 'function'; | ||
} | ||
function isBlank(value) { | ||
@@ -71,4 +85,2 @@ return value === '' || value === null || value === undefined; | ||
/* istanbul ignore next */ | ||
var $Symbol = typeof Symbol === 'function' ? Symbol : {}; | ||
var toStringTagSymbol = get$1($Symbol, 'toStringTag', '@@toStringTag'); | ||
@@ -88,3 +100,8 @@ | ||
/** | ||
* A couple of methods use identity functions. This avoids duplication. | ||
*/ | ||
/** | ||
* @fileoverview A key path is a list of property names that describe | ||
@@ -91,0 +108,0 @@ * a pathway through a nested javascript object. For example, |
@@ -204,2 +204,10 @@ 'use strict'; | ||
function renderMediator() { | ||
return React.createElement(PresenterMediator, { | ||
presenter: this, | ||
parentState: this.state, | ||
parentProps: this.props | ||
}); | ||
} | ||
/* istanbul ignore next */ | ||
@@ -216,5 +224,4 @@ var identity = function identity() {}; | ||
if (_this.render !== Presenter.prototype.render) { | ||
if (_this.render) { | ||
_this.defaultRender = _this.render; | ||
_this.render = Presenter.prototype.render; | ||
} else { | ||
@@ -224,2 +231,8 @@ _this.defaultRender = passChildren; | ||
// We need to wrap the children of this presenter in a | ||
// PresenterMediator component. This ensures that we can pass along | ||
// context in browsers that do not support static inheritence (IE10) | ||
// and allow overriding of lifecycle methods | ||
_this.render = renderMediator; | ||
// Autobind send so that context is maintained when passing send to children | ||
@@ -360,10 +373,2 @@ _this.send = _this.send.bind(_this); | ||
Presenter.prototype.render = function render() { | ||
return React.createElement(PresenterMediator, { | ||
presenter: this, | ||
parentState: this.state, | ||
parentProps: this.props | ||
}); | ||
}; | ||
return Presenter; | ||
@@ -370,0 +375,0 @@ }(React.PureComponent); |
@@ -60,2 +60,8 @@ 'use strict'; | ||
var $Symbol = isFunction(Symbol) ? Symbol : {}; | ||
var toStringTag = get($Symbol, 'toStringTag', '@@toStringTag'); | ||
var iteratorTag = get($Symbol, 'iterator', '@@iterator'); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
@@ -146,4 +152,2 @@ return typeof obj; | ||
*/ | ||
var uidStepper = 0; | ||
@@ -155,2 +159,18 @@ function uid(prefix) { | ||
/** | ||
* Merge on object into the next, but only assign keys that are | ||
* defined in the base. | ||
*/ | ||
function mergeSame(target, head) { | ||
var next = {}; | ||
for (var key in head) { | ||
if (key in target) { | ||
next[key] = head[key]; | ||
} | ||
} | ||
return next; | ||
} | ||
/** | ||
* Shallow copy an object | ||
@@ -301,5 +321,3 @@ */ | ||
/* istanbul ignore next */ | ||
var $Symbol = typeof Symbol === 'function' ? Symbol : {}; | ||
var toStringTagSymbol = get($Symbol, 'toStringTag', '@@toStringTag'); | ||
function toStringTag(value) { | ||
function getStringTag(value) { | ||
if (!value) { | ||
@@ -309,3 +327,3 @@ return ''; | ||
return value[toStringTagSymbol] || ''; | ||
return value[toStringTag] || ''; | ||
} | ||
@@ -318,3 +336,3 @@ | ||
function isGeneratorFn(value) { | ||
return toStringTag(value) === 'GeneratorFunction'; | ||
return getStringTag(value) === 'GeneratorFunction'; | ||
} | ||
@@ -347,2 +365,6 @@ | ||
/** | ||
* A couple of methods use identity functions. This avoids duplication. | ||
*/ | ||
/** | ||
* @fileoverview Emitter is an abstract class used by a few other | ||
@@ -636,6 +658,6 @@ * classes to communicate via events | ||
var onResolve = function onResolve() { | ||
outstanding -= 1; | ||
if (outstanding <= 0) { | ||
if (outstanding <= 1) { | ||
_this2.resolve(); | ||
} else { | ||
outstanding -= 1; | ||
} | ||
@@ -650,2 +672,4 @@ }; | ||
onResolve(); | ||
return this; | ||
@@ -788,2 +812,6 @@ }; | ||
Action.prototype.toString = function toString() { | ||
return this.command.toString(); | ||
}; | ||
Action.prototype.toJSON = function toJSON() { | ||
@@ -887,8 +915,5 @@ return { | ||
} | ||
// Strip out keys not managed by this repo. This prevents children from | ||
// accidentally having their keys reset by parents. | ||
var sanitary = repo.domains.sanitize(payload); | ||
action.resolve(sanitary); | ||
action.resolve(mergeSame(repo.state, payload)); | ||
}; | ||
@@ -1030,14 +1055,44 @@ } | ||
*/ | ||
// $FlowFixMe | ||
History.prototype[iteratorTag] = function () { | ||
var _this2 = this; | ||
var cursor = this.root; | ||
var iterator = { | ||
next: function next() { | ||
var next = cursor; | ||
if (next == null) { | ||
return { done: true }; | ||
} | ||
cursor = next == _this2.head ? null : cursor.next; | ||
// Ignore certain lifecycle actions that are only for | ||
// internal purposes | ||
if (next && (next.command === BIRTH || next.command === START || next.command === ADD_DOMAIN)) { | ||
return iterator.next(); | ||
} | ||
return { value: next, done: false }; | ||
} | ||
}; | ||
return iterator; | ||
}; | ||
History.prototype.map = function map(fn, scope) { | ||
// $FlowFixMe | ||
var iterator = this[iteratorTag](); | ||
var next = iterator.next(); | ||
var items = []; | ||
var cursor = this.root; | ||
while (cursor) { | ||
items.push(fn.call(scope, cursor)); | ||
while (!next.done) { | ||
items.push(fn.call(scope, next.value, items.length)); | ||
next = iterator.next(); | ||
} | ||
if (cursor == this.head) break; | ||
cursor = cursor.next; | ||
} | ||
return items; | ||
@@ -1053,3 +1108,3 @@ }; | ||
History.prototype.wait = function wait() { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -1061,5 +1116,5 @@ var group = new Action('GROUP'); | ||
return group.then(function () { | ||
if (_this2.releasing) { | ||
if (_this3.releasing) { | ||
return new Promise(function (resolve) { | ||
_this2.once('release', resolve); | ||
_this3.once('release', resolve); | ||
}); | ||
@@ -1227,2 +1282,3 @@ } | ||
* signal that the action should be removed. | ||
* @private | ||
*/ | ||
@@ -1316,2 +1372,6 @@ | ||
History.prototype.toString = function toString() { | ||
return this.toArray().join(', '); | ||
}; | ||
/** | ||
@@ -1334,70 +1394,2 @@ * Serialize history into JSON data | ||
var Archive = function () { | ||
function Archive() { | ||
classCallCheck(this, Archive); | ||
this.pool = {}; | ||
} | ||
/** | ||
* Create an initial snapshot for an action by setting it to that of its | ||
* parent. | ||
*/ | ||
Archive.prototype.create = function create(action) { | ||
this.set(action, this.get(action.parent)); | ||
}; | ||
/** | ||
* Access a prior snapshot for a given action | ||
*/ | ||
Archive.prototype.get = function get(action, fallback) { | ||
console.assert(action, 'Unable to get ' + (typeof action === 'undefined' ? 'undefined' : _typeof(action)) + ' action'); | ||
if (action && this.has(action)) { | ||
return this.pool[action.id]; | ||
} | ||
return fallback == null ? {} : fallback; | ||
}; | ||
/** | ||
* Does a snapshot exist for an action? | ||
*/ | ||
Archive.prototype.has = function has(action) { | ||
return typeof this.pool[action.id] !== 'undefined'; | ||
}; | ||
/** | ||
* Assign a new snapshot for an action | ||
*/ | ||
Archive.prototype.set = function set(action, snapshot) { | ||
this.pool[action.id] = snapshot; | ||
}; | ||
/** | ||
* Remove a snapshot for an action. | ||
*/ | ||
Archive.prototype.remove = function remove(action) { | ||
console.assert(action, 'Unable to remove ' + (typeof action === 'undefined' ? 'undefined' : _typeof(action)) + ' action.'); | ||
delete this.pool[action.id]; | ||
}; | ||
return Archive; | ||
}(); /** | ||
* @fileoverview Keeps track of prior action states according to an | ||
* action's id | ||
* | ||
*/ | ||
/** | ||
@@ -1424,3 +1416,3 @@ * @fileoverview Every Microcosm includes MetaDomain. It provides the | ||
MetaDomain.prototype.reset = function reset(oldState, newState) { | ||
var filtered = this.repo.domains.sanitize(newState); | ||
var filtered = mergeSame(oldState, newState); | ||
@@ -1436,3 +1428,3 @@ return merge(oldState, this.repo.getInitialState(), filtered); | ||
MetaDomain.prototype.patch = function patch(oldState, newState) { | ||
var filtered = this.repo.domains.sanitize(newState); | ||
var filtered = mergeSame(oldState, newState); | ||
@@ -1463,10 +1455,2 @@ return merge(oldState, filtered); | ||
var Registration = function Registration(key, domain, handler) { | ||
classCallCheck(this, Registration); | ||
this.key = key; | ||
this.domain = domain; | ||
this.handler = handler; | ||
}; | ||
var ALIASES = { | ||
@@ -1539,3 +1523,3 @@ inactive: 'inactive', | ||
return handler ? [new Registration([], this.repo, handler)] : []; | ||
return handler ? [{ key: [], source: this.repo, handler: handler }] : []; | ||
}; | ||
@@ -1560,3 +1544,3 @@ | ||
if (handler) { | ||
handlers.push(new Registration(key, domain, handler)); | ||
handlers.push({ key: key, source: domain, handler: handler }); | ||
} | ||
@@ -1599,46 +1583,2 @@ } | ||
DomainEngine.prototype.reduce = function reduce(fn, state, scope) { | ||
var next = state; | ||
// Important: start at 1 to avoid the meta domain | ||
for (var i = 1, len = this.domains.length; i < len; i++) { | ||
var _domains$i2 = this.domains[i], | ||
key = _domains$i2[0], | ||
domain = _domains$i2[1]; | ||
next = fn.call(scope, next, key, domain); | ||
} | ||
return next; | ||
}; | ||
DomainEngine.prototype.supportsKey = function supportsKey(key) { | ||
if (key in this.repo.state) { | ||
return true; | ||
} | ||
return this.domains.some(function (entry) { | ||
return getKeyString(entry[0]) === key; | ||
}); | ||
}; | ||
DomainEngine.prototype.sanitize = function sanitize(data) { | ||
var repo = this.repo; | ||
var parent = repo.parent; | ||
var next = {}; | ||
for (var key in data) { | ||
if (parent && parent.domains.supportsKey(key)) { | ||
continue; | ||
} | ||
if (this.supportsKey(key)) { | ||
next[key] = data[key]; | ||
} | ||
} | ||
return next; | ||
}; | ||
DomainEngine.prototype.dispatch = function dispatch(state, action) { | ||
@@ -1651,3 +1591,3 @@ var handlers = this.register(action); | ||
key = _handlers$i.key, | ||
domain = _handlers$i.domain, | ||
source = _handlers$i.source, | ||
handler = _handlers$i.handler; | ||
@@ -1657,3 +1597,3 @@ | ||
var last = get(result, key); | ||
var next = handler.call(domain, last, action.payload); | ||
var next = handler.call(source, last, action.payload); | ||
@@ -1667,19 +1607,33 @@ result = set(result, key, next); | ||
DomainEngine.prototype.deserialize = function deserialize(payload) { | ||
return this.reduce(function (memo, key, domain) { | ||
var next = payload; | ||
for (var i = 0; i < this.domains.length; i++) { | ||
var _domains$i2 = this.domains[i], | ||
key = _domains$i2[0], | ||
domain = _domains$i2[1]; | ||
if (domain.deserialize) { | ||
return set(memo, key, domain.deserialize(get(payload, key))); | ||
next = set(next, key, domain.deserialize(get(payload, key))); | ||
} | ||
} | ||
return memo; | ||
}, payload); | ||
return next; | ||
}; | ||
DomainEngine.prototype.serialize = function serialize(state, payload) { | ||
return this.reduce(function (memo, key, domain) { | ||
var next = payload; | ||
for (var i = 0; i < this.domains.length; i++) { | ||
var _domains$i3 = this.domains[i], | ||
key = _domains$i3[0], | ||
domain = _domains$i3[1]; | ||
if (domain.serialize) { | ||
return set(memo, key, domain.serialize(get(state, key))); | ||
next = set(next, key, domain.serialize(get(state, key))); | ||
} | ||
} | ||
return memo; | ||
}, payload); | ||
return next; | ||
}; | ||
@@ -1761,5 +1715,7 @@ | ||
Node.prototype.connect = function connect(node) { | ||
if (node !== this && this.edges.indexOf(node) < 0) { | ||
this.edges.push(node); | ||
} | ||
console.assert(this.edges.indexOf(node) <= 0, node.id + ' is already connected to ' + this.id); | ||
console.assert(node !== this, 'Unable to connect node ' + node.id + ' to self.'); | ||
this.edges.push(node); | ||
}; | ||
@@ -1874,3 +1830,3 @@ | ||
for (var i = 0, len = keyPaths.length; i < len; i++) { | ||
for (var i = keyPaths.length - 1; i >= 0; i--) { | ||
this.addBranch(keyPaths[i], query); | ||
@@ -1933,3 +1889,3 @@ } | ||
if (!this.nodes[id]) { | ||
if (this.nodes.hasOwnProperty(id) === false) { | ||
this.nodes[id] = new Node(id, key, parent); | ||
@@ -1951,3 +1907,3 @@ } | ||
if (!this.queries[id]) { | ||
if (this.queries.hasOwnProperty(id) === false) { | ||
this.queries[id] = new Query(id, dependencies); | ||
@@ -2038,2 +1994,4 @@ } | ||
*/ | ||
function processGenerator(action, body, repo) { | ||
@@ -2252,3 +2210,3 @@ action.open(); | ||
_this.archive = new Archive(); | ||
_this.snapshots = {}; | ||
_this.domains = new DomainEngine(_this); | ||
@@ -2326,4 +2284,8 @@ _this.effects = new EffectEngine(_this); | ||
Microcosm.prototype.recall = function recall(action, fallback) { | ||
return this.archive.get(action, fallback); | ||
Microcosm.prototype.recall = function recall(action) { | ||
if (action && action.id in this.snapshots) { | ||
return this.snapshots[action.id]; | ||
} | ||
return this.initial; | ||
}; | ||
@@ -2338,3 +2300,3 @@ | ||
Microcosm.prototype.createSnapshot = function createSnapshot(action) { | ||
this.archive.create(action); | ||
this.snapshots[action.id] = this.recall(action.parent); | ||
}; | ||
@@ -2348,3 +2310,3 @@ | ||
Microcosm.prototype.updateSnapshot = function updateSnapshot(action) { | ||
var next = this.recall(action.parent, this.initial); | ||
var next = this.recall(action.parent); | ||
@@ -2359,5 +2321,3 @@ if (this.parent) { | ||
this.archive.set(action, next); | ||
this.state = next; | ||
this.state = this.snapshots[action.id] = next; | ||
}; | ||
@@ -2371,3 +2331,3 @@ | ||
Microcosm.prototype.removeSnapshot = function removeSnapshot(action) { | ||
this.archive.remove(action); | ||
delete this.snapshots[action.id]; | ||
}; | ||
@@ -2494,6 +2454,5 @@ | ||
var domain = this.domains.add(key, config, options); | ||
var initial = domain.getInitialState ? domain.getInitialState() : null; | ||
if (domain.getInitialState) { | ||
this.initial = set(this.initial, key, domain.getInitialState()); | ||
} | ||
this.initial = set(this.initial, key, initial); | ||
@@ -2500,0 +2459,0 @@ this.push(ADD_DOMAIN, domain); |
{ | ||
"name": "microcosm", | ||
"version": "12.9.0-beta4", | ||
"version": "12.9.0", | ||
"description": "Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.", | ||
@@ -5,0 +5,0 @@ "main": "microcosm.js", |
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 not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
7
419199
5821