rescope
Version:
Intuitive & scalable state management system based on flux architecture, stores data components & inheritable scopes
25 lines • 42.9 kB
JavaScript
/*!
* MIT License
*
* Copyright (c) 2018 Wise Wild Web
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
module.exports=function(t){var e={};function s(i){if(e[i])return e[i].exports;var n=e[i]={i:i,l:!1,exports:{}};return t[i].call(n.exports,n,n.exports,s),n.l=!0,n.exports}return s.m=t,s.c=e,s.d=function(t,e,i){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,e){if(1&e&&(t=s(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)s.d(i,n,function(e){return t[e]}.bind(null,n));return i},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="/",s(s.s=14)}([function(t,e){t.exports=require("is")},function(t,e){t.exports=require("@babel/runtime/helpers/toConsumableArray")},function(t,e,s){"use strict";s.r(e),s.d(e,"walknSet",(function(){return a})),s.d(e,"walknGet",(function(){return o})),s.d(e,"keyWalknSet",(function(){return h})),s.d(e,"keyWalknGet",(function(){return u}));var i=s(1),n=s.n(i),r=s(0);function a(t,e,s,i){return r.string(e)&&(e=e.split(".")),!!e.length&&(1==e.length?t[e[0]]=i?[].concat(n()(t[e[0]]||[]),[s]):s:a(t[e[0]]=t[e[0]]||{},e.slice(1),s,i))}function o(t,e,s){return r.string(e)&&(e=e.split(".")),e.length?t[e[0]]&&o(t[e[0]],e.slice(1)):t}function h(t,e,s,i){return r.string(e)&&(e=e.split(/(\>|\/)/gi).filter((function(t){return">"!==t&&t}))),a(t,e,s)}function u(t,e,s){return r.string(e)&&(e=e.split(/(\>|\/)/gi).filter((function(t){return">"!==t&&t}))),e.length?t[e[0]]&&o(t[e[0]],e.slice(1)):t}},function(t,e){t.exports=require("@babel/runtime/helpers/defineProperty")},function(t,e){t.exports=require("@babel/runtime/helpers/assertThisInitialized")},function(t,e){t.exports=require("@babel/runtime/helpers/getPrototypeOf")},function(t,e){t.exports=require("@babel/runtime/helpers/createClass")},function(t,e){t.exports=require("@babel/runtime/helpers/classCallCheck")},function(t,e){t.exports=require("@babel/runtime/helpers/possibleConstructorReturn")},function(t,e){t.exports=require("@babel/runtime/helpers/get")},function(t,e){t.exports=require("@babel/runtime/helpers/inherits")},function(t,e){t.exports=require("shortid")},function(t,e,s){"use strict";s.r(e),s.d(e,"default",(function(){return l}));var i=s(1),n=s.n(i),r=s(7),a=s.n(r),o=s(6),h=s.n(o),u=s(0),c=s.n(u),l=function(){function t(){a()(this,t),this._events={}}return h()(t,[{key:"on",value:function(t,e){var s=this;if(!c.a.string(t)&&t)return Object.keys(t).forEach((function(e){return s.on(e,t[e])}));this._events[t]=this._events[t]||[],this._events[t].push(e)}},{key:"un",value:function(t,e){var s=this;if(!c.a.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=n()(this._events[t]),s=arguments.length,i=new Array(s>1?s-1:0),r=1;r<s;r++)i[r-1]=arguments[r];for(var a=0;a<e.length;a++)e[a].apply(e,i)}}},{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,i=this;this.on(t,s=function(){i.un(t,s),e.apply(void 0,arguments)})}}]),t}()},function(t,e,s){"use strict";s.r(e);var i=s(1),n=s.n(i),r=s(3),a=s.n(r),o=s(7),h=s.n(o),u=s(8),c=s.n(u),l=s(5),p=s.n(l),f=s(4),_=s.n(f),d=s(6),v=s.n(d),y=s(10),b=s.n(y),g=s(0),m=s.n(g),k=s(11),S=s.n(k),w=s(12),O=s(2);function j(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),s.push.apply(s,i)}return s}function T(t){for(var e=1;e<arguments.length;e++){var s=null!=arguments[e]?arguments[e]:{};e%2?j(Object(s),!0).forEach((function(e){a()(t,e,s[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):j(Object(s)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(s,e))}))}return t}var x=function(t,e,s){var i=function(){};i.prototype=s?new s._[e]:t[e]||{},t[e]=new i,t._[e]=i},C={},E=function(t){function e(t){var s,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.parent,r=i.upperScope,a=i.key,o=i.keyMap,u=void 0===o?n&&n.keyMap||{}:o,l=i.id,f=i.snapshot,d=i.state,v=i.data,y=i.incrementId,b=void 0===y?!!a:y,g=i.persistenceTm,k=i.autoDestroy,w=i.rootEmitter,O=i.boundedActions;h()(this,e),s=c()(this,p()(e).call(this));var j={keyPID:r&&r._id||n&&n._id||S.a.generate(),key:a,incrementId:b,baseId:l};if(l=l||a&&j.keyPID+">"+a,j.isLocalId=!l,u[l=l||"_____"+S.a.generate()]&&b){for(var T=-1;u[l+"["+ ++T+"]"];);l=l+"["+T+"]"}if(u[l]=!0,s.keyMap=u,C[l])return s._id=l,j.baseId&&C[l].register(t),c()(s,C[l]);if(C[l]=_()(s),s._id=l,s._rev=0,s._=j,s.actions={},s.stores={},s.state={},s.data={},s.parent=n,"inherit"==k&&(k=n&&n._autoDestroy),s._autoDestroy=k,j.persistenceTm=g||s.constructor.persistenceTm,n&&n.dead)throw new Error("Can't use a dead scope as parent !");return x(_()(s),"actions",n),x(_()(s),"stores",n),x(_()(s),"state",n),x(_()(s),"data",n),s.sources=[],j.childScopes=[],j.childScopesList=[],j.unStableChilds=0,j.seenChilds=0,j._listening={},j._scope={},j._mixed=[],j._mixedList=[],j.followers=[],s.__retains={all:0},s.__locks={all:1},j._boundedActions=m.a.array(O)?{test:O.includes.bind(O)}:O,n&&(n.retain("isMyParent"),w?n.on(j._parentList={update:function(t){return s._propag()}}):(!n._stable&&s.wait("waitingParent"),n.on(j._parentList={stable:function(t){return s.release("waitingParent")},unstable:function(t){return s.wait("waitingParent")},update:function(t){return s._propag()}}))),f&&s.restore(f),s.register(t,d,v),s.__locks.all--,s._stable=!s.__locks.all,n&&n._addChild(_()(s)),k&&setTimeout((function(t){s.retain("autoDestroy"),s.dispose("autoDestroy")})),s}return b()(e,t),v()(e,null,[{key:"stateMapToRefList",value:function(t){var s,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"";return Object.keys(t).forEach((function(o){var h=a?a+"."+o:o;t[o]instanceof e.scopeRef?n.push(t[o].path+":"+h):t[o]&&t[o]instanceof Function?"$apply"===o?s=t[o]:r[o]=t[o]:t[o]&&t[o].prototype instanceof e.Store?n.push(t[o].as(h)):i[h]=t[o]})),s}},{key:"getScope",value:function(t){var s=m.a.array(t)?t.sort((function(t,e){return t.firstname<e.firstname?-1:t.firstname>e.firstname?1:0})).join("+"):t;return C[s]=C[s]||new e({},{id:s})}}]),v()(e,[{key:"mount",value:function(t,e,s,i){var n=this;return m.a.array(t)?t.forEach((function(t){return n._mount(t,e,s,i)})):this._mount.apply(this,arguments),this}},{key:"_mount",value:function(t,s,i,n){var r,a=this._;if(r=this.parseRef(t),"$parent"!=t){if(!a._scope[r.storeId]){var o;if(a._mixed.reduceRight((function(e,r){return e||r._mount(t,s,i,n)}),!1)||!this.parent)return;return(o=this.parent)._mount.apply(o,arguments)}var h=a._scope[r.storeId],u=[];if(e.isStoreClass(h))for(a._scope[r.storeId]=new h(this,{name:r.storeId,state:i,data:n},u);u.length;)u.shift()();else e.isScopeClass(h)&&(h=a._scope[r.storeId]=new h({$parent:this},{key:r.storeId,incrementId:!0,upperScope:this}),r.path.length>1&&a._scope[r.storeId].mount(r.path.slice(1).join("."),s,i,n));return e.isStore(h)&&(void 0!==i&&void 0===n?h.setState(i):void 0!==i&&(h.state=i),void 0!==n&&h.push(n)),e.isScope(h)&&(void 0!==i&&h.setState(i),r.path.length>1&&h._mount(r.path.slice(1).join("."))),this._watchStore(r.storeId),a._scope[r.storeId]}}},{key:"resetKeys",value:function(){for(var t in this.keyMap)this.keyMap.hasOwnProperty(t)&&delete this.keyMap[t]}},{key:"register",value:function(t){var s=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.relink(t,this,!1,!1),Object.keys(t).forEach((function(r){if("$parent"!==r)return e.isScopable(t[r])?void(t[r].singleton||m.a.fn(t[r])&&(i[r]||n[r])?s._mount(r,void 0,i[r],n[r]):i[r]||n[r]?n[r]?(i[r]&&(s.stores[r].state=i[r]),s.stores[r].push(n[r])):i[r]&&s.stores[r].setState(i[r]):s._watchStore(r)):console.warn("RS: ",s._id,", can't register not scopable object :",r)}))}},{key:"relink",value:function(t){var s=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this,n=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,a=this._;Object.keys(t).forEach((function(o){var h,u;if(!(!r&&i._._scope[o]===t[o]||i._._scope[o]&&i._._scope[o].constructor===t[o])){if(!r&&i._._scope[o]?n||m.a.fn(i._._scope[o])?!n&&m.a.fn(i._._scope[o])&&(i._._scope[o]=t[o]):(i._._scope[o].__proto__=t[o].prototype,i._._scope[o].__onHotReloaded&&i._._scope[o].__onHotReloaded(t[o])):r||n||(a._scope[o]=t[o]),Object.defineProperty(i._.stores.prototype,o,{enumerable:!0,configurable:!0,get:function(){return a._scope[o]}}),u=i._.actions.prototype,"$parent"!==o){if(Object.defineProperty(i._.state.prototype,o,{enumerable:!0,configurable:!0,get:function(){return a._scope[o]&&a._scope[o].state},set:function(t){return s._mount(o,void 0,t)}}),Object.defineProperty(i._.data.prototype,o,{enumerable:!0,configurable:!0,get:function(){return a._scope[o]&&a._scope[o].data},set:function(t){return s._mount(o,void 0,void 0,t)}}),h=t[o]instanceof e.Store?t[o].constructor.actions:t[o].actions,e.isScopeClass(a._scope[o])&&s._mount(o),e.isScope(a._scope[o]))u[o]&&console.warn("RS : Sub scope actions is mapped over an existing function !",o),u[o]=a._scope[o].actions;else if(!e.isStore(a._scope[o])&&!e.isStoreClass(a._scope[o]))return;h&&s._mapActions(h,u,o)}else u[o]=t[o].actions;void 0}}))}},{key:"_mapActions",value:function(t,e,s){for(var i in t)t.hasOwnProperty(i)&&(m.a.object(t[i])?(e[i]&&!m.a.object(e[i])&&console.warn("RS : Actions namespace is mapped over an existing function !",s,i),e[i]=e[i]||{__targetStores:0},this._mapActions(t[i],e[i]),e[i].__targetStores++):e.hasOwnProperty(i)?e[i].__targetStores++:(m.a.object(e[i])&&console.warn("RS : Action is mapped over existing namespace !",s,i),e[i]=this.dispatch.bind(this,i),e[i].__targetStores=1))}},{key:"_watchStore",value:function(t){var e=this,s=this._;return s._listening[t]||m.a.fn(s._scope[t])||(!s._scope[t]._autoDestroy&&s._scope[t].retain("scoped"),!s._scope[t].isStable()&&this.wait(t),s._scope[t].on(s._listening[t]={destroy:function(e){delete s._listening[t],s._scope[t]=s._scope[t].constructor},update:function(t){return e.propag()},stable:function(s){return e.release(t)},unstable:function(s){return e.wait(t)}})),!0}},{key:"mixin",value:function(t){var e,s=this,i=this.parent,n=this._;n._mixed.push(t),t.retain("mixedTo"),t._stable||this.wait(t._id),n._mixedList.push(e={stable:function(e){return s.release(t._id)},unstable:function(e){return s.wait(t._id)},update:function(t){return s._propag()}}),t.on(e),x(this,"actions",i),x(this,"stores",i),x(this,"state",i),x(this,"data",i),this.relink(n._scope,this,!1,!0),n._mixed.forEach((function(t){x(s,"actions"),x(s,"stores"),x(s,"state"),x(s,"data"),s.stores.__origin="mixed "+t._id,t.relink(t._._scope,s,!0,!0)}))}},{key:"bind",value:function(t,e,s){var i,n,r,o=this,h=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};if(e&&!m.a.array(e)&&(e=[e]),!1!==s&&!0!==s||(h=s,s=null),r=e.map((function(t){return m.a.string(t)?t:t.name})).map((function(t){return o.parseRef(t)})),this._.followers.push([t,e,s||void 0,i=r.reduce((function(t,e){return t[e.storeId]=t[e.storeId]||{rev:0,refs:[]},t[e.storeId].refs.push(e),t}),u)]),this.mount(e),this.retainStores(Object.keys(i),"listeners"),h&&this._stable){if(!(n=this.getUpdates(i)))return this;"function"!=typeof t?s?t.setState(a()({},s,n)):t.setState(n):t(n)}return this}},{key:"unBind",value:function(t,e,s){for(var i=this._.followers,n=i&&i.length;i&&n--;)if(i[n][0]===t&&""+i[n][1]==""+e&&i[n][2]==s)return this.disposeStores(Object.keys(i[n][3]),"listeners"),i.splice(n,1)}},{key:"map",value:function(t,e){var s=this,i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n=arguments.length>3?arguments[3]:void 0,r=this.constructor.Store,a=(e=m.a.array(e)?e:[e]).map(this.parseRef);if(this.mount(e),i&&t instanceof r)r.map(t,e,this,this,!1);else if(i){this.bind(t,e,void 0,!1);var o,h=t.isReactComponent?"componentWillUnmount":"destroy";t.hasOwnProperty(h)&&(o=t[h]),t[h]=function(){return delete t[h],o&&(t[h]=o),s.unBind(t,e),t[h]&&t[h].apply(t,arguments)}}return n&&this.getUpdates(n)||a.reduce((function(t,e){return Object(O.walknSet)(t,e.alias||e.path,s.retrieve(e.path)),t}),{})}},{key:"retrieve",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(t=m.a.string(t)?t.split("."):t)&&this.stores[t[0]]&&this.stores[t[0]].retrieve&&this.stores[t[0]].retrieve(t.slice(1))}},{key:"restoreRefPath",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";t=m.a.string(t)?t.split("."):t;for(var s,i=0,n=this;i<t.length;){if(s=n.stores[t[i]],(e.isScopeClass(s)||e.isStoreClass(s))&&(n.mount(t[0]),s=n.stores[t[i]]),!e.isScope(s)){if(e.isStore(s)){s.restore();break}break}n=s,i++}}},{key:"retrieveStore",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(t=m.a.string(t)?t.split("."):t)&&t.length&&(1!=t.length&&this.stores[t[0]].retrieveStore?this.stores[t[0]].retrieveStore(t.slice(1)):1==t.length&&this.stores[t[0]])}},{key:"getStoresRevs",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,s=this._._scope;return t||(t={}),Object.keys(s).forEach((function(e){"$parent"!=e&&(m.a.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:"_getRevMap",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=this._._scope;return Object.keys(e).forEach((function(s){"$parent"===s||t[s]||(t[s]={rev:e[s]._rev,refs:[]})})),this._._mixed.reduceRight((function(t,e){return e._getRevMap(t)}),t),this.parent&&this.parent._getRevMap(t),t}},{key:"getRefsUpdates",value:function(t,e,s){var i=this;return e=e||t.map((function(t){return m.a.string(t)?t:t.name})).map((function(t){return i.parseRef(t)})).reduce((function(t,e){return t[e.storeId]=t[e.storeId]||{rev:0,refs:[]},t[e.storeId].refs.push(e),t}),{}),this.getUpdates(e,s)}},{key:"getUpdates",value:function(t,e,s){var i=this;return e=e||{},t=t||this._getRevMap(),Object.keys(t).forEach((function(n){var r=i.stores[n];t[n]=t[n]||{rev:0,refs:[]},r&&m.a.fn(r)?(s=!0,e[n]=void 0):r&&r._rev>t[n].rev&&(t[n].rev=r._rev,s=!0,t[n].refs.forEach((function(t){e[t.alias]=i.retrieve(t.path)})))})),s&&e}},{key:"_getAllChilds",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return t.push.apply(t,n()(this._.childScopes)),this._.childScopes.forEach((function(e){e._getAllChilds(t)})),t}},{key:"serialize",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=(this._._scope,this._),i=s.baseId,n=s.key,r=s.keyPID,a=(s.incrementId,t.alias),o=t.parentAlias,h=n?(o||r)+">"+n:a||o&&o+"/"+i||this._id;return this.serialize_ex(t,e,h,a,["$parent"])}},{key:"serialize_ex",value:function(){var t=this,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,a=arguments.length>4?arguments[4]:void 0,o=this._,h=o._scope,u=o.incrementId,c=s.withChilds,l=void 0===c||c,p=s.withMixed,f=void 0===p||p,_=s.norefs;if(Object(O.keyWalknGet)(i,n)){if(!u)return i;if(u){for(var d=-1;Object(O.keyWalknGet)(i,n+"["+ ++d+"]"););n=n+"["+d+"]"}}return Object(O.keyWalknSet)(i,n,{}),Object.keys(h).forEach((function(t){a.includes(t)||e.isStoreClass(h[t])||e.isScopeClass(h[t])||h[t].serialize(T({},s,{parentAlias:n}),i)})),l&&o.childScopes.forEach((function(t){!t._.isLocalId&&t.serialize({withChild:!0,withParents:!1,parentAlias:n,withMixed:f,norefs:_},i)})),f&&o._mixed.forEach((function(t){!t._.isLocalId&&t.serialize({withChild:!1,withParents:!1,withMixed:f,norefs:_},i)})),r&&(i=Object.keys(i).reduce((function(e,s){return e[s===t._id?r:s]=i[s],e}),{})),i}},{key:"restore",value:function(t){var e,s=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:m.a.bool(i)&&i,r=this._._scope;t&&i&&i.alias&&i.alias!=this._id&&(delete(e=T({},t,a()({},this._id,t[i.alias])))[i.alias],t=e),(t=t&&Object(O.keyWalknGet)(t,this._id)||this.takeSnapshotByKey(this._id))&&(this._.snapshot=T({},t),e=t["/"],t["/"]=T({},e),e&&Object.keys(e).forEach((function(t){"$parent"!=t&&r[t]&&(n&&!m.a.fn(r[t])&&r[t].destroy(),s._mount(t))})),this._._mixed.forEach((function(t){!t._.isLocalId&&t.restore(void 0,n)})),this._.childScopes.forEach((function(t){!t._.isLocalId&&t.restore(void 0,n)})))}},{key:"getSnapshotByKey",value:function(t,e){return this._.snapshot&&t.startsWith(this._id)?Object(O.keyWalknGet)(this._.snapshot,t.substr(this._id.length)):!e&&this.parent&&this.parent.getSnapshotByKey(t)||this.stores.$parent&&this.stores.$parent.getSnapshotByKey(t)}},{key:"getSnapshotByKeyExt",value:function(t,e,s){if(t)return Object(O.keyWalknGet)(t,e)}},{key:"takeSnapshotByKey",value:function(t,e){if(this._.snapshot&&t.startsWith(this._id)){var s=Object(O.keyWalknGet)(this._.snapshot,t.substr(this._id.length));return s&&this.deleteSnapshotByKey(t,!0),s}return!e&&this.parent&&this.parent.takeSnapshotByKey(t)||this.stores.$parent&&this.stores.$parent.takeSnapshotByKey(t)}},{key:"deleteSnapshotByKey",value:function(t,e){if(this._.snapshot&&t.startsWith(this._id)){var s=Object(O.keyWalknGet)(this._.snapshot,t.substr(this._id.length).replace(/^(.*[\>|\/])[^\>|\/]+$/gi,"$1"));s&&delete s[t.replace(/^.*[\>|\/]([^\>|\/]+)$/gi,"$1")]}return!e&&this.parent&&this.parent.deleteSnapshotByKey(t)||this.stores.$parent&&this.stores.$parent.deleteSnapshotByKey(t)}},{key:"setState",value:function(t){var e=this;Object.keys(t).forEach((function(s){return e.state[s]=t[s]}))}},{key:"parseRef",value:function(t){"string"!=typeof t&&(this.register(a()({},t.name,t.store)),t=t.name);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=arguments.length,i=new Array(s>1?s-1:0),n=1;n<s;n++)i[n-1]=arguments[n];if(!this.dead){var r=this._._boundedActions;for(var a in this._._scope){var o;"$parent"!==a&&(m.a.fn(this._._scope[a])||(o=this._._scope[a]).trigger.apply(o,[t].concat(i)))}return r&&r.test(t)?this:(this._._mixed.forEach((function(e){return e.dispatch.apply(e,[t].concat(i))})),this.parent&&(e=this.parent).dispatch.apply(e,[t].concat(i)),this)}console.warn("Dispatch was called on a dead scope, check you're async functions in this stack...",(new Error).stack)}},{key:"trigger",value:function(){this.dispatch.apply(this,arguments)}},{key:"then",value:function(t){var e=this;return this._stable?t(this.data):this.once("stable",(function(s){return e.then(t)}))}},{key:"onceStableTree",value:function(t){var e=this;return this._.unStableChilds?this.once("stableTree",(function(s){return e.onceStableTree(t)})):t(this.data)}},{key:"retainStores",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],s=arguments.length>1?arguments[1]:void 0;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.length>1?arguments[1]:void 0;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;if(t&&(0==this.__locks[t]&&console.error("Release more than locking !",t),this.__locks[t]=this.__locks[t]||0,this.__locks[t]--),t||0!=this.__locks.all||console.error("Release more than locking !"),this.__locks.all--,!this.__locks.all){if(this._.stabilizerTM)return;this._.stabilizerTM&&clearTimeout(this._.stabilizerTM),this._.stabilizerTM=setTimeout((function(t){e._.stabilizerTM=null,e.__locks.all||(e._.propagTM&&clearTimeout(e._.propagTM),e._rev++,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],i=(e[1],e[2]),n=e[3],r=(e[3],t.getUpdates(n));r&&("function"!=typeof s?i?s.setState(a()({},i,r)):s.setState(r):s(r,n&&T({},n)||"no revs"))})),this.emit("update",this.getUpdates())}},{key:"isStable",value:function(){return this._stable}},{key:"isStableTree",value:function(){return!this._.unStableChilds}},{key:"_addChild",value:function(t){var e=this;this._.childScopes.push(t),this._.seenChilds++;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;-1!=e&&(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.then((function(t){!e.__retains.all&&!e.dead&&e.destroy()}))}),this._.persistenceTm)):this.then((function(t){return!e.__retains.all&&!e.dead&&e.destroy()})))}},{key:"destroy",value:function(){var t=this,e=this._._scope;for(var s in n()(this._.childScopes).map((function(t){return t.destroy()})),e)if(!m.a.fn(e[s])){if("$parent"==s)continue;!e[s]._autoDestroy&&e[s].dispose("scoped")}for(this._.stabilizerTM&&clearTimeout(this._.stabilizerTM),this._.propagTM&&clearTimeout(this._.propagTM),Object.keys(this._._listening).forEach((function(e){return"$parent"!==e&&t._._scope[e].removeListener(t._._listening[e])}));this._._mixedList.length;)this._._mixed[0].removeListener(this._._mixedList.shift()),this._._mixed.shift().dispose("mixedTo");n()(this._.followers).map((function(e){return t.unBind.apply(t,n()(e))})),this._._parentList&&(this.parent._rmChild(this),this.parent.removeListener(this._._parentList),this.parent.dispose("isMyParent"),this._._parentList=null),this.dead=!0,delete C[this._id],this.emit("destroy",this)}}]),e}(w.default);E.persistenceTm=1,E.Store=null,E.scopeRef=function(t){this.path=t},E.scopes=C,E.isScopable=function(t){return E.isScope(t)||E.isScopeClass(t)||E.isStore(t)||E.isStoreClass(t)},E.isScope=function(t){return t instanceof E},E.isScopeClass=function(t){return E.isPrototypeOf(t)||t===E},e.default=E},function(t,e,s){t.exports=s(15)},function(t,e,s){"use strict";s.r(e),function(t){s.d(e,"Scope",(function(){return n})),s.d(e,"Store",(function(){return r})),s.d(e,"scopeRef",(function(){return o}));var i="undefined"!=typeof window?window:t,n=s(13).default,r=s(17).default,a=i.___rescope||{};function o(t,e){return t[e]=new n.scopeRef(t[e]),t}i.___rescope?(console.warn("ReScope is defined multiple times !! \nCheck you're packaging"),n=a.Scope,r=a.Store,o=a.scopeRef):(i.___rescope=a,n.Store=r),e.default={Scope:n,Store:r,scopeRef:o}}.call(this,s(16))},function(t,e){var s;s=function(){return this}();try{s=s||new Function("return this")()}catch(t){"object"==typeof window&&(s=window)}t.exports=s},function(t,e,s){"use strict";s.r(e);var i=s(3),n=s.n(i),r=s(1),a=s.n(r),o=s(7),h=s.n(o),u=s(6),c=s.n(u),l=s(8),p=s.n(l),f=s(4),_=s.n(f),d=s(5),v=s.n(d),y=s(9),b=s.n(y),g=s(10),m=s.n(g);function k(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),s.push.apply(s,i)}return s}function S(t){for(var e=1;e<arguments.length;e++){var s=null!=arguments[e]?arguments[e]:{};e%2?k(Object(s),!0).forEach((function(e){n()(t,e,s[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):k(Object(s)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(s,e))}))}return t}var w=s(0),O=s(13).default,j=s(2),T=j.keyWalknSet,x=j.keyWalknGet,C=s(12).default,E=s(18).default,R=s(11),P=Object.getPrototypeOf({}),M=function(t){function e(){var t,s,i;h()(this,e),i=p()(this,v()(e).call(this));var n=Array.prototype.slice.call(arguments),r=i.constructor,o=n[0]instanceof O?n.shift():r.scope?O.getScope(r.scope):w.string(n[0])?O.getScope(n.shift()):r.staticScope,u=!n[0]||w.array(n[0])||w.string(n[0])?{}:n.shift(),c=w.array(n[0])?n.shift():null,l=u.name||r.name,f=u.use||[],d=u.apply||null,y=r.state||r.initialState||r.defaultState;return i._uid=u._uid||R.generate(),i.__retains={all:0},i.__locks={all:0},i._onStabilize=[],i._autoDestroy=!!i._persistenceTm,i._persistenceTm=u.persistenceTm||r.persistenceTm||(u.autoDestroy||r.autoDestroy)&&5,i._cfg=u,u&&u.on&&i.on(u.on),i.name=l,o.stores?(i.scopeObj=o,i.scope=o.stores):(i.scopeObj=new O(o),i.scope=o.stores),i.$scope=i.scopeObj,i.$stores=i.scopeObj.stores,i.$actions=i.scopeObj.actions,i.$dispatch=i.scopeObj.dispatch.bind(i.scopeObj),i._rev=i.constructor._rev||0,i._revs={},i.stores={},i._require=[],i._sources=[l],w.array(r.use)?i._use=[].concat(a()(f),a()((r.use||[]).map((function(t){var e=t.match(/^(\!?)([^\:]*)(?:\:(.*))?$/);if(e[1]){var s=e[2].split(".");return i._require.push(e[3]||s[s.length-1]),t.substr(1)}return t})))):i._use=[].concat(a()(f),a()(r.use?Object.keys(r.use).map((function(t){var e=t.match(/^(\!?)(.*)$/);return e[1]&&i._require.push(r.use[t]),e[2]+(!0===r.use[t]?"":":"+r.use[t])})):[])),r.require&&(t=i._require).push.apply(t,a()(r.require)),u.require&&(s=i._require).push.apply(s,a()(u.require)),i._followers=[],i._changesSW=S({},y),y&&Object.keys(y).length&&(i._nextState=i._changesSW),i.state=y&&{},d&&(i.apply=d),c?c.push(i._afterConstructor.bind(_()(i))):setTimeout(i._afterConstructor.bind(_()(i))),i}return m()(e,t),c()(e,[{key:"_afterConstructor",value:function(){var t,e=this._cfg,s=this.constructor,i=(this.restore(void 0,!0),this.state),n=this.data;n?this.data=n:void 0!==s.data?this.data=S({},s.data):e.hasOwnProperty("data")&&(this.data=e.data),e.hasOwnProperty("state")&&void 0!==e.state&&(i=S({},i,{},e.state)),void 0===this.data?(i||this._use.length)&&(this._nextState=this._changesSW=S({},this._changesSW,{},i||{},{},this.$scope.map(this,this._use)),this.state={},this.shouldApply(this._nextState)&&void 0===this.data&&(this.data=this.apply(this.data,this._nextState,this._changesSW),t=!0,this.state=this._changesSW,this._nextState=this._changesSW=null)):(t=!0,this.state=S({},this._changesSW,{},i||{},{},this.$scope.map(this,this._use)),this._nextState=this._changesSW=null),void 0===this.data&&!t||this.__locks.all?(this._stable=!1,s.managed||this.state||this._use&&this._use.length||console.warn("ReScope store '",this.name,"' have no initial data, state or use. It can't stabilize...")):(this._stable=!0,this._rev++),!this._stable&&this.emit("unstable",this.state)}},{key:"shouldPropag",value:function(t){return!0}},{key:"shouldSerialize",value:function(){return!0}},{key:"hasDataChange",value:function(t){this.constructor;var e,s=this.data;return!(e=!s&&t||s!==t)&&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)&&(w.array(s.follow)?s.follow.reduce((function(t,s){return t||e&&e[s]}),!1):!s.follow||Object.keys(s.follow).reduce((function(i,n){return i||e&&w.fn(s.follow[n])&&s.follow[n].call(t,e[n])||s.follow[n]&&e[n]!==t.state[n]}),!1))}},{key:"apply",value:function(t,e,s){return e}},{key:"stabilize",value:function(t){t&&this.once("stable",t),this._stabilizer||(this._stable&&this.emit("unstable",this.state,this.data),this._stable=!1,this._stabilizer=E.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=w.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=new Array(s>1?s-1:0),n=1;n<s;n++)i[n-1]=arguments[n];(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,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];var a=(s=e[t]).call.apply(s,[this].concat(n));w.function(a)&&(a=a(this.nextState)),a&&this.setState(a)}}},{key:"push",value:function(t,e,s){if(s=!0===e?s: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)}return!1}this.data=t,this.wait(),this.release(s)}},{key:"pushState",value:function(t){if(this._stabilizer=null,t||this._changesSW||!this.data){var e,s=t||this._nextState||this.state;if(Object.keys(s).forEach((function(t){return void 0===s[t]&&delete s[t]})),e=this.apply(this.data,s,this._changesSW),this.state=s,this._nextState=null,this._changesSW=null,!t&&!this.hasDataChange(e)){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=e,this.wait(),this.release()}}},{key:"setState",value:function(t,e,s){var i,n,r=this._changesSW=this._changesSW||{},a=this._nextState=this._nextState||S({},this.state);for(n in t)(!this.state||r.hasOwnProperty(n)&&t[n]!==r[n]||t.hasOwnProperty(n)&&t[n]!==this.state[n])&&(i=!0,a[n]=r[n]=t[n]);if(this.shouldApply(a))return s?(this.pushState(),e&&e()):i?this.stabilize(e):e&&e(),this}},{key:"setStateSync",value:function(t){var e=this._changesSW=this._changesSW||{};for(var s in t)(!this.state||t.hasOwnProperty(s)&&t[s]!==this.state[s])&&(!0,this._revs[s]=t[s]&&t[s]._rev||!0,e[s]=t[s]);return this.shouldApply(S({},this.state||{},{},e))&&this.pushState(),this.data}},{key:"as",value:function(t){return{store:this,name:t}}},{key:"on",value:function(t){var s=this;!w.string(t)&&t?Object.keys(t).forEach((function(i){return b()(v()(e.prototype),"on",s).call(s,i,t[i])})):b()(v()(e.prototype),"on",this).apply(this,arguments)}},{key:"removeListener",value:function(t){var s=this;!w.string(t)&&t?Object.keys(t).forEach((function(i){return b()(v()(e.prototype),"removeListener",s).call(s,i,t[i])})):b()(v()(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._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,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.parentAlias||this.scopeObj._id,r=0,a=!s.norefs&&w.array(this._use)&&this._use.reduce((function(s,i){var n=t.$scope.parseRef(i),a=t.$stores[n.storeId];return a&&e.isStore(a)&&!a.scopeObj._.isLocalId&&(r++,s[n.alias]=n.path),s}),{}),o=this.state||{},h=this.shouldSerialize();if(!h)return T(i,n+"/"+this.name,{dataRefs:s.dataRefs,refs:a}),i;var u=Object.keys(o)||[],c=u.map((function(t){return o[t]})),l=0,p=s.dataRefs||{},f=!s.norefs&&this.data&&Object.keys(this.data).reduce((function(e,s){var i=c.indexOf(t.data[s]);return-1!=i&&(l++,e[s]=u[i]),e}),{}),_={dataRefs:s.dataRefs,state:o&&(s.norefs?S({},o):Object.keys(o).reduce((function(t,e){return!a[e]&&(t[e]=o[e]),t}),{})),data:(this.data&&this.data.__proto__===P?Object.keys(this.data).reduce((function(e,s){return f[s]||p[s]||(e[s]=t.data[s],l++),e}),{}):(w.bool(this.data)||w.number(this.data)||w.string(this.data))&&this.data)||void 0};return a&&r&&(_.refs=a),f&&l&&(_.inRefs=f),T(i,n+"/"+this.name,_),i}},{key:"restore",value:function(t,e){var s=this;(t=t&&x(t,this.scopeObj._id+"/"+this.name)||this.$scope.takeSnapshotByKey(this.scopeObj._id+"/"+this.name))&&t&&(this.isStable()||e||this.then((function(){return s.restore(t)})),this.state=S({},t.state),t.refs&&Object.keys(t.refs).forEach((function(e){s.$scope.restoreRefPath(t.refs[e]),s.state[e]=s.$scope.retrieve(t.refs[e])})),!0===t.inRefs?this.data=S({},this.state):(this.data=t.data,t.inRefs&&Object.keys(t.inRefs).forEach((function(e){s.data[e]=s.state[t.inRefs[e]]}))),t.dataRefs&&(this.data=this.data||{},Object.keys(t.dataRefs).forEach((function(e){s.$scope.restoreRefPath(t.dataRefs[e]),s.data[e]=s.$scope.retrieve(t.dataRefs[e])}))))}},{key:"bind",value:function(t,e){var s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=arguments.length>3?arguments[3]:void 0;if(this._followers.push([t,e,i]),s&&this.data&&this._stable){var r=i?this.retrieve(i):this.data;"function"!=typeof t?e?t.setState(n()({},e,r)):t.setState(r):t(r)}}},{key:"unBind",value:function(t,e,s){for(var i=this._followers,n=i&&i.length;i&&n--;)if(i[n][0]===t&&i[n][1]===e&&i[n][2]===s)return i.splice(n,1)}},{key:"then",value:function(t){var e=this;if(this._stable)return t(this.data);this.once("stable",(function(s){return t(e.data)}))}},{key:"wait",value:function(t){if("number"==typeof t)return this.__locks.all+=t;if(w.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=w.string(t)?t:null;return e&&(this.__locks[e]=this.__locks[e]||0,this.__locks[e]++),t&&w.fn(t.then)&&t.then(this.release.bind(this,null)),this}},{key:"release",value:function(t,e){this.constructor;var s=this,i=this._stable;if(w.fn(t)&&(e=t,t=null),t&&(0==this.__locks[t]&&console.error("Release more than locking !",t),this.__locks[t]=this.__locks[t]||0,this.__locks[t]--),t||0!=this.__locks.all||console.error("Release more than locking !"),!--this.__locks.all&&this.isComplete()){var r=this.shouldPropag(this.data);this._stable=!0,r&&this._rev++,r&&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]?n()({},t[1],e):e)})),!i&&this.emit("stable",this.data),r&&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("RS : Dispose more than retaining on store '"+this.name+"' : "+t);this.__retains[t]--}if(0==this.__retains.all)throw new Error("RS : Dispose more than retaining on store "+this.name);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.dead&&e.destroy()}),this._persistenceTm)):!this.__retains.all&&!this.dead&&this.destroy())}},{key:"destroy",value:function(){this._stabilizer&&(this._stabilizer=null,clearTimeout(this._stabilizer)),this.emit("destroy",this),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:"nextState",get:function(){return this._nextState||this.state}}]),e}(C);M.follow=void 0,M.require=void 0,M.staticScope=new O({},{id:"static"}),M.state=void 0,M.persistenceTm=!1,M.as=function(t){return{store:this,name:t}},M.map=function(t,e,s,i){var n=arguments.length>4&&void 0!==arguments[4]&&arguments[4],r=t._revs||{},o=t.stores||(t.stores={}),h={};return e=w.array(e)?a()(e):[e],s=s||M.staticScope,e=e.filter((function(e){var u,c,l,p,f,_;if(!e)return console.error("Not a mappable store item '"+e+"' in "+i+" !!"),!1;if(e.store&&e.name?(l=c=e.name,f=e.store):w.fn(e)?(c=l=e.name||e.defaultName,f=e):(c=(_=e.match(/([^\.\:]+)((?:\.[^\.\:]+)*)(?:\:([^\.\:]+))?/))[1],p=_[2]&&_[2].substr(1),f=s.stores[_[1]],l=_[3]||p&&p.match(/([^\.]*)$/)[0]||_[1]),!f){var d=[];for(var v in s.stores)d.push(v);return console.error("Not a mappable store item '"+c+"/"+l+"' in "+(t.name||t)+" !!",f,_,s.stores,d),!1}if(O.isScopeClass(f)&&s._mount(c),O.isScope(f))f=s._mount(e);else if(r[c])return!1;return w.fn(f)?(s._mount(c),s.stores[c].bind(t,l,n,p)):f.bind(t,l,n,p),s.stores[c]._sources&&(u=t._sources).push.apply(u,a()(s.stores[c]._sources)),r[l]=r[l]||!0,!o[c]&&(o[c]=s.stores[c]),s.stores[c].hasOwnProperty("data")&&(h[c]=s.data[c]),!0})),t.once("destroy",(function(){e.map((function(e){var i,n,r,a;e.store&&e.name?(n=i=e.name,a=e.store):w.fn(e)?(i=n=e.name||e.defaultName,a=s.stores[i]):(i=(e=e.match(/([^\.\:]+)((?:\.[^\.\:]+)*)(?:\:([^\.\:]+))?/))[1],r=e[2]&&e[2].substr(1),a=s.stores[e[1]],n=e[3]||r&&r.match(/([^\.]*)$/)[0]||e[1]),a&&!w.fn(a)&&a.unBind(t,n,r)}))})),h},M.isStore=O.isStore=function(t){return t instanceof M},M.isStoreClass=O.isStoreClass=function(t){return M.isPrototypeOf(t)||t===M},e.default=M},function(t,e,s){"use strict";s.r(e),function(t){var s,i,n=[],r=0,a=0,o=0,h={lastError:null,dispatch:function(t){h.disable(),s&&s[0].handleError?s[0].handleError(t,s):s&&console.error("ReScope : An apply task has failed !!",s[1]," on ",s[0].name||s[0].constructor.name,"\n",t),i=!1,s=null,u()},enable:"undefined"!=typeof window?function(){window.addEventListener("error",h.dispatch)}:function(){t.on("uncaughtException",h.dispatch)},disable:"undefined"!=typeof window?function(){window.removeEventListener("error",h.dispatch)}:function(){t.removeListener("uncaughtException",h.dispatch)}};function u(){i||function(){Date.now();i=!0,h.enable();for(;o;){for(;!n[r]||!n[r].length;)r++;o--,s=n[r].shift();try{!s[0].dead&&s[0][s[1]](s[2])}catch(t){return h.dispatch(t)}}s=void 0,h.disable(),i=!1,o&&setTimeout(u)}()}e.default={pushTask:function(t,e,s){var i=t._sources&&t._sources.length||1,h=n[i]=n[i]||[];return a=Math.max(a,i),r=Math.min(r,i),o++,h.push([t,e,s]),setTimeout(u,0),h.length}}}.call(this,s(19))},function(t,e){var s,i,n=t.exports={};function r(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function o(t){if(s===setTimeout)return setTimeout(t,0);if((s===r||!s)&&setTimeout)return s=setTimeout,setTimeout(t,0);try{return s(t,0)}catch(e){try{return s.call(null,t,0)}catch(e){return s.call(this,t,0)}}}!function(){try{s="function"==typeof setTimeout?setTimeout:r}catch(t){s=r}try{i="function"==typeof clearTimeout?clearTimeout:a}catch(t){i=a}}();var h,u=[],c=!1,l=-1;function p(){c&&h&&(c=!1,h.length?u=h.concat(u):l=-1,u.length&&f())}function f(){if(!c){var t=o(p);c=!0;for(var e=u.length;e;){for(h=u,u=[];++l<e;)h&&h[l].run();l=-1,e=u.length}h=null,c=!1,function(t){if(i===clearTimeout)return clearTimeout(t);if((i===a||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(t);try{i(t)}catch(e){try{return i.call(null,t)}catch(e){return i.call(this,t)}}}(t)}}function _(t,e){this.fun=t,this.array=e}function d(){}n.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var s=1;s<arguments.length;s++)e[s-1]=arguments[s];u.push(new _(t,e)),1!==u.length||c||o(f)},_.prototype.run=function(){this.fun.apply(null,this.array)},n.title="browser",n.browser=!0,n.env={},n.argv=[],n.version="",n.versions={},n.on=d,n.addListener=d,n.once=d,n.off=d,n.removeListener=d,n.removeAllListeners=d,n.emit=d,n.prependListener=d,n.prependOnceListener=d,n.listeners=function(t){return[]},n.binding=function(t){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(t){throw new Error("process.chdir is not supported")},n.umask=function(){return 0}}]);
//# sourceMappingURL=reScope.js.map