microcosm
Advanced tools
Comparing version 12.10.0-alpha.4 to 12.10.0
@@ -46,3 +46,7 @@ 'use strict'; | ||
return value == null ? fallback : value; | ||
if (value === undefined || value === null) { | ||
return arguments.length <= 2 ? value : fallback; | ||
} | ||
return value; | ||
} | ||
@@ -49,0 +53,0 @@ |
@@ -41,3 +41,7 @@ import Microcosm, { get, set } from '../microcosm.js'; | ||
return value == null ? fallback : value; | ||
if (value === undefined || value === null) { | ||
return arguments.length <= 2 ? value : fallback; | ||
} | ||
return value; | ||
} | ||
@@ -44,0 +48,0 @@ |
@@ -199,7 +199,11 @@ /** | ||
for (var i = 0, len = args.length; i < len; i++) { | ||
copy = copy || args[i]; | ||
if (isObject(args[i]) === false) { | ||
continue; | ||
} | ||
copy = copy || args[i] || {}; | ||
subject = subject || copy; | ||
var next = args[i]; | ||
for (var key in next) { | ||
@@ -235,3 +239,7 @@ if (copy[key] !== next[key]) { | ||
return value == null ? fallback : value; | ||
if (value === undefined || value === null) { | ||
return arguments.length <= 2 ? value : fallback; | ||
} | ||
return value; | ||
} | ||
@@ -1128,2 +1136,3 @@ | ||
var birth = new Action(BIRTH, 'resolve'); | ||
birth.adopt(action); | ||
@@ -1137,5 +1146,9 @@ | ||
action.on('change', this.reconcile, this); | ||
this._emit('append', action); | ||
action.on('change', this.reconcile, this); | ||
if (status && action.command !== START) { | ||
this.reconcile(action); | ||
} | ||
@@ -1272,5 +1285,7 @@ return action; | ||
root.prune(); | ||
if (root !== this.root) { | ||
this.root = root; | ||
root.prune(); | ||
} | ||
this.root = root; | ||
this.size = size; | ||
@@ -1303,3 +1318,3 @@ }; | ||
History.prototype.setLimit = function setLimit(limit) { | ||
this.limit = Math.max(0, limit); | ||
this.limit = Math.max(DEFAULTS$1.maxHistory, limit); | ||
}; | ||
@@ -1424,3 +1439,3 @@ | ||
var ALIASES = { | ||
var STATUSES = { | ||
inactive: 'inactive', | ||
@@ -1442,3 +1457,3 @@ open: 'open', | ||
var answer = null; | ||
var alias = ALIASES[status]; | ||
var alias = STATUSES[status]; | ||
@@ -1526,3 +1541,4 @@ var nest = pool[command]; | ||
DomainEngine.prototype.add = function add(key, config, options) { | ||
var domain = createOrClone(config, options, this.repo); | ||
var deepOptions = merge(this.repo.options, config.defaults, options); | ||
var domain = createOrClone(config, deepOptions, this.repo); | ||
var keyPath = castPath(key); | ||
@@ -1536,3 +1552,3 @@ | ||
if (domain.setup) { | ||
domain.setup(this.repo, options); | ||
domain.setup(this.repo, deepOptions); | ||
} | ||
@@ -1558,4 +1574,4 @@ | ||
var base = get(result, key); | ||
var head = get(snapshot.last, key); | ||
var base = get(result, key, null); | ||
var head = get(snapshot.last, key, null); | ||
@@ -1626,6 +1642,7 @@ if ( | ||
EffectEngine.prototype.add = function add(config, options) { | ||
var effect = createOrClone(config, options, this.repo); | ||
var deepOptions = merge(this.repo.options, config.defaults, options); | ||
var effect = createOrClone(config, deepOptions, this.repo); | ||
if (effect.setup) { | ||
effect.setup(this.repo, options); | ||
effect.setup(this.repo, deepOptions); | ||
} | ||
@@ -2166,5 +2183,5 @@ | ||
var options = merge(DEFAULTS, _this.constructor.defaults, preOptions || {}); | ||
_this.options = merge(DEFAULTS, _this.constructor.defaults, preOptions || {}); | ||
_this.parent = options.parent; | ||
_this.parent = _this.options.parent; | ||
@@ -2174,3 +2191,3 @@ _this.initial = _this.parent ? _this.parent.initial : _this.getInitialState(); | ||
_this.history = _this.parent ? _this.parent.history : new History(options); | ||
_this.history = _this.parent ? _this.parent.history : new History(_this.options); | ||
@@ -2186,3 +2203,3 @@ _this.snapshots = Object.create(_this.parent ? _this.parent.snapshots : null); | ||
// When an action is first created | ||
_this.history.on('append', _this.createSnapshot, _this);_this.history.on('update', _this.updateSnapshot, _this);_this.history.on('remove', _this.removeSnapshot, _this);_this.history.on('reconcile', _this.dispatchEffect, _this);_this.history.on('release', _this.release, _this);_this.setup(options | ||
_this.history.on('append', _this.createSnapshot, _this);_this.history.on('update', _this.updateSnapshot, _this);_this.history.on('remove', _this.removeSnapshot, _this);_this.history.on('reconcile', _this.dispatchEffect, _this);_this.history.on('release', _this.release, _this);_this.setup(_this.options | ||
@@ -2194,3 +2211,3 @@ // If given state, reset to that snapshot | ||
if (options.debug) { | ||
if (_this.options.debug) { | ||
installDevtools(_this); | ||
@@ -2197,0 +2214,0 @@ } |
@@ -203,7 +203,11 @@ 'use strict'; | ||
for (var i = 0, len = args.length; i < len; i++) { | ||
copy = copy || args[i]; | ||
if (isObject(args[i]) === false) { | ||
continue; | ||
} | ||
copy = copy || args[i] || {}; | ||
subject = subject || copy; | ||
var next = args[i]; | ||
for (var key in next) { | ||
@@ -239,3 +243,7 @@ if (copy[key] !== next[key]) { | ||
return value == null ? fallback : value; | ||
if (value === undefined || value === null) { | ||
return arguments.length <= 2 ? value : fallback; | ||
} | ||
return value; | ||
} | ||
@@ -1132,2 +1140,3 @@ | ||
var birth = new Action(BIRTH, 'resolve'); | ||
birth.adopt(action); | ||
@@ -1141,5 +1150,9 @@ | ||
action.on('change', this.reconcile, this); | ||
this._emit('append', action); | ||
action.on('change', this.reconcile, this); | ||
if (status && action.command !== START) { | ||
this.reconcile(action); | ||
} | ||
@@ -1276,5 +1289,7 @@ return action; | ||
root.prune(); | ||
if (root !== this.root) { | ||
this.root = root; | ||
root.prune(); | ||
} | ||
this.root = root; | ||
this.size = size; | ||
@@ -1307,3 +1322,3 @@ }; | ||
History.prototype.setLimit = function setLimit(limit) { | ||
this.limit = Math.max(0, limit); | ||
this.limit = Math.max(DEFAULTS$1.maxHistory, limit); | ||
}; | ||
@@ -1428,3 +1443,3 @@ | ||
var ALIASES = { | ||
var STATUSES = { | ||
inactive: 'inactive', | ||
@@ -1446,3 +1461,3 @@ open: 'open', | ||
var answer = null; | ||
var alias = ALIASES[status]; | ||
var alias = STATUSES[status]; | ||
@@ -1530,3 +1545,4 @@ var nest = pool[command]; | ||
DomainEngine.prototype.add = function add(key, config, options) { | ||
var domain = createOrClone(config, options, this.repo); | ||
var deepOptions = merge(this.repo.options, config.defaults, options); | ||
var domain = createOrClone(config, deepOptions, this.repo); | ||
var keyPath = castPath(key); | ||
@@ -1540,3 +1556,3 @@ | ||
if (domain.setup) { | ||
domain.setup(this.repo, options); | ||
domain.setup(this.repo, deepOptions); | ||
} | ||
@@ -1562,4 +1578,4 @@ | ||
var base = get(result, key); | ||
var head = get(snapshot.last, key); | ||
var base = get(result, key, null); | ||
var head = get(snapshot.last, key, null); | ||
@@ -1630,6 +1646,7 @@ if ( | ||
EffectEngine.prototype.add = function add(config, options) { | ||
var effect = createOrClone(config, options, this.repo); | ||
var deepOptions = merge(this.repo.options, config.defaults, options); | ||
var effect = createOrClone(config, deepOptions, this.repo); | ||
if (effect.setup) { | ||
effect.setup(this.repo, options); | ||
effect.setup(this.repo, deepOptions); | ||
} | ||
@@ -2170,5 +2187,5 @@ | ||
var options = merge(DEFAULTS, _this.constructor.defaults, preOptions || {}); | ||
_this.options = merge(DEFAULTS, _this.constructor.defaults, preOptions || {}); | ||
_this.parent = options.parent; | ||
_this.parent = _this.options.parent; | ||
@@ -2178,3 +2195,3 @@ _this.initial = _this.parent ? _this.parent.initial : _this.getInitialState(); | ||
_this.history = _this.parent ? _this.parent.history : new History(options); | ||
_this.history = _this.parent ? _this.parent.history : new History(_this.options); | ||
@@ -2190,3 +2207,3 @@ _this.snapshots = Object.create(_this.parent ? _this.parent.snapshots : null); | ||
// When an action is first created | ||
_this.history.on('append', _this.createSnapshot, _this);_this.history.on('update', _this.updateSnapshot, _this);_this.history.on('remove', _this.removeSnapshot, _this);_this.history.on('reconcile', _this.dispatchEffect, _this);_this.history.on('release', _this.release, _this);_this.setup(options | ||
_this.history.on('append', _this.createSnapshot, _this);_this.history.on('update', _this.updateSnapshot, _this);_this.history.on('remove', _this.removeSnapshot, _this);_this.history.on('reconcile', _this.dispatchEffect, _this);_this.history.on('release', _this.release, _this);_this.setup(_this.options | ||
@@ -2198,3 +2215,3 @@ // If given state, reset to that snapshot | ||
if (options.debug) { | ||
if (_this.options.debug) { | ||
installDevtools(_this); | ||
@@ -2201,0 +2218,0 @@ } |
@@ -1,2 +0,2 @@ | ||
"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(s):[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||{})}var l=require("../microcosm.js"),a=r(l),f=n(Symbol)?Symbol:{},p=t(f,"toStringTag","@@toStringTag"),c=t(f,"iterator","@@iterator"),s=".",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,c=null,s=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,c);o!==c&&(c=o,s=e.reduce(function(r,t){return t.call(a,r,p)},c))}return t.reduce(function(r,t){return t.call(a,r,p)},s)};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}}};module.exports=d; | ||
"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 void 0===u||null===u?arguments.length<=2?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(s):[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||{})}var l=require("../microcosm.js"),a=r(l),f=n(Symbol)?Symbol:{},p=t(f,"toStringTag","@@toStringTag"),c=t(f,"iterator","@@iterator"),s=".",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,c=null,s=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,c);o!==c&&(c=o,s=e.reduce(function(r,t){return t.call(a,r,p)},c))}return t.reduce(function(r,t){return t.call(a,r,p)},s)};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}}};module.exports=d; | ||
//# sourceMappingURL=indexing.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return Array.isArray(t)?t:f(t)?[]:"string"==typeof t?t.trim().split(k):[t]}function e(e){return"string"==typeof e?(""+e).split(A).map(t):e.every(Array.isArray)?e:e.map(t)}function n(t){return t.join(k)}function r(t){return t.map(n).join(A)}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 u=r[o];for(var p in u)t[p]!==u[p]&&(t===e&&(t=s(e)),t[p]=u[p])}return t||{}}function u(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),o=i.length;if(o<=0)return r;if(u(e,i)===r)return e;for(var a=s(e),p=a,h=0;h<o;h++){var c=i[h],l=r;h<o-1&&(l=c in p?s(p[c]):{}),p[c]=l,p=p[c]}return a}function h(t){return(c(t)||l(t))&&l(t.then)}function c(t){return!(!t||"object"!==(void 0===t?"undefined":I(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)?p(e,o,r):p(e,o,r(u(e,o,i)))}function m(t,e){if("string"==typeof t)return m(function(t){return t},t);if(!0===t.__tagged)return t;C+=1;var n=e||(t.name||T)+"."+C,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 x(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 h(i)?(t.open.apply(t,n),i.then(function(e){return setTimeout(function(){return t.resolve(e)},0)},function(e){return setTimeout(function(){return t.reject(e)},0)}),t):y(i)?x(t,i,r):l(i)?(i(t,r),t):t.resolve(i)}function O(t){var e=("undefined"==typeof global?window:global).__MICROCOSM_DEVTOOLS_GLOBAL_HOOK__;e&&(e.emit("init",t),t.history.setLimit(1/0))}Object.defineProperty(exports,"__esModule",{value:!0});var k=".",A=",",z=l(Symbol)?Symbol:{},j=u(z,"toStringTag","@@toStringTag"),E=u(z,"iterator","@@iterator"),I="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},P=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(){P(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}(),C=0,T="_action",N={inactive:!1,open:!1,update:!1,resolve:!0,reject:!0,cancel:!0},M=function(t){function e(n,r){P(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="undefined"!=typeof requestIdleCallback?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){P(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&&(e.command!==F&&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(){P(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){P(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],u=s[1];if(u.register){var p=_(u.register(),n,r);p&&e.push({key:a,source:u,handler:p})}}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,n){for(var r=this.register(t),i=e,o=0,s=r.length;o<s;o++){var a=r[o],h=a.key,c=a.source,l=a.handler,f=u(i,h);i=f!==u(n.last,h)||t.payload!==n.payload||t.status!==n.status?p(i,h,l.call(c,f,t.payload)):p(i,h,u(n.next,h))}return i},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=p(e,i,o.deserialize(u(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=p(n,o,s.serialize(u(t,o))))}return n},e}(),$=function(){function t(e){P(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){P(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){P(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]=u(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){P(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 u=null==e?e:e[a.key],p=null==n?n:n[a.key];this.scan(a,u,p,r)}}return r},t}(),it={maxHistory:0,parent:null,batch:!1,debug:!1},ot=function(t){function e(n,r,i){P(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=Object.create(o.parent?o.parent.snapshots:null),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].next:this.getInitialState()},e.prototype.rebase=function(t){var e=this.recall(t.parent);return this.parent&&(e=a(e,this.parent.recall(t))),e},e.prototype.createSnapshot=function(t){var e={last:this.state,next:this.state,status:"inactive",payload:void 0};return this.snapshots[t.id]=e,e},e.prototype.updateSnapshot=function(t){var e=this.snapshots[t.id],n=this.rebase(t);t.disabled?e.next=n:e.next=this.domains.dispatch(t,n,e),this.snapshots[t.id]=a(e,{last:n,status:t.status,payload:t.payload}),this.state=e.next},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 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),i=r.getInitialState?r.getInitialState():null;return this.initial=p(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=u,exports.set=p,exports.update=g,exports.merge=a,exports.getRegistration=_; | ||
"use strict";function t(t){return Array.isArray(t)?t:f(t)?[]:"string"==typeof t?t.trim().split(k):[t]}function e(e){return"string"==typeof e?(""+e).split(A).map(t):e.every(Array.isArray)?e:e.map(t)}function n(t){return t.join(k)}function r(t){return t.map(n).join(A)}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++)if(!1!==c(r[o])){t=t||r[o]||{},e=e||t;var p=r[o];for(var u in p)t[u]!==p[u]&&(t===e&&(t=s(e)),t[u]=p[u])}return t||{}}function p(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 void 0===o||null===o?arguments.length<=2?o:r:o}function u(e,n,r){var i=t(n),o=i.length;if(o<=0)return r;if(p(e,i)===r)return e;for(var a=s(e),u=a,h=0;h<o;h++){var c=i[h],l=r;h<o-1&&(l=c in u?s(u[c]):{}),u[c]=l,u=u[c]}return a}function h(t){return(c(t)||l(t))&&l(t.then)}function c(t){return!(!t||"object"!==(void 0===t?"undefined":I(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(p(e,o,i)))}function m(t,e){if("string"==typeof t)return m(function(t){return t},t);if(!0===t.__tagged)return t;C+=1;var n=e||(t.name||T)+"."+C,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 x(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 h(i)?(t.open.apply(t,n),i.then(function(e){return setTimeout(function(){return t.resolve(e)},0)},function(e){return setTimeout(function(){return t.reject(e)},0)}),t):y(i)?x(t,i,r):l(i)?(i(t,r),t):t.resolve(i)}function O(t){var e=("undefined"==typeof global?window:global).__MICROCOSM_DEVTOOLS_GLOBAL_HOOK__;e&&(e.emit("init",t),t.history.setLimit(1/0))}Object.defineProperty(exports,"__esModule",{value:!0});var k=".",A=",",z=l(Symbol)?Symbol:{},j=p(z,"toStringTag","@@toStringTag"),E=p(z,"iterator","@@iterator"),I="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},P=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(){P(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}(),C=0,T="_action",N={inactive:!1,open:!1,update:!1,resolve:!0,reject:!0,cancel:!0},M=function(t){function e(n,r){P(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="undefined"!=typeof requestIdleCallback?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){P(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,n.on("change",this.reconcile,this),this._emit("append",n),e&&n.command!==F&&this.reconcile(n),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&&(e.command!==F&&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!==this.root&&(this.root=e,e.prune()),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(V.maxHistory,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(){P(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){P(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],p=s[1];if(p.register){var u=_(p.register(),n,r);u&&e.push({key:a,source:p,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=a(this.repo.options,n.defaults,r),o=v(n,i,this.repo),s=t(e);return this.domains.push([s,o]),this.registry={},o.setup&&o.setup(this.repo,i),o.teardown&&this.repo.on("teardown",o.teardown,o),o},e.prototype.dispatch=function(t,e,n){for(var r=this.register(t),i=e,o=0,s=r.length;o<s;o++){var a=r[o],h=a.key,c=a.source,l=a.handler,f=p(i,h,null);i=f!==p(n.last,h,null)||t.payload!==n.payload||t.status!==n.status?u(i,h,l.call(c,f,t.payload)):u(i,h,p(n.next,h))}return i},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(p(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(p(t,o))))}return n},e}(),$=function(){function t(e){P(this,t),this.repo=e,this.effects=[]}return t.prototype.add=function(t,e){var n=a(this.repo.options,t.defaults,e),r=v(t,n,this.repo);return r.setup&&r.setup(this.repo,n),r.teardown&&this.repo.on("teardown",r.teardown,r),this.effects.push(r),r},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){P(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){P(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]=p(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){P(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 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){P(this,e);var o=q(this,t.call(this));return o.options=a(it,o.constructor.defaults,n||{}),o.parent=o.options.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(o.options),o.snapshots=Object.create(o.parent?o.parent.snapshots:null),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(o.options),r&&o.reset(r,i),o.options.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].next:this.getInitialState()},e.prototype.rebase=function(t){var e=this.recall(t.parent);return this.parent&&(e=a(e,this.parent.recall(t))),e},e.prototype.createSnapshot=function(t){var e={last:this.state,next:this.state,status:"inactive",payload:void 0};return this.snapshots[t.id]=e,e},e.prototype.updateSnapshot=function(t){var e=this.snapshots[t.id],n=this.rebase(t);t.disabled?e.next=n:e.next=this.domains.dispatch(t,n,e),this.snapshots[t.id]=a(e,{last:n,status:t.status,payload:t.payload}),this.state=e.next},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 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),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=p,exports.set=u,exports.update=g,exports.merge=a,exports.getRegistration=_; | ||
//# sourceMappingURL=microcosm.js.map |
{ | ||
"name": "microcosm", | ||
"version": "12.10.0-alpha.4", | ||
"version": "12.10.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", |
@@ -46,3 +46,7 @@ 'use strict'; | ||
return value == null ? fallback : value; | ||
if (value === undefined || value === null) { | ||
return arguments.length <= 2 ? value : fallback; | ||
} | ||
return value; | ||
} | ||
@@ -49,0 +53,0 @@ |
@@ -203,7 +203,11 @@ 'use strict'; | ||
for (var i = 0, len = args.length; i < len; i++) { | ||
copy = copy || args[i]; | ||
if (isObject(args[i]) === false) { | ||
continue; | ||
} | ||
copy = copy || args[i] || {}; | ||
subject = subject || copy; | ||
var next = args[i]; | ||
for (var key in next) { | ||
@@ -239,3 +243,7 @@ if (copy[key] !== next[key]) { | ||
return value == null ? fallback : value; | ||
if (value === undefined || value === null) { | ||
return arguments.length <= 2 ? value : fallback; | ||
} | ||
return value; | ||
} | ||
@@ -1140,2 +1148,3 @@ | ||
var birth = new Action(BIRTH, 'resolve'); | ||
birth.adopt(action); | ||
@@ -1149,5 +1158,9 @@ | ||
action.on('change', this.reconcile, this); | ||
this._emit('append', action); | ||
action.on('change', this.reconcile, this); | ||
if (status && action.command !== START) { | ||
this.reconcile(action); | ||
} | ||
@@ -1286,5 +1299,7 @@ return action; | ||
root.prune(); | ||
if (root !== this.root) { | ||
this.root = root; | ||
root.prune(); | ||
} | ||
this.root = root; | ||
this.size = size; | ||
@@ -1317,3 +1332,3 @@ }; | ||
History.prototype.setLimit = function setLimit(limit) { | ||
this.limit = Math.max(0, limit); | ||
this.limit = Math.max(DEFAULTS$1.maxHistory, limit); | ||
}; | ||
@@ -1438,3 +1453,3 @@ | ||
var ALIASES = { | ||
var STATUSES = { | ||
inactive: 'inactive', | ||
@@ -1456,3 +1471,3 @@ open: 'open', | ||
var answer = null; | ||
var alias = ALIASES[status]; | ||
var alias = STATUSES[status]; | ||
@@ -1546,3 +1561,4 @@ console.assert(alias, 'Invalid action status ' + status); | ||
DomainEngine.prototype.add = function add(key, config, options) { | ||
var domain = createOrClone(config, options, this.repo); | ||
var deepOptions = merge(this.repo.options, config.defaults, options); | ||
var domain = createOrClone(config, deepOptions, this.repo); | ||
var keyPath = castPath(key); | ||
@@ -1556,3 +1572,3 @@ | ||
if (domain.setup) { | ||
domain.setup(this.repo, options); | ||
domain.setup(this.repo, deepOptions); | ||
} | ||
@@ -1578,4 +1594,4 @@ | ||
var base = get(result, key); | ||
var head = get(snapshot.last, key); | ||
var base = get(result, key, null); | ||
var head = get(snapshot.last, key, null); | ||
@@ -1646,6 +1662,7 @@ if ( | ||
EffectEngine.prototype.add = function add(config, options) { | ||
var effect = createOrClone(config, options, this.repo); | ||
var deepOptions = merge(this.repo.options, config.defaults, options); | ||
var effect = createOrClone(config, deepOptions, this.repo); | ||
if (effect.setup) { | ||
effect.setup(this.repo, options); | ||
effect.setup(this.repo, deepOptions); | ||
} | ||
@@ -2191,5 +2208,5 @@ | ||
var options = merge(DEFAULTS, _this.constructor.defaults, preOptions || {}); | ||
_this.options = merge(DEFAULTS, _this.constructor.defaults, preOptions || {}); | ||
_this.parent = options.parent; | ||
_this.parent = _this.options.parent; | ||
@@ -2199,3 +2216,3 @@ _this.initial = _this.parent ? _this.parent.initial : _this.getInitialState(); | ||
_this.history = _this.parent ? _this.parent.history : new History(options); | ||
_this.history = _this.parent ? _this.parent.history : new History(_this.options); | ||
@@ -2211,3 +2228,3 @@ _this.snapshots = Object.create(_this.parent ? _this.parent.snapshots : null); | ||
// When an action is first created | ||
_this.history.on('append', _this.createSnapshot, _this);_this.history.on('update', _this.updateSnapshot, _this);_this.history.on('remove', _this.removeSnapshot, _this);_this.history.on('reconcile', _this.dispatchEffect, _this);_this.history.on('release', _this.release, _this);_this.setup(options | ||
_this.history.on('append', _this.createSnapshot, _this);_this.history.on('update', _this.updateSnapshot, _this);_this.history.on('remove', _this.removeSnapshot, _this);_this.history.on('reconcile', _this.dispatchEffect, _this);_this.history.on('release', _this.release, _this);_this.setup(_this.options | ||
@@ -2219,3 +2236,3 @@ // If given state, reset to that snapshot | ||
if (options.debug) { | ||
if (_this.options.debug) { | ||
installDevtools(_this); | ||
@@ -2222,0 +2239,0 @@ } |
{ | ||
"name": "microcosm", | ||
"version": "12.10.0-alpha.4", | ||
"version": "12.10.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", |
@@ -47,3 +47,7 @@ (function (global, factory) { | ||
return value == null ? fallback : value; | ||
if (value === undefined || value === null) { | ||
return arguments.length <= 2 ? value : fallback; | ||
} | ||
return value; | ||
} | ||
@@ -50,0 +54,0 @@ |
@@ -205,7 +205,11 @@ (function (global, factory) { | ||
for (var i = 0, len = args.length; i < len; i++) { | ||
copy = copy || args[i]; | ||
if (isObject(args[i]) === false) { | ||
continue; | ||
} | ||
copy = copy || args[i] || {}; | ||
subject = subject || copy; | ||
var next = args[i]; | ||
for (var key in next) { | ||
@@ -241,3 +245,7 @@ if (copy[key] !== next[key]) { | ||
return value == null ? fallback : value; | ||
if (value === undefined || value === null) { | ||
return arguments.length <= 2 ? value : fallback; | ||
} | ||
return value; | ||
} | ||
@@ -1134,2 +1142,3 @@ | ||
var birth = new Action(BIRTH, 'resolve'); | ||
birth.adopt(action); | ||
@@ -1143,5 +1152,9 @@ | ||
action.on('change', this.reconcile, this); | ||
this._emit('append', action); | ||
action.on('change', this.reconcile, this); | ||
if (status && action.command !== START) { | ||
this.reconcile(action); | ||
} | ||
@@ -1278,5 +1291,7 @@ return action; | ||
root.prune(); | ||
if (root !== this.root) { | ||
this.root = root; | ||
root.prune(); | ||
} | ||
this.root = root; | ||
this.size = size; | ||
@@ -1309,3 +1324,3 @@ }; | ||
History.prototype.setLimit = function setLimit(limit) { | ||
this.limit = Math.max(0, limit); | ||
this.limit = Math.max(DEFAULTS$1.maxHistory, limit); | ||
}; | ||
@@ -1430,3 +1445,3 @@ | ||
var ALIASES = { | ||
var STATUSES = { | ||
inactive: 'inactive', | ||
@@ -1448,3 +1463,3 @@ open: 'open', | ||
var answer = null; | ||
var alias = ALIASES[status]; | ||
var alias = STATUSES[status]; | ||
@@ -1532,3 +1547,4 @@ var nest = pool[command]; | ||
DomainEngine.prototype.add = function add(key, config, options) { | ||
var domain = createOrClone(config, options, this.repo); | ||
var deepOptions = merge(this.repo.options, config.defaults, options); | ||
var domain = createOrClone(config, deepOptions, this.repo); | ||
var keyPath = castPath(key); | ||
@@ -1542,3 +1558,3 @@ | ||
if (domain.setup) { | ||
domain.setup(this.repo, options); | ||
domain.setup(this.repo, deepOptions); | ||
} | ||
@@ -1564,4 +1580,4 @@ | ||
var base = get(result, key); | ||
var head = get(snapshot.last, key); | ||
var base = get(result, key, null); | ||
var head = get(snapshot.last, key, null); | ||
@@ -1632,6 +1648,7 @@ if ( | ||
EffectEngine.prototype.add = function add(config, options) { | ||
var effect = createOrClone(config, options, this.repo); | ||
var deepOptions = merge(this.repo.options, config.defaults, options); | ||
var effect = createOrClone(config, deepOptions, this.repo); | ||
if (effect.setup) { | ||
effect.setup(this.repo, options); | ||
effect.setup(this.repo, deepOptions); | ||
} | ||
@@ -2172,5 +2189,5 @@ | ||
var options = merge(DEFAULTS, _this.constructor.defaults, preOptions || {}); | ||
_this.options = merge(DEFAULTS, _this.constructor.defaults, preOptions || {}); | ||
_this.parent = options.parent; | ||
_this.parent = _this.options.parent; | ||
@@ -2180,3 +2197,3 @@ _this.initial = _this.parent ? _this.parent.initial : _this.getInitialState(); | ||
_this.history = _this.parent ? _this.parent.history : new History(options); | ||
_this.history = _this.parent ? _this.parent.history : new History(_this.options); | ||
@@ -2192,3 +2209,3 @@ _this.snapshots = Object.create(_this.parent ? _this.parent.snapshots : null); | ||
// When an action is first created | ||
_this.history.on('append', _this.createSnapshot, _this);_this.history.on('update', _this.updateSnapshot, _this);_this.history.on('remove', _this.removeSnapshot, _this);_this.history.on('reconcile', _this.dispatchEffect, _this);_this.history.on('release', _this.release, _this);_this.setup(options | ||
_this.history.on('append', _this.createSnapshot, _this);_this.history.on('update', _this.updateSnapshot, _this);_this.history.on('remove', _this.removeSnapshot, _this);_this.history.on('reconcile', _this.dispatchEffect, _this);_this.history.on('release', _this.release, _this);_this.setup(_this.options | ||
@@ -2200,3 +2217,3 @@ // If given state, reset to that snapshot | ||
if (options.debug) { | ||
if (_this.options.debug) { | ||
installDevtools(_this); | ||
@@ -2203,0 +2220,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 not supported yet
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
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
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1067603
84
11320