Comparing version 0.2.6 to 0.2.7
import { Dispatch, Select } from './store'; | ||
export interface ActionOptions<R = any, A extends any[] = any> { | ||
} | ||
/** | ||
@@ -28,2 +30,4 @@ * An `Action` is a dispatchable function. It could do anything synchronously or | ||
(...args: A): Action<R, A>; | ||
options: ActionOptions<R, A>; | ||
config(options: ActionOptions<R, A>): this; | ||
} | ||
@@ -30,0 +34,0 @@ /** |
@@ -74,29 +74,2 @@ 'use strict'; | ||
/* | ||
* @since 2020-11-03 13:23:14 | ||
* @author acrazing <joking.young@gmail.com> | ||
*/ | ||
/** | ||
* `action` is the recommended way to create an `ActionFactory` to create | ||
* actions which depends on some dynamic parameters. For example, fetch the | ||
* specified user's profile with `id`. | ||
* | ||
* @param actor The function to be called with internal parameters and dynamicly | ||
* injected parameters by calling the `ActionFactory`. | ||
* @param type An optional string to identify the type of the created action. | ||
* | ||
* @stable | ||
*/ | ||
function action(actor, type) { | ||
return Object.assign(function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return ({ object: 'action', type: type, args: args, actor: actor }); | ||
}, { | ||
type: type, | ||
}); | ||
} | ||
/* | ||
* @since 2020-11-04 11:12:36 | ||
@@ -187,4 +160,36 @@ * @author acrazing <joking.young@gmail.com> | ||
var isArray = Array.isArray; | ||
function config(options) { | ||
return Object.assign(this, { options: options }); | ||
} | ||
/* | ||
* @since 2020-11-03 13:23:14 | ||
* @author acrazing <joking.young@gmail.com> | ||
*/ | ||
/** | ||
* `action` is the recommended way to create an `ActionFactory` to create | ||
* actions which depends on some dynamic parameters. For example, fetch the | ||
* specified user's profile with `id`. | ||
* | ||
* @param actor The function to be called with internal parameters and dynamicly | ||
* injected parameters by calling the `ActionFactory`. | ||
* @param type An optional string to identify the type of the created action. | ||
* | ||
* @stable | ||
*/ | ||
function action(actor, type) { | ||
return Object.assign(function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return ({ object: 'action', type: type, args: args, actor: actor }); | ||
}, { | ||
type: type, | ||
options: {}, | ||
config: config, | ||
}); | ||
} | ||
/* | ||
* @since 2020-11-05 15:24:04 | ||
@@ -399,3 +404,3 @@ * @author acrazing <joking.young@gmail.com> | ||
React.useEffect(function () { | ||
state.store !== state.store && setState({ store: store }); | ||
state.store !== store && setState({ store: store }); | ||
}, [store]); | ||
@@ -653,3 +658,3 @@ return React__default['default'].createElement(__Context.Provider, { value: state }, children); | ||
*/ | ||
var VERSION = '0.2.6'; | ||
var VERSION = '0.2.7'; | ||
@@ -656,0 +661,0 @@ exports.Box = Box; |
@@ -66,29 +66,2 @@ import { __spread, __assign, __values, __read } from 'tslib'; | ||
/* | ||
* @since 2020-11-03 13:23:14 | ||
* @author acrazing <joking.young@gmail.com> | ||
*/ | ||
/** | ||
* `action` is the recommended way to create an `ActionFactory` to create | ||
* actions which depends on some dynamic parameters. For example, fetch the | ||
* specified user's profile with `id`. | ||
* | ||
* @param actor The function to be called with internal parameters and dynamicly | ||
* injected parameters by calling the `ActionFactory`. | ||
* @param type An optional string to identify the type of the created action. | ||
* | ||
* @stable | ||
*/ | ||
function action(actor, type) { | ||
return Object.assign(function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return ({ object: 'action', type: type, args: args, actor: actor }); | ||
}, { | ||
type: type, | ||
}); | ||
} | ||
/* | ||
* @since 2020-11-04 11:12:36 | ||
@@ -179,4 +152,36 @@ * @author acrazing <joking.young@gmail.com> | ||
var isArray = Array.isArray; | ||
function config(options) { | ||
return Object.assign(this, { options: options }); | ||
} | ||
/* | ||
* @since 2020-11-03 13:23:14 | ||
* @author acrazing <joking.young@gmail.com> | ||
*/ | ||
/** | ||
* `action` is the recommended way to create an `ActionFactory` to create | ||
* actions which depends on some dynamic parameters. For example, fetch the | ||
* specified user's profile with `id`. | ||
* | ||
* @param actor The function to be called with internal parameters and dynamicly | ||
* injected parameters by calling the `ActionFactory`. | ||
* @param type An optional string to identify the type of the created action. | ||
* | ||
* @stable | ||
*/ | ||
function action(actor, type) { | ||
return Object.assign(function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return ({ object: 'action', type: type, args: args, actor: actor }); | ||
}, { | ||
type: type, | ||
options: {}, | ||
config: config, | ||
}); | ||
} | ||
/* | ||
* @since 2020-11-05 15:24:04 | ||
@@ -391,3 +396,3 @@ * @author acrazing <joking.young@gmail.com> | ||
useEffect(function () { | ||
state.store !== state.store && setState({ store: store }); | ||
state.store !== store && setState({ store: store }); | ||
}, [store]); | ||
@@ -645,5 +650,5 @@ return React.createElement(__Context.Provider, { value: state }, children); | ||
*/ | ||
var VERSION = '0.2.6'; | ||
var VERSION = '0.2.7'; | ||
export { Box, Consumer, Provider, VERSION, action, arrayEqual, createStore, hoistMethod, identity, isAmosObject, selector, shallowEqual, signal, useDispatch, useSelector, useStore }; | ||
//# sourceMappingURL=amos.es.js.map |
@@ -1,2 +0,2 @@ | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self).Amos={},r.React)}(this,(function(r,e){"use strict";function t(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var n=t(e),o=function(){function r(r,e,t){this.key=r,this.initialState=e,this.preload=t,this.listeners={}}return r.prototype.subscribe=function(r,e){this.listeners["string"==typeof r?r:r.type]=e},r.prototype.mutation=function(r,e){var t=this;return function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];return{object:"mutation",type:e,box:t,args:n,result:n[0],mutator:r}}},r}();var u=function(){return(u=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++)for(var o in e=arguments[t])Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o]);return r}).apply(this,arguments)};function i(r){var e="function"==typeof Symbol&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&"number"==typeof r.length)return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(r,e){var t="function"==typeof Symbol&&r[Symbol.iterator];if(!t)return r;var n,o,u=t.call(r),i=[];try{for(;(void 0===e||e-- >0)&&!(n=u.next()).done;)i.push(n.value)}catch(r){o={error:r}}finally{try{n&&!n.done&&(t=u.return)&&t.call(u)}finally{if(o)throw o.error}}return i}function a(){for(var r=[],e=0;e<arguments.length;e++)r=r.concat(s(arguments[e]));return r}var c=function(r){return r};var f="function"==typeof Symbol?Symbol("AMOS_OBJECT"):"Symbol(AMOS_OBJECT)";function l(r,e){return e.hasOwnProperty(f)||Object.defineProperty(e,f,{value:r}),e}function p(r,e){return!!e&&e[f]===r}function y(r,e){return r===e}function d(r,e){if(r.length!==e.length)return!1;for(var t=0;t<r.length;t++)if(r[t]!==e[t])return!1;return!0}var v=Array.isArray;var h=e.createContext(null);function b(){var r=e.useContext(h);if(!r)throw new Error("[Amos] you are using hooks without <Provider />.");return r.store}var g={selectors:[],deps:[],snapshots:[],results:[]};function O(r,e){for(var t in r)if(r.hasOwnProperty(t)&&e.hasOwnProperty(t))return!0;return!1}function m(r,e,t,n){var o,u;if(!(null===(u=r.factory)||void 0===u?void 0:u.deps)||!t[n])return!0;var i=(o=r.factory).deps.apply(o,a([e.select],r.args)),s=d(t[n]||[],i);return t[n]=i,!s}function w(r,e,t){return r.factory?r.factory.compare(e,t):y(e,t)}function j(r,e,t,n,o){var u,i;if(!(r&&"function"==typeof r&&t&&r.args&&e.args))return!0;if(!(r===e||e.factory&&e.factory===r.factory))return!0;if(void 0===(null===(i=e.factory)||void 0===i?void 0:i.deps))return!d(r.args,e.args);var s=(u=e.factory).deps.apply(u,a([n.select],e.args));return!d(o||[],s)&&s}r.Box=o,r.Consumer=function(r){var e=r.children;return n.default.createElement(h.Consumer,null,(function(r){if(!r)throw new Error("[Amos] <Consumer /> should use inside <Provider />.");return e(r.store)}))},r.Provider=function(r){var t=r.store,o=r.children,u=s(e.useState({store:t}),2),i=u[0],a=u[1];return e.useEffect((function(){i.store!=i.store&&a({store:t})}),[t]),n.default.createElement(h.Provider,{value:i},o)},r.VERSION="0.2.6",r.action=function(r,e){return Object.assign((function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return{object:"action",type:e,args:t,actor:r}}),{type:e})},r.arrayEqual=d,r.createStore=function(r){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];var n,o={},s=[],c=[],f=function(e){if(!o.hasOwnProperty(e.key)){var t=e.initialState;(null==r?void 0:r.hasOwnProperty(e.key))&&(t=e.preload(r[e.key],t)),o[e.key]=t,s.push(e)}},p=0,y={},d=function(r,e){(e!==o[r]||y.hasOwnProperty(r))&&(y[r]=e,o[r]=e)},h=function(r){var e,t;switch(r.object){case"action":return r.actor.apply(r,a([b.dispatch,b.select],r.args));case"mutation":return f(r.box),d(r.box.key,r.mutator.apply(r,a([o[r.box.key]],r.args))),r.result;case"signal":try{for(var n=i(s),u=n.next();!u.done;u=n.next()){var c=u.value,l=c.listeners[r.type];l&&d(c.key,l(o[c.key],r.data))}}catch(r){e={error:r}}finally{try{u&&!u.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}return r.data}},b={snapshot:function(){return o},subscribe:function(r){return c.push(r),function(){var e=c.indexOf(r);e>-1&&c.splice(e,1)}},dispatch:l("store.dispatch",(function(r){1==++p&&(y={});try{return v(r)?r.map(h):h(r)}finally{if(0==--p&&Object.keys(y).length>0){var e=u({},y);c.forEach((function(r){return r(e)}))}}})),select:l("store.select",(function(r,e){if("function"!=typeof r)return f(r),n&&(n[r.key]=o[r.key]),o[r.key];if(!e)return r(b.select);if(n)throw new Error("[Amos] recursive snapshot collection is not supported.");n=e;try{return r(b.select)}finally{n=void 0}}))};return b=e.reduce((function(r,e){return e(r)}),b),"object"==typeof process&&"development"===process.env.NODE_ENV&&Object.freeze(b),b},r.hoistMethod=function(r,e){var t,n=function(t){e.hasOwnProperty(t)||Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))};return Object.getOwnPropertyNames(r).forEach(n),null===(t=Object.getOwnPropertySymbols)||void 0===t||t.call(Object,r).forEach(n),e},r.identity=c,r.isAmosObject=p,r.selector=function(r,e,t,n){void 0===t&&(t=y);var o=Object.assign((function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e[0];if(p("store.select",n))return r.apply(void 0,a(e));var u=function(t){return r.apply(void 0,a([t],e))};return u.factory=o,u.args=e,u}),{deps:e,compare:t,type:n});return o},r.shallowEqual=function(r,e){if(r===e)return!0;var t=Object.keys(r);if(t.length!==Object.keys(e).length)return!1;for(var n=0;n<t.length;n++)if(!e.hasOwnProperty(t[n])||r[t[n]]!==e[t[n]])return!1;return!0},r.signal=function(r,e){return void 0===e&&(e=c),Object.assign((function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return{object:"signal",type:r,data:e.apply(void 0,a(t))}}),{type:r})},r.useDispatch=function(){return b().dispatch},r.useSelector=function(){for(var r,t,n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];var u,i=s(e.useReducer((function(r){return r+1}),0),2),a=i[1],c=b(),f=e.useRef(g),l=e.useRef();if((null===(r=l.current)||void 0===r?void 0:r.store)!==c&&(f.current=g,null===(t=l.current)||void 0===t||t.disposer(),l.current={store:c,updated:!1,error:void 0,disposer:c.subscribe((function(r){var e,t=0,n=f.current,o=n.selectors,u=n.snapshots,i=n.results,s=n.deps,p=o.length;try{for(;t<p;t++){var y=o[t],d=u[t];if("function"==typeof y){if((!d||O(d,r))&&m(y,c,s,t)){var v={},h=c.select(y,v);(e=l.current).updated||(e.updated=!w(y,i[t],h)),u[t]=v,i[t]=h}}else if(r.hasOwnProperty(y.key)){var b=c.select(y);l.current.updated=b!==i[t],i[t]=b}}l.current.updated&&a()}catch(r){u.length=i.length=t,l.current.error="object"==typeof r&&r?Object.assign(r,{message:"[Amos] selector throws error: "+r.message}):new Error("[Amos] selector throws falsy error: "+r),a()}}))}),e.useEffect((function(){return function(){var r;return null===(r=l.current)||void 0===r?void 0:r.disposer()}}),[]),l.current.error){var p=l.current.error;throw l.current.error=void 0,p}if(l.current.updated)l.current.updated=!1,u=f.current.results;else{f.current===g&&(f.current={selectors:[],deps:[],snapshots:[],results:[]});for(var y=f.current,d=y.selectors,v=y.deps,h=y.snapshots,P=y.results,E=0;E<n.length;E++){var k=d[E],S=n[E];if("object"==typeof S)P[E]=c.select(S),d[E]=S;else{var x=j(k,S,h[E],c,v[E]);if(x){h[E]=void 0;var A={};P[E]=c.select(S,A),v[E]=!0===x?void 0:x,h[E]=A,d[E]=S}}}P.length=n.length,u=P}return e.useDebugValue(u,(function(r){return r.reduce((function(r,e,t){var o,u,i,s=n[t],a="function"==typeof s?null!==(i=null!==(o=s.type)&&void 0!==o?o:null===(u=s.factory)||void 0===u?void 0:u.type)&&void 0!==i?i:s.name:s.key;return a||(a="anonymous"),r.hasOwnProperty(a)&&(a=a+"_"+t),r[a]=e,r}),{})})),u},r.useStore=b,Object.defineProperty(r,"__esModule",{value:!0})})); | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self).Amos={},r.React)}(this,(function(r,e){"use strict";function t(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var n=t(e),o=function(){function r(r,e,t){this.key=r,this.initialState=e,this.preload=t,this.listeners={}}return r.prototype.subscribe=function(r,e){this.listeners["string"==typeof r?r:r.type]=e},r.prototype.mutation=function(r,e){var t=this;return function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];return{object:"mutation",type:e,box:t,args:n,result:n[0],mutator:r}}},r}(),u=function(r){return r};var i="function"==typeof Symbol?Symbol("AMOS_OBJECT"):"Symbol(AMOS_OBJECT)";function s(r,e){return e.hasOwnProperty(i)||Object.defineProperty(e,i,{value:r}),e}function a(r,e){return!!e&&e[i]===r}function c(r,e){return r===e}function f(r,e){if(r.length!==e.length)return!1;for(var t=0;t<r.length;t++)if(r[t]!==e[t])return!1;return!0}var l=Array.isArray;function p(r){return Object.assign(this,{options:r})}var y=function(){return(y=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++)for(var o in e=arguments[t])Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o]);return r}).apply(this,arguments)};function d(r){var e="function"==typeof Symbol&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&"number"==typeof r.length)return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function v(r,e){var t="function"==typeof Symbol&&r[Symbol.iterator];if(!t)return r;var n,o,u=t.call(r),i=[];try{for(;(void 0===e||e-- >0)&&!(n=u.next()).done;)i.push(n.value)}catch(r){o={error:r}}finally{try{n&&!n.done&&(t=u.return)&&t.call(u)}finally{if(o)throw o.error}}return i}function h(){for(var r=[],e=0;e<arguments.length;e++)r=r.concat(v(arguments[e]));return r}var g=e.createContext(null);function b(){var r=e.useContext(g);if(!r)throw new Error("[Amos] you are using hooks without <Provider />.");return r.store}var O={selectors:[],deps:[],snapshots:[],results:[]};function m(r,e){for(var t in r)if(r.hasOwnProperty(t)&&e.hasOwnProperty(t))return!0;return!1}function w(r,e,t,n){var o,u;if(!(null===(u=r.factory)||void 0===u?void 0:u.deps)||!t[n])return!0;var i=(o=r.factory).deps.apply(o,h([e.select],r.args)),s=f(t[n]||[],i);return t[n]=i,!s}function j(r,e,t){return r.factory?r.factory.compare(e,t):c(e,t)}function P(r,e,t,n,o){var u,i;if(!(r&&"function"==typeof r&&t&&r.args&&e.args))return!0;if(!(r===e||e.factory&&e.factory===r.factory))return!0;if(void 0===(null===(i=e.factory)||void 0===i?void 0:i.deps))return!f(r.args,e.args);var s=(u=e.factory).deps.apply(u,h([n.select],e.args));return!f(o||[],s)&&s}r.Box=o,r.Consumer=function(r){var e=r.children;return n.default.createElement(g.Consumer,null,(function(r){if(!r)throw new Error("[Amos] <Consumer /> should use inside <Provider />.");return e(r.store)}))},r.Provider=function(r){var t=r.store,o=r.children,u=v(e.useState({store:t}),2),i=u[0],s=u[1];return e.useEffect((function(){i.store!==t&&s({store:t})}),[t]),n.default.createElement(g.Provider,{value:i},o)},r.VERSION="0.2.7",r.action=function(r,e){return Object.assign((function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return{object:"action",type:e,args:t,actor:r}}),{type:e,options:{},config:p})},r.arrayEqual=f,r.createStore=function(r){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];var n,o={},u=[],i=[],a=function(e){if(!o.hasOwnProperty(e.key)){var t=e.initialState;(null==r?void 0:r.hasOwnProperty(e.key))&&(t=e.preload(r[e.key],t)),o[e.key]=t,u.push(e)}},c=0,f={},p=function(r,e){(e!==o[r]||f.hasOwnProperty(r))&&(f[r]=e,o[r]=e)},v=function(r){var e,t;switch(r.object){case"action":return r.actor.apply(r,h([g.dispatch,g.select],r.args));case"mutation":return a(r.box),p(r.box.key,r.mutator.apply(r,h([o[r.box.key]],r.args))),r.result;case"signal":try{for(var n=d(u),i=n.next();!i.done;i=n.next()){var s=i.value,c=s.listeners[r.type];c&&p(s.key,c(o[s.key],r.data))}}catch(r){e={error:r}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}return r.data}},g={snapshot:function(){return o},subscribe:function(r){return i.push(r),function(){var e=i.indexOf(r);e>-1&&i.splice(e,1)}},dispatch:s("store.dispatch",(function(r){1==++c&&(f={});try{return l(r)?r.map(v):v(r)}finally{if(0==--c&&Object.keys(f).length>0){var e=y({},f);i.forEach((function(r){return r(e)}))}}})),select:s("store.select",(function(r,e){if("function"!=typeof r)return a(r),n&&(n[r.key]=o[r.key]),o[r.key];if(!e)return r(g.select);if(n)throw new Error("[Amos] recursive snapshot collection is not supported.");n=e;try{return r(g.select)}finally{n=void 0}}))};return g=e.reduce((function(r,e){return e(r)}),g),"object"==typeof process&&"development"===process.env.NODE_ENV&&Object.freeze(g),g},r.hoistMethod=function(r,e){var t,n=function(t){e.hasOwnProperty(t)||Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))};return Object.getOwnPropertyNames(r).forEach(n),null===(t=Object.getOwnPropertySymbols)||void 0===t||t.call(Object,r).forEach(n),e},r.identity=u,r.isAmosObject=a,r.selector=function(r,e,t,n){void 0===t&&(t=c);var o=Object.assign((function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e[0];if(a("store.select",n))return r.apply(void 0,h(e));var u=function(t){return r.apply(void 0,h([t],e))};return u.factory=o,u.args=e,u}),{deps:e,compare:t,type:n});return o},r.shallowEqual=function(r,e){if(r===e)return!0;var t=Object.keys(r);if(t.length!==Object.keys(e).length)return!1;for(var n=0;n<t.length;n++)if(!e.hasOwnProperty(t[n])||r[t[n]]!==e[t[n]])return!1;return!0},r.signal=function(r,e){return void 0===e&&(e=u),Object.assign((function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return{object:"signal",type:r,data:e.apply(void 0,h(t))}}),{type:r})},r.useDispatch=function(){return b().dispatch},r.useSelector=function(){for(var r,t,n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];var u,i=v(e.useReducer((function(r){return r+1}),0),2),s=i[1],a=b(),c=e.useRef(O),f=e.useRef();if((null===(r=f.current)||void 0===r?void 0:r.store)!==a&&(c.current=O,null===(t=f.current)||void 0===t||t.disposer(),f.current={store:a,updated:!1,error:void 0,disposer:a.subscribe((function(r){var e,t=0,n=c.current,o=n.selectors,u=n.snapshots,i=n.results,l=n.deps,p=o.length;try{for(;t<p;t++){var y=o[t],d=u[t];if("function"==typeof y){if((!d||m(d,r))&&w(y,a,l,t)){var v={},h=a.select(y,v);(e=f.current).updated||(e.updated=!j(y,i[t],h)),u[t]=v,i[t]=h}}else if(r.hasOwnProperty(y.key)){var g=a.select(y);f.current.updated=g!==i[t],i[t]=g}}f.current.updated&&s()}catch(r){u.length=i.length=t,f.current.error="object"==typeof r&&r?Object.assign(r,{message:"[Amos] selector throws error: "+r.message}):new Error("[Amos] selector throws falsy error: "+r),s()}}))}),e.useEffect((function(){return function(){var r;return null===(r=f.current)||void 0===r?void 0:r.disposer()}}),[]),f.current.error){var l=f.current.error;throw f.current.error=void 0,l}if(f.current.updated)f.current.updated=!1,u=c.current.results;else{c.current===O&&(c.current={selectors:[],deps:[],snapshots:[],results:[]});for(var p=c.current,y=p.selectors,d=p.deps,h=p.snapshots,g=p.results,E=0;E<n.length;E++){var k=y[E],S=n[E];if("object"==typeof S)g[E]=a.select(S),y[E]=S;else{var x=P(k,S,h[E],a,d[E]);if(x){h[E]=void 0;var A={};g[E]=a.select(S,A),d[E]=!0===x?void 0:x,h[E]=A,y[E]=S}}}g.length=n.length,u=g}return e.useDebugValue(u,(function(r){return r.reduce((function(r,e,t){var o,u,i,s=n[t],a="function"==typeof s?null!==(i=null!==(o=s.type)&&void 0!==o?o:null===(u=s.factory)||void 0===u?void 0:u.type)&&void 0!==i?i:s.name:s.key;return a||(a="anonymous"),r.hasOwnProperty(a)&&(a=a+"_"+t),r[a]=e,r}),{})})),u},r.useStore=b,Object.defineProperty(r,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=amos.umd.js.map |
@@ -39,1 +39,2 @@ /** | ||
export declare function arrayEqual<T extends ArrayLike<any>>(a: T, b: T): boolean; | ||
export declare function config<T extends object>(this: T, options: object): T; |
{ | ||
"name": "amos", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "A decentralized state manager for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -201,3 +201,3 @@ # amos | ||
unique in your project's boxes, it is used internally, so it can be a string | ||
in any format, the only thing you should care about it is **KEEP IT UNIQUE**. | ||
in any format, the only thing you should care about is **KEEP IT UNIQUE**. | ||
@@ -236,3 +236,3 @@ The second one is the initial state of the box, please note it is **NOT** a | ||
A `Mutation` is an object which while mutate a `box`'s state when it is dispatched. | ||
A `Mutation` is an object which will mutate a `box`'s state when it is dispatched. | ||
@@ -258,3 +258,3 @@ You can create a `MutationFactory` by calling [`mutation()`](#mutation): | ||
- the `mutator` will be called with two parameter which are the state of the `box` and | ||
- the `mutator` will be called with two parameters which are the state of the `box` and | ||
the parameter passed in when the `MutationFactory` is called. | ||
@@ -291,3 +291,3 @@ - the state of the `box` will be set as the return value of the `mutator`. | ||
`ActionFactory`. The `actor` is a function which will be called when you dispatch | ||
the `Action`. The `ActionFactory` is a function, which will returns an `Action`. | ||
the `Action`. The `ActionFactory` is a function, which will return an `Action`. | ||
@@ -297,3 +297,3 @@ The `Action` is dispatchable, when you dispatch it, the `actor` will be called | ||
when the `ActionFactory` is called. The `dispatch` and `select` are the | ||
[`store.dispatch`](#storedispatch) and [`store.select`](#storeselect), which are | ||
[`store.dispatch`](#storedispatch) and [`store.select`](#storeselect), which | ||
allow you to dispatch some dispatchable things and select states. The return | ||
@@ -304,7 +304,7 @@ value of `store.dispatch(action)` is the return value of `actor`. | ||
An `SignalFactory` is a function to create an `Signal`, and could be subscribed by | ||
a `box`. An `Signal` is an object, which while trigger the subscribed `boxes` | ||
A `SignalFactory` is a function to create an `Signal`, and could be subscribed by | ||
a `box`. A `Signal` is an object, which will trigger the subscribed `boxes` | ||
to mutate these states when you dispatch it. | ||
You can create an `SignalFactory` by calling [`signal()`](#signal), and subscribe its | ||
You can create a `SignalFactory` by calling [`signal()`](#signal), and subscribe its | ||
`Signals` by calling [`box.subscribe()`](#boxsubscribe): | ||
@@ -330,3 +330,3 @@ | ||
**Please note that an signal will only be dispatched to the boxes which is invoked | ||
**Please note that a signal will only be dispatched to the boxes which is invoked | ||
already(`select(box)` and `dispatch(mutation)` will invoke the relative `box` | ||
@@ -380,3 +380,3 @@ automatically).** | ||
const selectMultipleCount = select((select, multiplier: number) => { | ||
const selectMultipleCount = selector((select, multiplier: number) => { | ||
return select(countBox) * multiplier; | ||
@@ -465,4 +465,4 @@ }); | ||
1. It always inject `dispatch` to the HOC | ||
2. It does not support `mapActions` | ||
1. It always injects `dispatch` to the HOC. | ||
2. It does not support `mapActions`. | ||
3. The `mapProps`'s first parameter is [`store.select`](#storeselect) | ||
@@ -500,3 +500,3 @@ rather than the state. | ||
of the ECMAScript specification. The following code is ok with `babel`, but will | ||
emit some types error with `TypeScript`: | ||
emit some type errors with `TypeScript`: | ||
@@ -534,7 +534,7 @@ ```typescript jsx | ||
Every call of [`store.dispatch(dispatchable)`](#storedispatch) will notify all | ||
the subscribers which is registered by [`store.subscribe()`](#storesubscribe). | ||
the subscribers which are registered by [`store.subscribe()`](#storesubscribe). | ||
Which means if you call `store.dispatch` twice synchronously, the subscribers | ||
will be called twice yet. Something will make the thing different: | ||
1. call `store.dispatch` with a `dispatchable` array:: | ||
1. call `store.dispatch` with a `dispatchable` array: | ||
@@ -556,5 +556,5 @@ ```typescript jsx | ||
Both of the two action will only notice the subscribers once. **Please | ||
note the `2nd` one needs two be `synchronous`, which means the | ||
asynchronous dispatches is separated, you MUST call the `dispatch()` | ||
Both of the two actions will only notice the subscribers once. **Please | ||
note the `2nd` one needs to be `synchronous`, which means the | ||
asynchronous dispatches are separated, you MUST call the `dispatch()` | ||
in the `1th` form in your asynchronous actions.** For example: | ||
@@ -584,3 +584,3 @@ | ||
should update if the state of boxes updated. the `useSelector` will caches | ||
the last parameters and state snapshots and the result of it. if a `dispatch` | ||
the last parameters and state snapshots and the result of it. If a `dispatch` | ||
mutated the state which is not depended by the selectors, the component will | ||
@@ -620,5 +620,5 @@ not rerender. It is fantastic! | ||
In addition, [`selector()`](#selector) accepts the second parameter called `deps`, | ||
which is a function also. the `deps` should accepts parameters same to the `fn`, and | ||
returns an array as the cache key, it will be called in `useSelector` to check the | ||
selector should or should not be rerun. For example: | ||
which is a function also. The `deps` should accepts parameters same to the `fn`, and | ||
returns an array as the cache key, it will be called in `useSelector` to check if the | ||
selector should be rerun. For example: | ||
@@ -729,3 +729,3 @@ ```typescript jsx | ||
**Signal** is `dispatchable**.` | ||
**Signal** is `dispatchable`. | ||
@@ -732,0 +732,0 @@ ### selector() |
@@ -7,3 +7,6 @@ /* | ||
import { Dispatch, Select } from './store'; | ||
import { config } from './utils'; | ||
export interface ActionOptions<R = any, A extends any[] = any> {} | ||
/** | ||
@@ -36,2 +39,4 @@ * An `Action` is a dispatchable function. It could do anything synchronously or | ||
(...args: A): Action<R, A>; | ||
options: ActionOptions<R, A>; | ||
config(options: ActionOptions<R, A>): this; | ||
} | ||
@@ -56,3 +61,5 @@ | ||
type, | ||
options: {}, | ||
config, | ||
}); | ||
} |
@@ -117,1 +117,5 @@ /* | ||
export const isArray: (args: any) => args is any[] | readonly any[] = Array.isArray; | ||
export function config<T extends object>(this: T, options: object): T { | ||
return Object.assign(this, { options }); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
284370
3442