UNPKG

rescope

Version:

Flexible state management system based on flux architecture, stores data components & inheritable scopes

2 lines 34.3 kB
module.exports=function(t){function e(i){if(s[i])return s[i].exports;var r=s[i]={exports:{},id:i,loaded:!1};return t[i].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var s={};return e.m=t,e.c=s,e.p="/",e(0)}([function(t,e,s){"use strict";function i(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0});var r=s(2),n=i(r),o=s(4),a=i(o),u=s(6),l=i(u),c=s(8),h="undefined"!=typeof window?window:global;h.___rescope||(h.___rescope=n.default,a.default.Store=l.default,n.default.Scope=a.default,n.default.Context=a.default,n.default.Store=l.default,n.default.reScope=c.reScope,n.default.scopeToState=c.scopeToState,n.default.reScopeState=c.scopeToState,n.default.addScopableType=c.addScopableType,n.default.scopeRef=function(t,e){return t[e]=new a.default.scopeRef(t[e]),t}),e.default=h.___rescope||n.default,t.exports=e.default},function(t,e){t.exports=require("is")},function(t,e){t.exports=require("./index")},function(t,e,s){"use strict";function i(t){if(Array.isArray(t)){for(var e=0,s=Array(t.length);e<t.length;e++)s[e]=t[e];return s}return Array.from(t)}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e){for(var s=0;s<e.length;s++){var i=e[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,s,i){return s&&t(e.prototype,s),i&&t(e,i),e}}(),o=s(1),a=function(){function t(){r(this,t),this._events={}}return n(t,[{key:"on",value:function(t,e){var s=this;return!o.string(t)&&t?Object.keys(t).forEach(function(e){return s.on(e,t[e])}):(this._events[t]=this._events[t]||[],void this._events[t].push(e))}},{key:"un",value:function(t,e){var s=this;if(!o.string(t)&&t)return Object.keys(t).forEach(function(e){return s.un(e,t[e])});if(this._events[t]){var i=this._events[t].indexOf(e);this._events[t].splice(i,1)}}},{key:"emit",value:function(t){if(this._events[t]){for(var e=[].concat(i(this._events[t])),s=arguments.length,r=Array(s>1?s-1:0),n=1;n<s;n++)r[n-1]=arguments[n];for(var o=0;o<e.length;o++)e[o].apply(e,r)}}},{key:"addListener",value:function(){this.on.apply(this,arguments)}},{key:"removeListener",value:function(){this.un.apply(this,arguments)}},{key:"removeAllListeners",value:function(){this._events={}}},{key:"once",value:function(t,e){var s=this,i=void 0;this.on(t,i=function(){s.un(t,i),e.apply(void 0,arguments)})}}]),t}();e.default=a,t.exports=e.default},function(t,e,s){"use strict";function i(t){if(Array.isArray(t)){for(var e=0,s=Array(t.length);e<t.length;e++)s[e]=t[e];return s}return Array.from(t)}function r(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(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}function a(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)}Object.defineProperty(e,"__esModule",{value:!0});var u,l,c=function(){function t(t,e){for(var s=0;s<e.length;s++){var i=e[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,s,i){return s&&t(e.prototype,s),i&&t(e,i),e}}(),h=s(1),_=s(3),f=s(5),p=function(t,e,s){var i=function(){};i.prototype=s?new s._[e]:t[e]||{},t[e]=new i,t._[e]=i},d={},v=({}.constructor,l=u=function(t){function e(t){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=s.parent,r=s.key,a=s.id,u=s.state,l=s.data,c=s.incrementId,_=void 0===c?!!r:c,v=s.persistenceTm,y=s.autoDestroy,b=s.rootEmitter,g=s.boundedActions;n(this,e);var m=o(this,(e.__proto__||Object.getPrototypeOf(e)).call(this)),k={};if(a=a||r&&(i&&i._id||"")+"::"+r,k.isLocalId=!a,a=a||"_____"+f.generate(),d[a]&&!_){var w;return m._id=a,d[a].register(t),w=d[a],o(m,w)}if(d[a]&&_){for(var S=-1;d[a+"["+ ++S+"]"];);a=a+"["+S+"]"}if(m._id=a,d[a]=m,k.persistenceTm=v||m.constructor.persistenceTm,m.actions={},m.stores={},m.state={},m.data={},m.parent=i,m._=k,i&&i.dead)throw new Error("Can't use a dead scope as parent !");return p(m,"actions",i),p(m,"stores",i),p(m,"state",i),p(m,"data",i),m.sources=[],k.childScopes=[],k.childScopesList=[],k.unStableChilds=0,m.__retains={all:0},m.__locks={all:1},k._boundedActions=h.array(g)?{test:g.includes.bind(g)}:g,k._listening={},k._scope={},k._mixed=[],k._mixedList=[],k.followers=[],i&&(i.retain("isMyParent"),b?i.on(k._parentList={update:function(t){return m._propag()}}):(!i._stable&&m.wait("waitingParent"),i.on(k._parentList={stable:function(t){return m.release("waitingParent")},unstable:function(t){return m.wait("waitingParent")},update:function(t){return m._propag()}}))),m.register(t,u,l),m.__locks.all--,m._stable=!m.__locks.all,i&&i._addChild(m),y&&setTimeout(function(t){m.retain("autoDestroy"),m.dispose("autoDestroy")}),m}return a(e,t),c(e,null,[{key:"getScope",value:function(t){var s=h.array(t)?t.sort(function(t,e){return t.firstname<e.firstname?-1:t.firstname>e.firstname?1:0}).join("::"):t;return d[s]=d[s]||new e({},{id:s})}},{key:"stateMapToRefList",value:function(t){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"";return Object.keys(t).forEach(function(o){var a=n?n+"."+o:o;t[o]instanceof e.scopeRef?i.push(t[o].path+":"+a):t[o]&&t[o]instanceof Function?r[o]=t[o]:t[o]&&t[o].prototype instanceof e.Store?i.push(t[o].as(a)):s[a]=t[o]}),i}}]),c(e,[{key:"mount",value:function(t,e,s,i){var r=this;return h.array(t)?t.forEach(function(t){return r._mount(t,e,s,i)}):this._mount.apply(this,arguments),this}},{key:"_mount",value:function(t,e,s,i){if("string"!=typeof t&&(this.register(r({},t.name,t.store)),t=t.name),!this._._scope[t]){var n;if(this._._mixed.reduce(function(r,n){return r||n._mount(t,e,s,i)},!1)||!this.parent)return;return(n=this.parent)._mount.apply(n,arguments)}var o=this._._scope[t];return h.fn(o)?this._._scope[t]=new o(this,{snapshot:e,name:t,state:s,data:i}):e?o.restore(e):(void 0!==s&&void 0===i?o.setState(s):void 0!==s&&(o.state=s),void 0!==i&&o.push(i)),this._watchStore(t),this._._scope[t]}},{key:"_watchStore",value:function(t,e,s){var i=this;return this._._listening[t]||h.fn(this._._scope[t])||(!this._._scope[t]._autoDestroy&&this._._scope[t].retain("scoped"),!this._._scope[t].isStable()&&this.wait(t),this._._scope[t].on(this._._listening[t]={destroy:function(e){delete i._._listening[t],i._._scope[t]=i._._scope[t].constructor},update:function(t){return i.propag()},stable:function(e){return i.release(t)},unstable:function(e){return i.wait(t)}})),!0}},{key:"mixin",value:function(t){var e=this,s=this.parent,i=void 0;this._._mixed.push(t),t.retain("mixedTo"),t._stable||this.wait(t._id),this._._mixedList.push(i={stable:function(s){return e.release(t._id)},unstable:function(s){return e.wait(t._id)},update:function(t){return e._propag()}}),this.actions={},this.stores={},this.state={},this.data={},t.on(i),p(this,"actions",s),p(this,"stores",s),p(this,"state",s),p(this,"data",s),this.relink(this._._scope,this,!1,!0),this._._mixed.forEach(function(t){p(e,"actions"),p(e,"stores"),p(e,"state"),p(e,"data"),t.relink(t._._scope,e,!0,!0)})}},{key:"register",value:function(t){var e=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.relink(t,this,!1,!1),Object.keys(t).forEach(function(r){t[r].singleton||h.fn(t[r])&&(s[r]||i[r])?e._mount(r,void 0,s[r],i[r]):s[r]||i[r]?i[r]?(s[r]&&(e.stores[r].state=s[r]),e.stores[r].push(i[r])):s[r]&&e.stores[r].setState(s[r]):e._watchStore(r)})}},{key:"relink",value:function(t){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this,i=this,r=arguments[2],n=arguments[3],o=s._.stores.prototype;Object.keys(t).forEach(function(a){if(!(!n&&s._._scope[a]===t[a]||s._._scope[a]&&s._._scope[a].constructor===t[a])){if(!n&&s._._scope[a])return r||h.fn(s._._scope[a])||(s._._scope[a].__proto__=t[a].prototype),void(!r&&h.fn(s._._scope[a])&&(s._._scope[a]=t[a]));n||r||(i._._scope[a]=t[a]),Object.defineProperty(o,a,{enumerable:!0,get:function(){return i._._scope[a]}}),Object.defineProperty(s._.state.prototype,a,{enumerable:!0,get:function(){return i._._scope[a]&&i._._scope[a].state},set:function(t){return i._mount(a,void 0,t)}}),Object.defineProperty(s._.data.prototype,a,{enumerable:!0,get:function(){return i._._scope[a]&&i._._scope[a].data},set:function(t){return i._mount(a,void 0,t)}});var u=t[a]instanceof e.Store?t[a].constructor.actions:t[a].actions,l=s._.actions.prototype;u&&Object.keys(u).forEach(function(t){l.hasOwnProperty(t)?l[t].__targetStores++:(l[t]=i.dispatch.bind(i,t),l[t].__targetStores=1)})}})}},{key:"bind",value:function(t,e,s){var i=this,n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=void 0,a=void 0,u=void 0;if(e&&!h.array(e)&&(e=[e]),s!==!1&&s!==!0||(n=s,s=null),u=e.map(function(t){return h.string(t)?t:t.name}).map(function(t){return i.parseRef(t)}),this._.followers.push([t,e,s||void 0,o=u.reduce(function(t,e){return t[e.storeId]=t[e.storeId]||{rev:0,refs:[]},t[e.storeId].refs.push(e),t},{})]),this.mount(e),this.retainStores(Object.keys(o),"listeners"),n&&this._stable){if(a=this.getUpdates(o),!a)return;"function"!=typeof t?s?t.setState(r({},s,a)):t.setState(a):t(a)}return this}},{key:"unBind",value:function(t,e,s){for(var i=this._.followers,r=i&&i.length;i&&r--;)if(i[r][0]===t&&""+i[r][1]==""+e&&i[r][2]==s)return this.disposeStores(Object.keys(i[r][3]),"listeners"),i.splice(r,1)}},{key:"map",value:function(t,e){var s=this,i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=this.constructor.Store;e=h.array(e)?e:[e];var n=e.map(this.parseRef);if(this.mount(n.map(function(t){return t.storeId})),i&&t instanceof r)r.map(t,e,this,this,!1);else if(i){this.bind(t,e,void 0,!1);var o=void 0,a=t.isReactComponent?"componentWillUnmount":"destroy";t.hasOwnProperty(a)&&(o=t[a]),t[a]=function(){return delete t[a],o&&(t[a]=o),s.unBind(t,e),t[a]&&t[a].apply(t,arguments)}}return e.reduce(function(t,e){return h.string(e)||(e=e.name),e=e.split(":"),e[0]=e[0].split("."),t[e[1]||e[0][e[0].length-1]]=s.stores[e[0][0]]&&s.stores[e[0][0]].retrieve&&s.stores[e[0][0]].retrieve(e[0].splice(1)),t},{})}},{key:"retrieve",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return t=h.string(t)?t.split("."):t,t&&this.stores[t[0]]&&this.stores[t[0]].retrieve(t.slice(1))}},{key:"getStoresRevs",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments[1],s=this._._scope;return t||(t={}),Object.keys(s).forEach(function(e){h.fn(s[e])?t.hasOwnProperty(e)||(t[e]=!1):t[e]=s[e]._rev}),e||(this._._mixed.reduce(function(e,s){return s.getStoresRevs(t),t},t),this.parent&&this.parent.getStoresRevs(t)),t}},{key:"getUpdates",value:function(t,e,s){var i=this,r=this._._scope;return e=e||{},Object.keys(r).forEach(function(n){e.hasOwnProperty(n)||h.fn(r[n])||t&&(!t.hasOwnProperty(n)||void 0!==t[n])&&(!t.hasOwnProperty(n)||r[n]._rev<=t[n].rev)||(s=!0,e[n]=i.data[n],t&&t.hasOwnProperty(n)?(t[n].rev=r[n]._rev,t[n].refs.forEach(function(t){e[t.alias]=i.retrieve(t.path)})):e[n]=i.data[n])}),s=this._._mixed.reduce(function(s,i){return i.getUpdates(t,e,s)||s},s),s=this.parent&&this.parent.getUpdates(t,e,s)||s,s&&e}},{key:"_getAllChilds",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return t.push.apply(t,i(this._.childScopes)),this._.childScopes.forEach(function(e){e._getAllChilds(t)}),t}},{key:"serialize",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},s=e.alias,i=e.withChilds,r=void 0===i||i,n=e.withParents,o=e.withMixed,a=void 0===o||o,u=e.norefs,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},c=this._._scope;if(!l[this._id])return l[this._id]={},Object.keys(c).forEach(function(t){h.fn(c[t])||c[t].serialize(!u,l)}),n&&this.parent&&this.parent.serialize({withChild:!1,withParents:!0,withMixed:a,norefs:u},l),r&&this._.childScopes.forEach(function(t){!t._.isLocalId&&t.serialize({withChild:!0,withParents:!1,withMixed:a,norefs:u},l)}),a&&this._._mixed.forEach(function(t){!t._.isLocalId&&t.serialize({withChild:!1,withParents:!1,withMixed:a,norefs:u},l)}),s&&(l=Object.keys(l).reduce(function(e,i){return e[i.replace(t._id,s)]=l[i],e},{})),l}},{key:"restore",value:function(t,e){var s=this,i=this._._scope;t[this._id]&&Object.keys(i).forEach(function(r){var n=t[s._id+"/"+r];n&&(e&&!h.fn(i[r])&&i[r].destroy(),s.mount(r,t))}),this._._mixed.forEach(function(s){!s._.isLocalId&&s.restore(t,e)}),this._.childScopes.forEach(function(s){!s._.isLocalId&&s.restore(t,e)})}},{key:"parseRef",value:function(t){var e=t.split(":");return e[0]=e[0].split("."),{storeId:e[0][0],path:e[0],alias:e[1]||e[0][e[0].length-1],ref:t}}},{key:"dispatch",value:function(t){for(var e,s=this,i=arguments.length,r=Array(i>1?i-1:0),n=1;n<i;n++)r[n-1]=arguments[n];if(!this.dead){var o=this._._boundedActions;if(Object.keys(this._._scope).forEach(function(e){var i;h.fn(s._._scope[e])||(i=s._._scope[e]).trigger.apply(i,[t].concat(r))}),!o||!o.test(t))return this._._mixed.forEach(function(e){return e.dispatch.apply(e,[t].concat(r))}),this.parent&&(e=this.parent).dispatch.apply(e,[t].concat(r)),this}}},{key:"then",value:function(t){var e=this;return this._stable?t(null,this.data):void this.once("stable",function(s){return t(null,e.data)})}},{key:"retainStores",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],s=arguments[1];e.forEach(function(e){return t.stores[e]&&t.stores[e].retain&&t.stores[e].retain(s)})}},{key:"disposeStores",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],s=arguments[1];e.forEach(function(e){return t.stores[e]&&t.stores[e].dispose&&t.stores[e].dispose(s)})}},{key:"wait",value:function(t){this._stable&&!this.__locks.all&&this.emit("unstable",this),this._stable=!1,this.__locks.all++,t&&(this.__locks[t]=this.__locks[t]||0,this.__locks[t]++)}},{key:"release",value:function(t){var e=this;t&&(0==this.__locks[t],this.__locks[t]=this.__locks[t]||0,this.__locks[t]--),!t&&0==this.__locks.all,this.__locks.all--,this.__locks.all||(this._.stabilizerTM&&clearTimeout(this._.stabilizerTM),this._.stabilizerTM=setTimeout(function(t){e._.stabilizerTM=null,e.__locks.all||(e._.propagTM&&clearTimeout(e._.propagTM),e._stable=!0,e.emit("stable",e),!e.dead&&e._propag())}))}},{key:"propag",value:function(){var t=this;this._.propagTM&&clearTimeout(this._.propagTM),this._.propagTM=setTimeout(function(e){t._.propagTM=null,t._propag()},2)}},{key:"_propag",value:function(){var t=this;this._.followers.length&&this._.followers.forEach(function(e){var s=e[0],n=(e[1],e[2]),o=e[3],a=(e[3],t.getUpdates(o));a&&("function"!=typeof s?n?s.setState(r({},n,a)):s.setState(a):s(a,o&&[].concat(i(o))||"no revs"))}),this.emit("update",this.getUpdates())}},{key:"isStable",value:function(){return this._stable}},{key:"_addChild",value:function(t){var e=this;this._.childScopes.push(t);var s={stable:function(t){e._.unStableChilds--,e._.unStableChilds||e.emit("stableTree",e)},unstable:function(t){e._.unStableChilds++,1==e._.unStableChilds&&e.emit("unstableTree",e)},stableTree:function(t){e._.unStableChilds--,e._.unStableChilds||e.emit("stableTree",e)},unstableTree:function(t){e._.unStableChilds++,1==e._.unStableChilds&&e.emit("unstableTree",e)},destroy:function(t){t._.unStableChilds&&e._.unStableChilds--,t.isStable()||e._.unStableChilds--,e._.unStableChilds||e.emit("stableTree",e)}},i=this._.unStableChilds;!t.isStable()&&this._.unStableChilds++,t._.unStableChilds&&this._.unStableChilds++,this._.childScopesList.push(s),!i&&this._.unStableChilds&&this.emit("unstableTree",this),t.on(s)}},{key:"_rmChild",value:function(t){var e=this._.childScopes.indexOf(t),s=this._.unStableChilds;e!=-1&&(this._.childScopes.splice(e,1),!t.isStable()&&this._.unStableChilds--,t._.unStableChilds&&this._.unStableChilds--,t.un(this._.childScopesList.splice(e,1)[0]),s&&!this._.unStableChilds&&this.emit("stableTree"))}},{key:"retain",value:function(t){this.__retains.all++,t&&(this.__retains[t]=this.__retains[t]||0,this.__retains[t]++)}},{key:"dispose",value:function(t){var e=this;if(t){if(!this.__retains[t])throw new Error("Dispose more than retaining : "+t);this.__retains[t]--}if(!this.__retains.all)throw new Error("Dispose more than retaining !");this.__retains.all--,this.__retains.all||(this._.persistenceTm?(this._.destroyTM&&clearTimeout(this._.destroyTM),this._.destroyTM=setTimeout(function(t){!e.__retains.all&&e.destroy()},this._.persistenceTm)):!this.__retains.all&&this.destroy())}},{key:"destroy",value:function(){var t=this,e=this._._scope;this.emit("destroy",this);for(var s in e)h.fn(e[s])||!e[s]._autoDestroy&&e[s].dispose("scoped");for(this.dead=!0,[].concat(i(this._.followers)).map(function(e){return t.unBind.apply(t,i(e))}),Object.keys(this._._listening).forEach(function(e){return t._._scope[e].removeListener(t._._listening[e])}),this._.stabilizerTM&&clearTimeout(this._.stabilizerTM),this._.propagTM&&clearTimeout(this._.propagTM),this._.isLocalId||delete d[this._id];this._._mixedList.length;)this._._mixed[0].removeListener(this._._mixedList.shift()),this._._mixed.shift().dispose("mixedTo");this._._parentList&&(this.parent._rmChild(this),this.parent.removeListener(this._._parentList),this.parent.dispose("isMyParent"),this._._parentList=null),this._=null}},{key:"datas",get:function(){return this.data}}]),e}(_),u.persistenceTm=1,u.Store=null,u.scopeRef=function(t){this.path=t},u.scopes=d,l);e.default=v,t.exports=e.default},function(t,e){t.exports=require("shortid")},function(t,e,s){"use strict";function i(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function r(t){if(Array.isArray(t)){for(var e=0,s=Array(t.length);e<t.length;e++)s[e]=t[e];return s}return Array.from(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(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}function a(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)}Object.defineProperty(e,"__esModule",{value:!0});var u,l,c=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t},h=function(){function t(t,e){for(var s=0;s<e.length;s++){var i=e[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,s,i){return s&&t(e.prototype,s),i&&t(e,i),e}}(),_=function t(e,s,i){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,s);if(void 0===r){var n=Object.getPrototypeOf(e);return null===n?void 0:t(n,s,i)}if("value"in r)return r.value;var o=r.get;return void 0!==o?o.call(i):void 0},f=s(1),p=s(4),d=s(3),v=s(7),y=s(5),b=Object.getPrototypeOf({}),g=(l=u=function(t){function e(){var t,s;n(this,e);var i,a=o(this,(e.__proto__||Object.getPrototypeOf(e)).call(this)),u=[].concat(Array.prototype.slice.call(arguments)),l=a.constructor,h=u[0]instanceof p?u.shift():l.scope?p.getScope(l.scope):f.string(u[0])?p.getScope(u.shift()):l.staticScope,_=!u[0]||f.array(u[0])||f.string(u[0])?{}:u.shift(),d=f.string(u[0])?u[0]:_.name||l.name,v=f.array(u[0])?u.shift():_.use||[],b=f.fn(u[0])?u.shift():_.apply||null,g=l.state||l.initialState||l.defaultState;return a._uid=_._uid||y.generate(),a.__retains={all:0},a.__locks={all:0},a._onStabilize=[],a._autoDestroy=!!a._persistenceTm,a._persistenceTm=_.persistenceTm||l.persistenceTm||(_.autoDestroy||l.autoDestroy)&&5,_&&_.on&&a.on(_.on),a.name=d,h.stores?(a.scopeObj=h,a.scope=h.stores):(a.scopeObj=new p(h),a.scope=h.stores),a.$scope=a.scopeObj,a.$stores=a.scopeObj.stores,a.$actions=a.scopeObj.actions,a.$dispatch=a.scopeObj.dispatch.bind(a.scopeObj),a._rev=a.constructor._rev||0,a._revs={},a.stores={},a._require=[],a._sources=[d],f.array(l.use)?a._use=[].concat(r(v),r((l.use||[]).map(function(t){var e=t.match(/^(\!?)([^\:]*)(?:\:(.*))?$/);if(e[1]){var s=e[2].split(".");a._require.push(e[3]||s[s.length-1])}return e[2]}))):a._use=[].concat(r(v),r(l.use?Object.keys(l.use).map(function(t){var e=t.match(/^(\!?)(.*)$/);return e[1]&&a._require.push(l.use[t]),e[2]+(l.use[t]===!0?"":":"+l.use[t])}):[])),l.require&&(t=a._require).push.apply(t,r(l.require)),_.require&&(s=a._require).push.apply(s,r(_.require)),a._followers=[],a._changesSW={},b&&(a.apply=b),_.snapshot&&_.snapshot[a.scopeObj._id+"/"+d]?(a.restore(_.snapshot),a._stable=!0,h.bind(a,a._use,!1)):(void 0!==l.data&&(a.data=c({},l.data)),_.hasOwnProperty("data")&&void 0!==_.data&&(a.data=_.data),_.hasOwnProperty("state")&&void 0!==_.state&&(g=c({},g,_.state)),(g||a._use.length)&&(a._changesSW=c({},g||{},h.map(a,a._use)),a.state={},a.shouldApply(a._changesSW)&&void 0===a.data&&(a.data=a.apply(a.data,a._changesSW,a._changesSW),i=!0,a.state=a._changesSW,a._changesSW={}))),void 0===a.data&&!i||a.__locks.all?(a._stable=!1,!(l.managed||a.state||a._use&&a._use.length)):(a._stable=!0,a._rev++),!a._stable&&a.emit("unstable",a.state),a}return a(e,t),h(e,[{key:"shouldPropag",value:function(t){return!0}},{key:"hasDataChange",value:function(t){var e,s=(this.constructor,this.data);return e=!s&&t||s!==t,!e&&s&&Object.keys(s).forEach(function(i){e=e||(t?s[i]!==t[i]:s&&s[i])}),!e&&t&&Object.keys(t).forEach(function(i){e=e||(t?s[i]!==t[i]:s&&s[i])}),e}},{key:"shouldApply",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state,s=this.constructor;return!!this.isComplete(e)&&(f.array(s.follow)?s.follow.reduce(function(t,s){return t||e&&e[s]},!1):!s.follow||Object.keys(s.follow).reduce(function(i,r){return i||e&&f.fn(s.follow[r])&&s.follow[r].call(t,e[r])||s.follow[r]&&e[r]!==t.state[r]},!1))}},{key:"apply",value:function(t,e,s){return e=e||this.state,this.refine?this.refine.apply(this,arguments):t&&t.__proto__===b&&e.__proto__===b?c({},t,e):e}},{key:"refine",value:function(t,e,s){return e=e||this.state,t&&t.__proto__===b&&e.__proto__===b?c({},t,e):e}},{key:"stabilize",value:function(t){t&&this.once("stable",t),this._stable&&this.emit("unstable",this.state,this.data),this._stable=!1,this._stabilizer||(this._stabilizer=v.pushTask(this,"pushState"))}},{key:"retrieve",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.data;return t=f.string(t)?t.split("."):t,s&&t&&t.length?t.length==e+1?s[t[e]]:this.retrieve(t,e+1,s[t[e]]):s}},{key:"dispatch",value:function(t){for(var e,s=arguments.length,i=Array(s>1?s-1:0),r=1;r<s;r++)i[r-1]=arguments[r];(e=this.scopeObj).dispatch.apply(e,[t].concat(i))}},{key:"trigger",value:function(t){var e=this.constructor.actions;if(e&&e[t]){for(var s,i=arguments.length,r=Array(i>1?i-1:0),n=1;n<i;n++)r[n-1]=arguments[n];var o=(s=e[t]).call.apply(s,[this].concat(r));o&&this.setState(o)}}},{key:"pull",value:function(t,e,s){var i=this,r=this.scopeObj.map(this,t);return e&&(this.wait(),t.forEach(function(t){return i.scope[t]&&i.wait(i.scope[t])}),this.release()),r}},{key:"push",value:function(t,e,s){if(s=e===!0?s:e,e=e===!0,!e&&!this.hasDataChange(t)){if(s&&s(),!this.__locks.all){var i=this._stable;this._stable=!0,!i&&this.emit("stable",this.state,this.data),this._stabilizer=null}return!1}this.data=t,this.wait(),this.release(s)}},{key:"pushState",value:function(t){if(t||this._changesSW||!this.data){var e=c({},this.state,this._changesSW||{}),s=this.apply(this.data,e,this._changesSW);if(this._stabilizer=null,this.state=e,this._changesSW=null,!t&&!this.hasDataChange(s)){if(!this.__locks.all){var i=this._stable;this._stable=!0,!i&&this.emit("stable",this.state,this.data),this._stabilizer=null}return!1}this.data=s,this.wait(),this.release()}}},{key:"setState",value:function(t,e,s){var i,r=this._changesSW=this._changesSW||{};for(var n in t)(!this.state||r.hasOwnProperty(n)&&t[n]!==r[n]||t.hasOwnProperty(n)&&(t[n]!==this.state[n]||this.state[n]&&t[n]&&t[n]._rev!=this._revs[n]))&&(i=!0,this._revs[n]=t[n]&&t[n]._rev||!0,r[n]=t[n]);if(this.shouldApply(c({},this.state,r)))return s?(this.pushState(),e&&e()):i?this.stabilize(e):e&&e(),this}},{key:"setStateSync",value:function(t){var e,s=this._changesSW=this._changesSW||{};for(var i in t)(!this.state||t.hasOwnProperty(i)&&(t[i]!=this.state[i]||this.state[i]&&t[i]&&t[i]._rev!=this._revs[i]))&&(e=!0,this._revs[i]=t[i]&&t[i]._rev||!0,s[i]=t[i]);return this.shouldApply(c({},this.state||{},s))&&this.pushState(),this.data}},{key:"as",value:function(t){return{store:this,name:t}}},{key:"on",value:function(t){var s=this;!f.string(t)&&t?Object.keys(t).forEach(function(i){return _(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"on",s).call(s,i,t[i])}):_(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"on",this).apply(this,arguments)}},{key:"removeListener",value:function(t){var s=this;!f.string(t)&&t?Object.keys(t).forEach(function(i){return _(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"removeListener",s).call(s,i,t[i])}):_(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"removeListener",this).apply(this,arguments)}},{key:"isComplete",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state;return this.constructor,!this._require||!this._require.length||t&&this._require.reduce(function(e,s){return e&&t[s]},!0)}},{key:"isStable",value:function(){return this._stable}},{key:"serialize",value:function(){var t=this,e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=e&&f.array(this._use)&&this._use.reduce(function(e,s){var i=void 0,r=void 0,n=void 0;return s.store&&s.name?r=i=s.name:f.fn(s)?i=r=s.name||s.defaultName:(s=s.match(/([\w_]+)((?:\.[\w_]+)*)(?:\:([\w_]+))?/),i=s[1],n=s[2]&&s[2].substr(1),r=s[3]||n&&n.match(/([^\.]*)$/)[0]||s[1]),t.scopeObj.stores[i].scopeObj._.isLocalId||(e[r]=t.scopeObj.stores[i].scopeObj._id+"/"+i),e},{})||{};return s[this.scopeObj._id+"/"+this.name]={state:this.state&&(e?Object.keys(this.state).reduce(function(e,s){return!i[s]&&(e[s]=t.state[s]),e},{}):c({},this.state)),data:this.data,refs:i},s}},{key:"restore",value:function(t){var e=t[this.scopeObj._id+"/"+this.name];e&&(this.state=e.state,Object.keys(e.refs).forEach(function(s){t[e.refs[s]]&&(e.state[s]=t[e.refs[s]].data)}),this.data=e.data)}},{key:"unBind",value:function(t,e,s){for(var i=this._followers,r=i&&i.length;i&&r--;)if(i[r][0]===t&&i[r][1]===e&&i[r][2]===s)return i.splice(r,1)}},{key:"bind",value:function(t,e){var s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=arguments[3];if(this._followers.push([t,e,r]),s&&this.data&&this._stable){var n=r?this.retrieve(r):this.data;"function"!=typeof t?e?t.setState(i({},e,n)):t.setState(n):t(n)}}},{key:"then",value:function(t){var e=this;return this._stable?t(null,this.data):void this.once("stable",function(s){return t(null,e.data)})}},{key:"wait",value:function(t){if("number"==typeof t)return this.__locks.all+=t;if(f.array(t))return t.map(this.wait.bind(this));this._stable&&this.emit("unstable",this.state,this.data),this._stable=!1,this.__locks.all++;var e=f.string(t)?t:null;return e&&(this.__locks[e]=this.__locks[e]||0,this.__locks[e]++),t&&f.fn(t.then)&&t.then(this.release.bind(this,null)),this}},{key:"release",value:function(t,e){var s=(this.constructor,this),r=this._stable;if(f.fn(t)&&(e=t,t=null),t&&(0==this.__locks[t],this.__locks[t]=this.__locks[t]||0,this.__locks[t]--),!t&&0==this.__locks.all,!--this.__locks.all&&this.isComplete()){var n=this.shouldPropag(this.data);this._stable=!0,n&&this._rev++,n&&this._followers.length&&this._followers.forEach(function(t){var e=t[2]?s.retrieve(t[2]):s.data;"function"==typeof t[0]?t[0](e):t[0].setState(t[1]?i({},t[1],e):e)}),!r&&this.emit("stable",this.data),n&&this.emit("update",this.data),e&&e()}else e&&this.then(e);return this}},{key:"propag",value:function(t){this.emit("update",t)}},{key:"retain",value:function(t){this.__retains.all++,t&&(this.__retains[t]=this.__retains[t]||0,this.__retains[t]++)}},{key:"dispose",value:function(t){var e=this;if(t){if(!this.__retains[t])throw new Error("Dispose more than retaining : "+t);this.__retains[t]--}if(0==this.__retains.all)throw new Error("Dispose more than retaining !");this.__retains.all--,this.__retains.all||(this._persistenceTm?(this._destroyTM&&clearTimeout(this._destroyTM),this._destroyTM=setTimeout(function(t){e._destroyTM=null,!e.__retains.all&&e.destroy()},this._persistenceTm)):!this.__retains.all&&this.destroy())}},{key:"destroy",value:function(){this.emit("destroy",this),this._stabilizer&&clearTimeout(this._stabilizer),this._followers.length&&this._followers.forEach(function(t){"function"!=typeof t[0]&&t[0].stores&&delete t[0].stores[t[1]]}),this._followers.length=0,this.constructor._rev=this.rev,this.dead=!0,this._revs=this.data=this.state=this.scope=null,this.removeAllListeners()}},{key:"contextObj",get:function(){return this.scopeObj}},{key:"context",get:function(){return this.scope}},{key:"datas",get:function(){return this.data},set:function(t){this.data=t}},{key:"nextState",get:function(){return this._changesSW&&c({},this.state,this._changesSW)||this.state}}]),e}(d),u.use=[],u.staticScope=new p({},{id:"static"}),u.state=void 0,u.persistenceTm=!1,l);g.as=function(t){return{store:this,name:t}},g.map=function(t,e,s,i){var n=arguments.length>4&&void 0!==arguments[4]&&arguments[4],o=t._revs||{},a=t.stores||(t.stores={}),u={};e=f.array(e)?[].concat(r(e)):[e],s=s||g.staticScope,e=e.filter(function(e){var i;if(!e)return!1;var l=void 0,c=void 0,h=void 0,_=void 0;return e.store&&e.name?(c=l=e.name,_=e.store):f.fn(e)?(l=c=e.name||e.defaultName,_=e):(e=e.match(/([\w_]+)((?:\.[\w_]+)*)(?:\:([\w_]+))?/),l=e[1],h=e[2]&&e[2].substr(1),_=s.stores[e[1]],c=e[3]||h&&h.match(/([^\.]*)$/)[0]||e[1]),!o[l]&&!!_&&(f.fn(_)?(s._mount(l),s.stores[l].bind(t,c,n,h)):_.bind(t,c,n,h),(i=t._sources).push.apply(i,r(s.stores[l]._sources)),o[c]=o[c]||!0,!a[l]&&(a[l]=s.stores[l]),s.stores[l].hasOwnProperty("data")&&(u[l]=s.data[l]),!0)});var l,c=t.isReactComponent?"componentWillUnmount":"destroy";return t.hasOwnProperty(c)&&(l=t[c]),t[c]=function(){return delete t[c],l&&(t[c]=l),e.map(function(e){var i=void 0,r=void 0,n=void 0,o=void 0;e.store&&e.name?(r=i=e.name,o=e.store):f.fn(e)?(i=r=e.name||e.defaultName,o=s.stores[i]):(e=e.match(/([\w_]+)((?:\.[\w_]+)*)(?:\:([\w_]+))?/),i=e[1],n=e[2]&&e[2].substr(1),o=s.stores[e[1]],r=e[3]||n&&n.match(/([^\.]*)$/)[0]||e[1]),o&&!f.fn(o)&&o.unBind(t,r,n)}),t[c]&&t[c].apply(t,arguments)},u},e.default=g,t.exports=e.default},function(t,e,s){"use strict";function i(t){return t&&t.__esModule?t:{default:t}}function r(){f||n()}function n(){for(Date.now(),f=!0,p.enable();h;){for(;!u[l]||!u[l].length;)l++;h--,_=u[l].shift(),_[0][_[1]].apply(_[0],_[2])}_=void 0,p.disable(),f=!1,h&&setTimeout(r)}Object.defineProperty(e,"__esModule",{value:!0});var o=s(2),a=(i(o),s(1)),u=(i(a),[]),l=0,c=0,h=0,_=void 0,f=void 0,p={lastError:null,dispatch:function(t){p.disable(),_&&_[0].handleError&&_[0].handleError(t,_),f=!1,_=null,r()},enable:"undefined"!=typeof window?function(){ window.addEventListener("error",p.dispatch)}:function(){process.on("uncaughtException",p.dispatch)},disable:"undefined"!=typeof window?function(){window.removeEventListener("error",p.dispatch)}:function(){process.removeListener("uncaughtException",p.dispatch)}};e.default={pushTask:function(t,e,s){var i=t._sources&&t._sources.length||1,n=u[i]=u[i]||[];return c=Math.max(c,i),l=Math.min(l,i),h++,n.push([t,e,s]),setTimeout(r),n.length}},t.exports=e.default},function(t,e,s){"use strict";function i(t){return t&&t.__esModule?t:{default:t}}function r(t){if(Array.isArray(t)){for(var e=0,s=Array(t.length);e<t.length;e++)s[e]=t[e];return s}return Array.from(t)}function n(t,e){var s=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];_.push({test:t,member:s,stateScope:i,handle:e})}function o(t,e,s){for(var i=0;i<_.length;i++)if((void 0===e||e==_[i].member)&&s==_[i].stateScope&&_[i].test(t))return!0;return!1}function a(t,e,s,i){for(var n=0;n<_.length;n++){var o;if(s==_[n].member&&i==_[n].stateScope&&_[n].test(t))return(o=_[n]).handle.apply(o,[t].concat(r(e)))}return!1}function u(){for(var t=arguments.length,e=Array(t),s=0;s<t;s++)e[s]=arguments[s];return e[0]instanceof h&&e[2]instanceof h&&e[0].hasOwnProperty(e[1])?(e[2].value=a(e[0],[],!0,!1),e[0]):o(e[0],void 0,!1)?a(e[0],e.slice(1),!1,!1):function(){for(var t=arguments.length,s=Array(t),i=0;i<t;i++)s[i]=arguments[i];return s[0]instanceof h&&s[2]instanceof h&&s[0].hasOwnProperty(s[1])?(s[2].value=a(s[0],e,!0,!1),s[0]):u.apply(void 0,[s[0]].concat(e))}}function l(){for(var t=arguments.length,e=Array(t),s=0;s<t;s++)e[s]=arguments[s];return e[0]instanceof h&&e[2]instanceof h&&e[0].hasOwnProperty(e[1])?(e[2].value=a(e[0],[],!0,!0),e[0]):o(e[0],void 0,!0)?a(e[0],e.slice(1),!1,!0):function(){for(var t=arguments.length,s=Array(t),i=0;i<t;i++)s[i]=arguments[i];return s[0]instanceof h&&s[2]instanceof h&&s[0].hasOwnProperty(s[1])?(s[2].value=a(s[0],e,!0,!0),s[0]):l.apply(void 0,[s[0]].concat(e))}}Object.defineProperty(e,"__esModule",{value:!0}),e.scopeToState=e.reScope=e.addScopableType=void 0;var c=s(1),h=(i(c),s(2),{}.constructor),_=[];e.addScopableType=n,e.reScope=u,e.scopeToState=l}]);