@simplux/core
Version:
The core package of simplux. Contains everything to manage your application state in a simple way.
3 lines (2 loc) • 6.2 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("redux"),require("immer")):"function"==typeof define&&define.amd?define(["exports","redux","immer"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@simplux/core"]={},t.redux,t.immer)}(this,function(t,n,y){"use strict";var b=function(){return(b=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},x=function(t,e){for(var n=0,r=e.length,i=t.length;n<r;n++,i++)t[i]=e[n];return t};var d="[SIMPLUX_SELECTOR]";function M(t,f){var l=t,p=l.$simplux;return Object.keys(f).reduce(function(t,e){var r,i,u,n,o=f[e],a=(r=o,function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return(!i||i.length!==n.length||!i.every(function(t,e){return t===n[e]}))&&(u=r.apply(void 0,n),i=n),u}),c=(p.lastSelectorId||0)+1,o=(p.lastSelectorId=c,n=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=null==(n=p.selectorMocks)?void 0:n[c];return n?n.apply(void 0,t):a.apply(void 0,x([p.getState()],t))},(o={})[s=e]=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return n.apply(void 0,t)},o[s]),s=t[e]=o;return s.withState=a,s.selectorId=c,s.selectorName=e,s.owningModule=l,s[d]="",t},{})}var p,r,i,u,v=0,O=(r=e,u={},{rootReducer:function(t,e){return void 0===t&&(t={}),i?i(t,e):t},getState:function(){return r().getState()},dispatch:function(t){return r().dispatch(t)},subscribe:function(t){return r().subscribe(t)},setReducer:function(t,e){u[t]=e,i=n.combineReducers(u),r().dispatch({type:"@simplux/setReducer/"+t})},getReducer:function(t){return u[t]}});function e(){return p}function o(t,e){var n=p;if(t){var r=v++;if(p=function(r,t,e,i){var n=!0,u=[];Promise.resolve().then(function(){n=!1;var t=u;t.splice(0,t.length)}).catch(function(){});return b(b({id:e,subscribers:i,actionsToDispatchOnStoreChange:u},r),{dispatch:function(t){return n&&u.push(t),r.dispatch(t)},getState:function(){return t(r.getState())},subscribe:function(t){var e=r.subscribe(t),n={handler:t,unsubscribe:e};return i.push(n),function(){e();var t=i.indexOf(n);0<=t&&i.splice(t,1)}}})}(t,e,r,[]),n){for(var i=p,u=0,o=n.subscribers;u<o.length;u++){var a=o[u];a.unsubscribe(),i.subscribe(a.handler)}for(var c=p,t=(t=n).actionsToDispatchOnStoreChange,s=0,f=t;s<f.length;s++){var l=f[s];c.dispatch(l)}}}else p=void 0;return function(){p=n}}var I="[SIMPLUX_MODULE]";function a(t,e){var n,r=t.getState,i=t.dispatch,u=t.subscribe,t=t.setReducer,o={name:e.name,mutations:{},dispatch:i,getReducer:function(){return O.getReducer(e.name)},getState:a};function a(){return o.mockStateValue||r()[e.name]}var c=e.initialState,s=[],f={shouldSkipInitialInvocation:!1};p=e.name,d=e.initialState,v=o.mutations,m="@simplux/"+p+"/mutation/";function l(t,e){g+=1;try{t=t||h(t,{type:"@simplux/immer/init"}),t=1===g?y.produce(t,function(t){return h(t,e)}):h(t,e)}finally{--g}return t}h=function(t,e){var n,r;return void 0===t&&(t=d),e.type.startsWith(m)?(r=e.mutationName,n=e.args,(null==(r=v[r])?void 0:r.apply(void 0,x([t],n)))||t):e.type==="@simplux/"+p+"/setState"?e.state:t},g=0;t(e.name,l),(t={state:void 0,setState:function(t){i({type:"@simplux/"+e.name+"/setState",state:t})},subscribeToStateChanges:function(e,t){void 0===t&&(t={});t=b(b({},f),t);s.push(e),1===s.length&&(c=a(),n=u(function(){var t=a();if(t!==c){var e=c;c=t;for(var n=0,r=s;n<r.length;n++)(0,r[n])(t,e)}})),t.shouldSkipInitialInvocation||e(c,c);return{unsubscribe:function(){var t=s.indexOf(e);0<=t&&s.splice(t,1),0===s.length&&n&&(n(),n=void 0)},handler:e}},$simplux:o})[I]="";var p,d,v,m,h,g,S=M(t,{state:function(t){return t}});return t.state=S.state,t}var c="[SIMPLUX_EFFECT]",s=[];function f(n){return Object.keys(n).reduce(function(t,e){var r,i;return b(b({},t),((t={})[e]=(r=n[e],(i=function(t,n){var e;return(e={})[t]=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return n.apply(void 0,t)},e[t]}(e=e,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=s.find(function(t){return t.effectToMock===i});return n?n.mockFn.apply(n,t):r.apply(void 0,t)})).effectName=e,i[c]="",i),t))},{})}var l="[SIMPLUX_MUTATION]";function m(){return O.rootReducer}function h(t,e){return o(t,e)}h(n.createStore(m()),function(t){return t}),t.SIMPLUX_EFFECT=c,t.SIMPLUX_MODULE=I,t.SIMPLUX_MUTATION=l,t.SIMPLUX_SELECTOR=d,t._getEffectMocks=function(){return s},t._getStoreProxy=e,t._isSimpluxEffect=function(t){return""===(null==t?void 0:t[c])},t._isSimpluxModule=function(t){return""===(null==t?void 0:t[I])},t._isSimpluxMutation=function(t){return""===(null==t?void 0:t[l])},t._isSimpluxSelector=function(t){return""===(null==t?void 0:t[d])},t.createEffect=function(t){var e;return f(((e={})["n/a"]=t,e))["n/a"]},t.createEffects=f,t.createMutations=function(t,e){var a=t,c=(t=a.$simplux).name,s=t.dispatch,f=t.getReducer,t=t.mutations;return Object.assign(t,e),Object.keys(e).reduce(function(t,r){var i="@simplux/"+c+"/mutation/"+r;function u(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=0!==(n=t).length&&function(t){if("undefined"!=typeof Event&&t instanceof Event)return 1;return!!(null!=t&&e(t,"target")&&e(t,"currentTarget")&&e(t,"defaultPrevented"));function e(t,e){return Object.prototype.hasOwnProperty.call(t,e)}}(n[0])?n.slice(1):n;return{type:i,mutationName:r,args:n}}n=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=null==(n=a.$simplux.mutationMocks)?void 0:n[r];return n?n.apply(void 0,t):(s(u.apply(void 0,t)),a.state())},(e={})[o=r]=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return n.apply(void 0,t)};var n,e=e[o],o=t[r]=e;return o.withState=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return f()(t,u.apply(void 0,e))},o.asAction=u,o.type=i,o.mutationName=r,o.owningModule=a,o[l]="",t},{})},t.createSelectors=M,t.createSimpluxModule=function(t,e){return a(O,"string"==typeof t?{name:t,initialState:e}:t)},t.getSimpluxReducer=m,t.setReduxStoreForSimplux=h,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=simplux.core.production.min.js.map