microcosm
Advanced tools
Comparing version 12.9.0-beta3 to 12.9.0-beta4
@@ -1614,6 +1614,6 @@ 'use strict'; | ||
var last = get(state, key); | ||
var last = get(result, key); | ||
var next = handler.call(domain, last, action.payload); | ||
result = set(state, key, next); | ||
result = set(result, key, next); | ||
} | ||
@@ -1620,0 +1620,0 @@ |
@@ -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(t,u);r=p(t,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(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=_; |
{ | ||
"name": "microcosm", | ||
"version": "12.9.0-beta3", | ||
"version": "12.9.0-beta4", | ||
"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-beta3", | ||
"version": "12.9.0-beta4", | ||
"description": "Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.", | ||
@@ -5,0 +5,0 @@ "main": "microcosm.js", |
@@ -1632,6 +1632,6 @@ 'use strict'; | ||
var last = get(state, key); | ||
var last = get(result, key); | ||
var next = handler.call(domain, last, action.payload); | ||
result = set(state, key, next); | ||
result = set(result, key, next); | ||
} | ||
@@ -1638,0 +1638,0 @@ |
{ | ||
"name": "microcosm", | ||
"version": "12.9.0-beta3", | ||
"version": "12.9.0-beta4", | ||
"description": "Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.", | ||
@@ -5,0 +5,0 @@ "main": "microcosm.js", |
419554