Comparing version 1.10.0 to 1.10.1
import { Store } from 'effector'; | ||
export declare function empty<A>(a: Store<A | null>): Store<boolean>; | ||
export declare function empty<A>(source: Store<A | null>): Store<boolean>; |
@@ -1,3 +0,3 @@ | ||
export function empty(a) { | ||
return a.map(value => value === null); | ||
export function empty(source) { | ||
return source.map(value => value === null); | ||
} |
@@ -110,2 +110,3 @@ import { createEvent, createEffect, createStore, guard, sample, attach, is } from 'effector'; | ||
clock: timeoutFx.done, | ||
filter: $isRunning, | ||
fn: () => { | ||
@@ -129,3 +130,3 @@ /* to be sure, nothing passed to tick */ | ||
or: { | ||
sid: "-uanqf7" | ||
sid: "-ua3xtu" | ||
} | ||
@@ -142,3 +143,3 @@ }); | ||
or: { | ||
sid: "6lcmyy" | ||
sid: "6lwfkb" | ||
} | ||
@@ -156,3 +157,3 @@ }); | ||
if (is.store(value, { | ||
sid: "6p7767" | ||
sid: "71ao85" | ||
})) return value; | ||
@@ -165,3 +166,3 @@ | ||
}, | ||
sid: "5hw6se" | ||
sid: "5yxt6l" | ||
}); | ||
@@ -168,0 +169,0 @@ } |
{ | ||
"name": "patronum", | ||
"version": "1.10.0", | ||
"version": "1.10.1", | ||
"description": "☄️ Effector utility library delivering modularity and convenience", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -1,2 +0,2 @@ | ||
import{combine as e,createEvent as r,is as n,withRegion as t,createStore as o,sample as a,guard as i,merge as s,split as u,createEffect as c,attach as d,forward as f,createNode as m,step as l,restore as v}from"effector";function p(){for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];return e({and:[n,e=>e.reduce(((e,r)=>Boolean(e)&&Boolean(r)))],or:{sid:"-rbm5ks"}})}function y(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r&&(t=t.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),n.push.apply(n,t)}return n}function g(e,r,n){return r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function w(e){var{events:u,reset:c,target:d=r({name:"target",sid:"3pez5"},{name:"target",sid:"3pez5"})}=e;return n.unit(d)||b("target should be a unit"),c&&!n.unit(c)&&b("reset should be a unit"),t(d,(()=>{var e=Object.keys(u),r=Array.isArray(u)?[...e].fill(""):{},n=o(e.length,{name:"$counter",sid:"-dszn9a"}),t=o(r,{name:"$results",sid:"boz3x7"});n.reset(a({and:[d],or:{sid:"-8yzcn6"}})),t.reset(d),c&&(n.reset(a({and:[c],or:{sid:"-72suil"}})),t.reset(c));var f=function(e){var r=o(!1,{name:"$isDone",sid:"ucs7nc"}).on(u[e],(()=>!0)).reset(d);c&&r.reset(c),n.on(r,(e=>e-1)),t.on(u[e],((r,n)=>{var t=Array.isArray(r)?[...r]:function(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?y(Object(n),!0).forEach((function(r){g(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))}))}return e}({},r);return t[e]=n,t}))};for(var m of e)f(m);i({and:[{source:a({and:[t,s(Object.values(u),{name:"and",sid:"-l8g4ey"})],or:{name:"source",sid:"uf92v9"}}),filter:n.map((e=>0===e)),target:d}],or:{sid:"ciekm0"}})})),d}function b(e){throw new Error(e)}function h(e){var{if:t,then:o,else:a,source:s=r({name:"source",sid:"epke23"},{name:"source",sid:"epke23"})}=e,c=n.unit(t)||"function"==typeof t?t:e=>e===t;return o&&a?u({and:[{source:s,match:{then:c,else:k(c)},cases:{then:o,else:a}}],or:{sid:"9tug3k"}}):o?i({and:[{source:s,filter:c,target:o}],or:{sid:"abznoh"}}):a&&i({and:[{source:s,filter:k(c),target:a}],or:{sid:"-eb29qp"}}),s}function k(e){return n.unit(e)?e.map((e=>!e)):r=>!e(r)}function j(e){var{source:t,timeout:i,target:s}=e;if(!n.unit(t))throw new TypeError("source must be unit from effector");if(n.domain(t,{sid:"jne2ft"}))throw new TypeError("source cannot be domain");var u=function(e){if(n.store(e,{sid:"-2xmoh9"}))return e;if("number"==typeof e){if(e<0||!Number.isFinite(e))throw new Error('timeout must be positive number or zero. Received: "'.concat(e,'"'));return o(e,{and:{name:"$timeout"},sid:"-757cx6"})}throw new TypeError('timeout parameter in interval method should be number or Store. "'.concat(typeof e,'" was passed'))}(i),m=r({name:"saveTimeoutId",sid:"eqtrwk"}),l=o(null,{and:{serialize:"ignore"},name:"$timeoutId",sid:"-5hlcyp"}).on(m,((e,r)=>r)),v=r({name:"saveReject",sid:"-m6vk0"}),p=o(null,{and:{serialize:"ignore"},name:"$rejecter",sid:"tqvf32"}).on(v,((e,r)=>r)),y=null!=s?s:r({name:"tick",sid:"-6wklwe"}),g=c((e=>{var{parameter:r,timeout:n,timeoutId:t,rejectPromise:o}=e;return t&&clearTimeout(t),o&&o(),new Promise(((e,t)=>{v(t),m(setTimeout(e,n,r))}))}),{name:"timerBaseFx",sid:"-xd98qa"}),w=d({and:{source:{timeoutId:l,rejectPromise:p},mapParams:(e,r)=>{var{parameter:n,timeout:t}=e,{timeoutId:o,rejectPromise:a}=r;return{parameter:n,timeout:t,timeoutId:o,rejectPromise:a}},effect:g},or:{name:"timerFx",sid:"-4ab544"}});return p.reset(w.done),l.reset(w.done),a({and:[{source:u,clock:t,fn:(e,r)=>({timeout:e,parameter:r}),target:w}],or:{sid:"m29k3f"}}),f({and:{from:w.done.map((e=>{var{result:r}=e;return r})),to:y},or:{sid:"-32ktwy"}}),y}function A(){for(var e={trace:!1},r=arguments.length,t=new Array(r),o=0;o<r;o++)t[o]=arguments[o];var[a,...i]=t;for(var s of(n.unit(a)?z(a):e=a,i))n.unit(s)&&z(s,e)}function E(e){return n.store(e,{sid:"-i74wsd"})?"store":n.effect(e,{sid:"-i5hj0a"})?"effect":n.event(e,{sid:"-i3u587"})?"event":n.domain(e,{sid:"-i26rg4"})?"domain":n.unit(e)?"unit":"unknown"}function O(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",t=n+T(e);e.watch((e=>{console.info("[".concat(r,"] ").concat(t),e)}))}function P(e){O(e.done,"effect",T(e)+"."),O(e.fail,"effect",T(e)+".")}function T(e){return e.compositeName&&e.compositeName.fullName?e.compositeName.fullName:e.shortName?e.shortName:e.name?e.name:""}function x(e){var r,n=function(e){var{meta:r}=e;return"config"in r?r.config.loc:r.loc}(e);return n?"".concat(null!==(r=n.file)&&void 0!==r?r:"",":").concat(n.line,":").concat(n.column):null}function z(e,r){var t=E(e);(n.store(e,{sid:"voorwi"})||n.effect(e,{sid:"-c68ujk"})||n.event(e,{sid:"-c68t31"}))&&(O(e,t),null!=r&&r.trace&&S(e)),n.effect(e,{sid:"w4mt3z"})&&P(e),n.domain(e,{sid:"w6tzhf"})&&(e.onCreateEvent((e=>{O(e,"event"),null!=r&&r.trace&&S(e)})),e.onCreateStore((e=>{O(e,"store"),null!=r&&r.trace&&S(e)})),e.onCreateEffect(P))}function $(e){if(!e)return"";var{meta:r}=e;if(!function(e){var r=function(e){return"graphite"in e?e.graphite:e}(e),{sid:n,named:t}=r.meta;return Boolean(!n&&("finally"===t||"done"===t||"doneData"===t||"fail"===t||"failData"===t||"inFlight"===t||"pending"===t))}(e))return r.name;var n=e.family.owners.find((e=>"effect"===e.meta.op));return n?"".concat($(n),".").concat(r.named):r.named}function S(e){var r=E(e),n=T(e);m({parent:[e],meta:{op:"watch"},family:{owners:e},regional:!0,node:[l.run({fn(e,t,o){var a=null==o?void 0:o.parent,i="[".concat(r,"] ").concat(n," trace");for(console.groupCollapsed(i);a;){var s,u,{node:c,value:d}=a,{meta:f}=c,m=f.op,l=$(c);if(!l)l=null!==(u=x(c))&&void 0!==u?u:"";if("on"===m){var v,p,y,g=$(null==c||null===(v=c.next)||void 0===v?void 0:v[0]);m="".concat(g,".").concat(f.op),l="".concat(g,".").concat(f.op,"(").concat($(null===(p=a)||void 0===p||null===(y=p.parent)||void 0===y?void 0:y.node),")")}console.info("<- [".concat(m,"] ").concat(l),d),a=null===(s=a)||void 0===s?void 0:s.parent}console.groupEnd()}})]})}function F(t){var{source:o,timeout:i,target:s=r({name:"target",sid:"-z2vw3w"},{name:"target",sid:"-z2vw3w"})}=t;if(!n.unit(o))throw new TypeError("source must be a unit from effector");if(!n.unit(s))throw new TypeError("target must be a unit from effector");var u=function(e){if(n.store(e,{sid:"-va560a"})||"function"==typeof e||"number"==typeof e)return e;throw new TypeError("'timeout' argument must be a function, Store, or a number. Passed \"".concat(typeof e,'"'))}(i),d=c((e=>{var{payload:r,milliseconds:n}=e;return new Promise((e=>{setTimeout(e,n,r)}))}),{name:"timerFx",sid:"-584o7j"});return a({and:[{source:e({and:[{milliseconds:u}],or:{name:"source",sid:"9rbdjo"}}),clock:o,fn:(e,r)=>{var{milliseconds:n}=e;return{payload:r,milliseconds:"function"==typeof n?n(r):n}},target:d}],or:{sid:"-wmj29s"}}),f({and:{from:d.doneData,to:s},or:{sid:"-vsadmx"}}),s}function N(r,t,o){return n.store(r,{sid:"n60kh0"})?e({and:[r,t,o,(e,r,n)=>e?r:n],or:{sid:"8ceklb"}}):N(r)}function q(e){return e.map((e=>null===e))}function D(r,n){return e({and:[r,n,(e,r)=>e===r],or:{sid:"jvku5g"}})}function B(r,t){var o,a=[],i=()=>!1;Array.isArray(r)?(a=r,i=t):Array.isArray(r.stores)&&(a=r.stores,i=r.predicate),o="function"==typeof i?i:n.store(i,{sid:"sid3ut"})?i.map((e=>r=>e===r)):e=>e===i;var s=e({and:[a],or:{name:"$values",sid:"h09uhg"}});return e({and:[o,s,(e,r)=>r.every(e)],or:{sid:"hfkdw9"}})}function I(r){for(var n=arguments.length,t=new Array(n>1?n-1:0),o=1;o<n;o++)t[o-1]=arguments[o];return e({and:[t,e=>r.reduce(((n,t,o)=>n.concat(R(r,o)?t:"".concat(t).concat(C(e[o])))),"")],or:{sid:"-yrbthp"}})}function C(e){return Array.isArray(e)?e.map((e=>String(e))).join(", "):String(e)}function R(e,r){return r===e.length-1}function _(r){var{effects:n,domain:t}=r;if(t){var o=t.createStore(0,{name:"$inFlight",sid:"-y7vg7t"});return t.onCreateEffect((e=>{o.on(e,(e=>e+1)).on(e.finally,(e=>e-1))})),o}return e({and:[n.map((e=>e.inFlight)),e=>e.reduce(((e,r)=>e+r),0)],or:{sid:"ubqxa7"}})}function K(e){var{timeout:t,start:s,stop:u,leading:f=!1,trailing:m=!1}=e,l=r({name:"tick",sid:"uo9p3s"}),v=o(!1,{name:"$isRunning",sid:"-wxesi8"}),p=function(e){if(n.store(e,{sid:"6p7767"}))return e;if("number"==typeof e)return o(e,{and:{name:"$timeout"},sid:"5hw6se"});throw new TypeError('timeout parameter in interval method should be number or Store. "'.concat(typeof e,'" was passed'))}(t),y=v.map((e=>!e)),g=r({name:"saveTimeout",sid:"as5clk"}),w=o(null,{name:"$timeoutId",sid:"-bh90bo"}).on(g,((e,r)=>r)),b=r({name:"saveReject",sid:"-64swis"}),h=o((()=>{}),{name:"$rejecter",sid:"eabbu7"}).on(b,((e,r)=>r)),k=c((e=>new Promise(((r,n)=>{var t=setTimeout(r,e);g(t),b(n)}))),{name:"timeoutFx",sid:"7lc3mj"}),j=d({and:{source:[w,h],effect:e=>{var[r,n]=e;n(),r&&clearTimeout(r)}},or:{name:"cleanupFx",sid:"pcn5jq"}});return i({and:[{clock:s,source:p,filter:y,target:k}],or:{sid:"-w5qmwp"}}),f&&i({and:[{clock:s,filter:y,target:l}],or:{sid:"-vpslni"}}),a({and:[{clock:s,fn:()=>!0,target:v}],or:{sid:"-vaed34"}}),i({and:[{clock:k.done,source:p,filter:v,target:k}],or:{sid:"-v73liy"}}),a({and:[{clock:k.done,fn:()=>{},target:l}],or:{sid:"-urpcwu"}}),u&&(m&&a({and:[{clock:u,target:l}],or:{sid:"-uanqf7"}}),v.on(u,(()=>!1)),a({and:[{clock:u,target:j}],or:{sid:"6lcmyy"}})),{tick:l,isRunning:v}}function M(e){return e.map((e=>!e))}function V(){for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];return e({and:[n,e=>e.reduce(((e,r)=>Boolean(e)||Boolean(r)))],or:{sid:"-44722k"}})}var G={some:e=>e.some(Boolean),every:e=>e.every(Boolean)};function H(r){var{effects:t,domain:o,of:a="some"}=r;if(!n.domain(o,{sid:"97b92c"})&&!t)throw new TypeError("domain or effects should be passed");if("some"!==a&&"every"!==a)throw new TypeError('strategy parameter "of" can be "every" or "some". Passed: "'.concat(a,'"'));var i=null!=t?t:[],s=G[a];return o&&(i=[],o.onCreateEffect((e=>i.push(e)))),e({and:[i.map((e=>e.pending)),s],or:{sid:"a37bj0"}})}function J(e){var{clock:r,target:n}=e,t=Array.isArray(n)?n:[n],o=Array.isArray(r)?r:[r];t.forEach((e=>{e.reset.call(e,o)}))}function L(e){var{source:r,shape:n}=e,t={};for(var o in n)o in n&&function(){var e=n[o];t[o]=r.map((r=>{var n=e(r);return void 0===n?null:n}))}();return t}function Q(e){var{source:r,clock:n,fn:t=(e=>e)}=e,i=t(r.defaultState),s=a(n?{and:[r,n,t],or:{name:"onSnapshot",sid:"-auitd0"}}:{and:[{source:r,fn:t}],or:{name:"onSnapshot",sid:"-auir6n"}}),u=o(i,{name:"$snapshot",sid:"-7zyoaf"});return u.on(s,((e,r)=>r)),u}function U(r,t){var o,a=[],i=()=>!1;Array.isArray(r)?(a=r,i=t):Array.isArray(r.stores)&&(a=r.stores,i=r.predicate),o="function"==typeof i?i:n.store(i,{sid:"zbwu0l"})?i.map((e=>r=>e===r)):e=>e===i;var s=e({and:[a],or:{name:"$values",sid:"-lv5do0"}});return e({and:[o,s,(e,r)=>r.some(e)],or:{sid:"-efc5w7"}})}function W(e){var{source:r,cases:t}=e,o={},a=n.store(r,{name:"current",sid:"-htjkz7"})?r.updates:r;for(var i in t)i in t&&function(){var e=t[i];o[i]=a.filterMap(e),a=a.filter({fn:r=>!e(r)})}();return o.__=a,o}var X={}.hasOwnProperty;function Y(e){var{targets:n,source:t=r({name:"source",sid:"-fkbi3c"},{name:"source",sid:"-fkbi3c"})}=e,o=function(e){if(s=n,u=e,X.call(s,u)){var r=n[e],o=i({and:[{source:t,greedy:!0,filter:r=>"object"==typeof r&&null!==r&&e in r}],or:{name:"hasTargetKey",sid:"-cov4g4"}});a({and:[{greedy:!0,clock:o,fn:r=>r[e],target:r}],or:{sid:"lpn34j"}})}var s,u};for(var s in n)o(s);return t}function Z(e){var{effect:r,defaultValue:n="initial"}=e,t=o(n,{name:"$status",sid:"abrgim"});return t.on(r,(()=>"pending")).on(r.done,(()=>"done")).on(r.fail,(()=>"fail")),t}function ee(e){var{source:t,timeout:s,target:u=r({name:"target",sid:"r328r6"},{name:"target",sid:"r328r6"})}=e;if(!n.unit(t))throw new TypeError("source must be unit from effector");var d=function(e){if(n.store(e,{sid:"-hl6vqh"}))return e;if("number"==typeof e){if(e<0||!Number.isFinite(e))throw new Error('timeout must be positive number or zero. Received: "'.concat(e,'"'));return o(e,{and:{name:"$timeout"},sid:"pu8pon"})}throw new TypeError('timeout parameter should be number or Store. "'.concat(typeof e,'" was passed'))}(s),f=c((e=>new Promise((r=>setTimeout(r,e)))),{name:"timerFx",sid:"-pyjx8k"}),m=i({and:[{clock:t,filter:f.pending.map((e=>!e))}],or:{name:"start",sid:"-p67kgr"}});return a({and:[{source:d,clock:m,target:f}],or:{sid:"-ievrvf"}}),a({and:[{source:t,clock:f.done,target:u}],or:{sid:"-i01buo"}}),u}var re=()=>Date.now();function ne(e){var{clock:r,getNow:n,initial:t}=e,o=null!=n?n:re,a=c(o,{name:"readNowFx",sid:"459ysb"}),i=v(a,null!=t?t:o(),{name:"$time",sid:"-ys9vce"});return f({and:{from:r,to:a},or:{sid:"rdje9v"}}),i}export{p as and,w as combineEvents,h as condition,j as debounce,A as debug,F as delay,N as either,q as empty,D as equals,B as every,I as format,_ as inFlight,K as interval,M as not,V as or,H as pending,J as reset,L as reshape,Q as snapshot,U as some,W as splitMap,Y as spread,Z as status,ee as throttle,ne as time}; | ||
import{combine as e,createEvent as r,is as n,withRegion as t,createStore as o,sample as a,guard as i,merge as s,split as u,createEffect as c,attach as d,forward as f,createNode as m,step as l,restore as v}from"effector";function p(){for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];return e({and:[n,e=>e.reduce(((e,r)=>Boolean(e)&&Boolean(r)))],or:{sid:"-rbm5ks"}})}function y(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r&&(t=t.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),n.push.apply(n,t)}return n}function g(e,r,n){return r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function w(e){var{events:u,reset:c,target:d=r({name:"target",sid:"3pez5"},{name:"target",sid:"3pez5"})}=e;return n.unit(d)||b("target should be a unit"),c&&!n.unit(c)&&b("reset should be a unit"),t(d,(()=>{var e=Object.keys(u),r=Array.isArray(u)?[...e].fill(""):{},n=o(e.length,{name:"$counter",sid:"-dszn9a"}),t=o(r,{name:"$results",sid:"boz3x7"});n.reset(a({and:[d],or:{sid:"-8yzcn6"}})),t.reset(d),c&&(n.reset(a({and:[c],or:{sid:"-72suil"}})),t.reset(c));var f=function(e){var r=o(!1,{name:"$isDone",sid:"ucs7nc"}).on(u[e],(()=>!0)).reset(d);c&&r.reset(c),n.on(r,(e=>e-1)),t.on(u[e],((r,n)=>{var t=Array.isArray(r)?[...r]:function(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?y(Object(n),!0).forEach((function(r){g(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))}))}return e}({},r);return t[e]=n,t}))};for(var m of e)f(m);i({and:[{source:a({and:[t,s(Object.values(u),{name:"and",sid:"-l8g4ey"})],or:{name:"source",sid:"uf92v9"}}),filter:n.map((e=>0===e)),target:d}],or:{sid:"ciekm0"}})})),d}function b(e){throw new Error(e)}function h(e){var{if:t,then:o,else:a,source:s=r({name:"source",sid:"epke23"},{name:"source",sid:"epke23"})}=e,c=n.unit(t)||"function"==typeof t?t:e=>e===t;return o&&a?u({and:[{source:s,match:{then:c,else:k(c)},cases:{then:o,else:a}}],or:{sid:"9tug3k"}}):o?i({and:[{source:s,filter:c,target:o}],or:{sid:"abznoh"}}):a&&i({and:[{source:s,filter:k(c),target:a}],or:{sid:"-eb29qp"}}),s}function k(e){return n.unit(e)?e.map((e=>!e)):r=>!e(r)}function j(e){var{source:t,timeout:i,target:s}=e;if(!n.unit(t))throw new TypeError("source must be unit from effector");if(n.domain(t,{sid:"jne2ft"}))throw new TypeError("source cannot be domain");var u=function(e){if(n.store(e,{sid:"-2xmoh9"}))return e;if("number"==typeof e){if(e<0||!Number.isFinite(e))throw new Error('timeout must be positive number or zero. Received: "'.concat(e,'"'));return o(e,{and:{name:"$timeout"},sid:"-757cx6"})}throw new TypeError('timeout parameter in interval method should be number or Store. "'.concat(typeof e,'" was passed'))}(i),m=r({name:"saveTimeoutId",sid:"eqtrwk"}),l=o(null,{and:{serialize:"ignore"},name:"$timeoutId",sid:"-5hlcyp"}).on(m,((e,r)=>r)),v=r({name:"saveReject",sid:"-m6vk0"}),p=o(null,{and:{serialize:"ignore"},name:"$rejecter",sid:"tqvf32"}).on(v,((e,r)=>r)),y=null!=s?s:r({name:"tick",sid:"-6wklwe"}),g=c((e=>{var{parameter:r,timeout:n,timeoutId:t,rejectPromise:o}=e;return t&&clearTimeout(t),o&&o(),new Promise(((e,t)=>{v(t),m(setTimeout(e,n,r))}))}),{name:"timerBaseFx",sid:"-xd98qa"}),w=d({and:{source:{timeoutId:l,rejectPromise:p},mapParams:(e,r)=>{var{parameter:n,timeout:t}=e,{timeoutId:o,rejectPromise:a}=r;return{parameter:n,timeout:t,timeoutId:o,rejectPromise:a}},effect:g},or:{name:"timerFx",sid:"-4ab544"}});return p.reset(w.done),l.reset(w.done),a({and:[{source:u,clock:t,fn:(e,r)=>({timeout:e,parameter:r}),target:w}],or:{sid:"m29k3f"}}),f({and:{from:w.done.map((e=>{var{result:r}=e;return r})),to:y},or:{sid:"-32ktwy"}}),y}function A(){for(var e={trace:!1},r=arguments.length,t=new Array(r),o=0;o<r;o++)t[o]=arguments[o];var[a,...i]=t;for(var s of(n.unit(a)?z(a):e=a,i))n.unit(s)&&z(s,e)}function E(e){return n.store(e,{sid:"-i74wsd"})?"store":n.effect(e,{sid:"-i5hj0a"})?"effect":n.event(e,{sid:"-i3u587"})?"event":n.domain(e,{sid:"-i26rg4"})?"domain":n.unit(e)?"unit":"unknown"}function O(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",t=n+T(e);e.watch((e=>{console.info("[".concat(r,"] ").concat(t),e)}))}function P(e){O(e.done,"effect",T(e)+"."),O(e.fail,"effect",T(e)+".")}function T(e){return e.compositeName&&e.compositeName.fullName?e.compositeName.fullName:e.shortName?e.shortName:e.name?e.name:""}function x(e){var r,n=function(e){var{meta:r}=e;return"config"in r?r.config.loc:r.loc}(e);return n?"".concat(null!==(r=n.file)&&void 0!==r?r:"",":").concat(n.line,":").concat(n.column):null}function z(e,r){var t=E(e);(n.store(e,{sid:"voorwi"})||n.effect(e,{sid:"-c68ujk"})||n.event(e,{sid:"-c68t31"}))&&(O(e,t),null!=r&&r.trace&&S(e)),n.effect(e,{sid:"w4mt3z"})&&P(e),n.domain(e,{sid:"w6tzhf"})&&(e.onCreateEvent((e=>{O(e,"event"),null!=r&&r.trace&&S(e)})),e.onCreateStore((e=>{O(e,"store"),null!=r&&r.trace&&S(e)})),e.onCreateEffect(P))}function $(e){if(!e)return"";var{meta:r}=e;if(!function(e){var r=function(e){return"graphite"in e?e.graphite:e}(e),{sid:n,named:t}=r.meta;return Boolean(!n&&("finally"===t||"done"===t||"doneData"===t||"fail"===t||"failData"===t||"inFlight"===t||"pending"===t))}(e))return r.name;var n=e.family.owners.find((e=>"effect"===e.meta.op));return n?"".concat($(n),".").concat(r.named):r.named}function S(e){var r=E(e),n=T(e);m({parent:[e],meta:{op:"watch"},family:{owners:e},regional:!0,node:[l.run({fn(e,t,o){var a=null==o?void 0:o.parent,i="[".concat(r,"] ").concat(n," trace");for(console.groupCollapsed(i);a;){var s,u,{node:c,value:d}=a,{meta:f}=c,m=f.op,l=$(c);if(!l)l=null!==(u=x(c))&&void 0!==u?u:"";if("on"===m){var v,p,y,g=$(null==c||null===(v=c.next)||void 0===v?void 0:v[0]);m="".concat(g,".").concat(f.op),l="".concat(g,".").concat(f.op,"(").concat($(null===(p=a)||void 0===p||null===(y=p.parent)||void 0===y?void 0:y.node),")")}console.info("<- [".concat(m,"] ").concat(l),d),a=null===(s=a)||void 0===s?void 0:s.parent}console.groupEnd()}})]})}function F(t){var{source:o,timeout:i,target:s=r({name:"target",sid:"-z2vw3w"},{name:"target",sid:"-z2vw3w"})}=t;if(!n.unit(o))throw new TypeError("source must be a unit from effector");if(!n.unit(s))throw new TypeError("target must be a unit from effector");var u=function(e){if(n.store(e,{sid:"-va560a"})||"function"==typeof e||"number"==typeof e)return e;throw new TypeError("'timeout' argument must be a function, Store, or a number. Passed \"".concat(typeof e,'"'))}(i),d=c((e=>{var{payload:r,milliseconds:n}=e;return new Promise((e=>{setTimeout(e,n,r)}))}),{name:"timerFx",sid:"-584o7j"});return a({and:[{source:e({and:[{milliseconds:u}],or:{name:"source",sid:"9rbdjo"}}),clock:o,fn:(e,r)=>{var{milliseconds:n}=e;return{payload:r,milliseconds:"function"==typeof n?n(r):n}},target:d}],or:{sid:"-wmj29s"}}),f({and:{from:d.doneData,to:s},or:{sid:"-vsadmx"}}),s}function N(r,t,o){return n.store(r,{sid:"n60kh0"})?e({and:[r,t,o,(e,r,n)=>e?r:n],or:{sid:"8ceklb"}}):N(r)}function D(e){return e.map((e=>null===e))}function q(r,n){return e({and:[r,n,(e,r)=>e===r],or:{sid:"jvku5g"}})}function B(r,t){var o,a=[],i=()=>!1;Array.isArray(r)?(a=r,i=t):Array.isArray(r.stores)&&(a=r.stores,i=r.predicate),o="function"==typeof i?i:n.store(i,{sid:"sid3ut"})?i.map((e=>r=>e===r)):e=>e===i;var s=e({and:[a],or:{name:"$values",sid:"h09uhg"}});return e({and:[o,s,(e,r)=>r.every(e)],or:{sid:"hfkdw9"}})}function I(r){for(var n=arguments.length,t=new Array(n>1?n-1:0),o=1;o<n;o++)t[o-1]=arguments[o];return e({and:[t,e=>r.reduce(((n,t,o)=>n.concat(R(r,o)?t:"".concat(t).concat(C(e[o])))),"")],or:{sid:"-yrbthp"}})}function C(e){return Array.isArray(e)?e.map((e=>String(e))).join(", "):String(e)}function R(e,r){return r===e.length-1}function _(r){var{effects:n,domain:t}=r;if(t){var o=t.createStore(0,{name:"$inFlight",sid:"-y7vg7t"});return t.onCreateEffect((e=>{o.on(e,(e=>e+1)).on(e.finally,(e=>e-1))})),o}return e({and:[n.map((e=>e.inFlight)),e=>e.reduce(((e,r)=>e+r),0)],or:{sid:"ubqxa7"}})}function K(e){var{timeout:t,start:s,stop:u,leading:f=!1,trailing:m=!1}=e,l=r({name:"tick",sid:"uo9p3s"}),v=o(!1,{name:"$isRunning",sid:"-wxesi8"}),p=function(e){if(n.store(e,{sid:"71ao85"}))return e;if("number"==typeof e)return o(e,{and:{name:"$timeout"},sid:"5yxt6l"});throw new TypeError('timeout parameter in interval method should be number or Store. "'.concat(typeof e,'" was passed'))}(t),y=v.map((e=>!e)),g=r({name:"saveTimeout",sid:"as5clk"}),w=o(null,{name:"$timeoutId",sid:"-bh90bo"}).on(g,((e,r)=>r)),b=r({name:"saveReject",sid:"-64swis"}),h=o((()=>{}),{name:"$rejecter",sid:"eabbu7"}).on(b,((e,r)=>r)),k=c((e=>new Promise(((r,n)=>{var t=setTimeout(r,e);g(t),b(n)}))),{name:"timeoutFx",sid:"7lc3mj"}),j=d({and:{source:[w,h],effect:e=>{var[r,n]=e;n(),r&&clearTimeout(r)}},or:{name:"cleanupFx",sid:"pcn5jq"}});return i({and:[{clock:s,source:p,filter:y,target:k}],or:{sid:"-w5qmwp"}}),f&&i({and:[{clock:s,filter:y,target:l}],or:{sid:"-vpslni"}}),a({and:[{clock:s,fn:()=>!0,target:v}],or:{sid:"-vaed34"}}),i({and:[{clock:k.done,source:p,filter:v,target:k}],or:{sid:"-v73liy"}}),a({and:[{clock:k.done,filter:v,fn:()=>{},target:l}],or:{sid:"-urpcwu"}}),u&&(m&&a({and:[{clock:u,target:l}],or:{sid:"-ua3xtu"}}),v.on(u,(()=>!1)),a({and:[{clock:u,target:j}],or:{sid:"6lwfkb"}})),{tick:l,isRunning:v}}function M(e){return e.map((e=>!e))}function V(){for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];return e({and:[n,e=>e.reduce(((e,r)=>Boolean(e)||Boolean(r)))],or:{sid:"-44722k"}})}var G={some:e=>e.some(Boolean),every:e=>e.every(Boolean)};function H(r){var{effects:t,domain:o,of:a="some"}=r;if(!n.domain(o,{sid:"97b92c"})&&!t)throw new TypeError("domain or effects should be passed");if("some"!==a&&"every"!==a)throw new TypeError('strategy parameter "of" can be "every" or "some". Passed: "'.concat(a,'"'));var i=null!=t?t:[],s=G[a];return o&&(i=[],o.onCreateEffect((e=>i.push(e)))),e({and:[i.map((e=>e.pending)),s],or:{sid:"a37bj0"}})}function J(e){var{clock:r,target:n}=e,t=Array.isArray(n)?n:[n],o=Array.isArray(r)?r:[r];t.forEach((e=>{e.reset(o)}))}function L(e){var{source:r,shape:n}=e,t={};for(var o in n)o in n&&function(){var e=n[o];t[o]=r.map((r=>{var n=e(r);return void 0===n?null:n}))}();return t}function Q(e){var{source:r,clock:n,fn:t=(e=>e)}=e,i=t(r.defaultState),s=a(n?{and:[r,n,t],or:{name:"onSnapshot",sid:"-auitd0"}}:{and:[{source:r,fn:t}],or:{name:"onSnapshot",sid:"-auir6n"}}),u=o(i,{name:"$snapshot",sid:"-7zyoaf"});return u.on(s,((e,r)=>r)),u}function U(r,t){var o,a=[],i=()=>!1;Array.isArray(r)?(a=r,i=t):Array.isArray(r.stores)&&(a=r.stores,i=r.predicate),o="function"==typeof i?i:n.store(i,{sid:"zbwu0l"})?i.map((e=>r=>e===r)):e=>e===i;var s=e({and:[a],or:{name:"$values",sid:"-lv5do0"}});return e({and:[o,s,(e,r)=>r.some(e)],or:{sid:"-efc5w7"}})}function W(e){var{source:r,cases:t}=e,o={},a=n.store(r,{name:"current",sid:"-htjkz7"})?r.updates:r;for(var i in t)i in t&&function(){var e=t[i];o[i]=a.filterMap(e),a=a.filter({fn:r=>!e(r)})}();return o.__=a,o}var X={}.hasOwnProperty;function Y(e){var{targets:n,source:t=r({name:"source",sid:"-fkbi3c"},{name:"source",sid:"-fkbi3c"})}=e,o=function(e){if(s=n,u=e,X.call(s,u)){var r=n[e],o=i({and:[{source:t,greedy:!0,filter:r=>"object"==typeof r&&null!==r&&e in r}],or:{name:"hasTargetKey",sid:"-cov4g4"}});a({and:[{greedy:!0,clock:o,fn:r=>r[e],target:r}],or:{sid:"lpn34j"}})}var s,u};for(var s in n)o(s);return t}function Z(e){var{effect:r,defaultValue:n="initial"}=e,t=o(n,{name:"$status",sid:"abrgim"});return t.on(r,(()=>"pending")).on(r.done,(()=>"done")).on(r.fail,(()=>"fail")),t}function ee(e){var{source:t,timeout:s,target:u=r({name:"target",sid:"r328r6"},{name:"target",sid:"r328r6"})}=e;if(!n.unit(t))throw new TypeError("source must be unit from effector");var d=function(e){if(n.store(e,{sid:"-hl6vqh"}))return e;if("number"==typeof e){if(e<0||!Number.isFinite(e))throw new Error('timeout must be positive number or zero. Received: "'.concat(e,'"'));return o(e,{and:{name:"$timeout"},sid:"pu8pon"})}throw new TypeError('timeout parameter should be number or Store. "'.concat(typeof e,'" was passed'))}(s),f=c((e=>new Promise((r=>setTimeout(r,e)))),{name:"timerFx",sid:"-pyjx8k"}),m=i({and:[{clock:t,filter:f.pending.map((e=>!e))}],or:{name:"start",sid:"-p67kgr"}});return a({and:[{source:d,clock:m,target:f}],or:{sid:"-ievrvf"}}),a({and:[{source:t,clock:f.done,target:u}],or:{sid:"-i01buo"}}),u}var re=()=>Date.now();function ne(e){var{clock:r,getNow:n,initial:t}=e,o=null!=n?n:re,a=c(o,{name:"readNowFx",sid:"459ysb"}),i=v(a,null!=t?t:o(),{name:"$time",sid:"-ys9vce"});return f({and:{from:r,to:a},or:{sid:"rdje9v"}}),i}export{p as and,w as combineEvents,h as condition,j as debounce,A as debug,F as delay,N as either,D as empty,q as equals,B as every,I as format,_ as inFlight,K as interval,M as not,V as or,H as pending,J as reset,L as reshape,Q as snapshot,U as some,W as splitMap,Y as spread,Z as status,ee as throttle,ne as time}; | ||
//# sourceMappingURL=patronum.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("effector")):"function"==typeof define&&define.amd?define(["exports","effector"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).patronum={},e.effector)}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(t);function o(e,t,n){return e(n={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&n.path)}},n.exports),n.exports}var a=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.and=function(...e){return(0,r.default.combine)({and:[e,e=>e.reduce(((e,t)=>Boolean(e)&&Boolean(t)))],or:{sid:"-rbm5ks"}})}})),i=o((function(e,t){function n(e){throw new Error(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.combineEvents=function({events:e,reset:t,target:o=(0,r.default.createEvent)({name:"target",sid:"3pez5"})}){r.default.is.unit(o)||n("target should be a unit");t&&!r.default.is.unit(t)&&n("reset should be a unit");return(0,r.default.withRegion)(o,(()=>{const n=Object.keys(e),a=Array.isArray(e)?[...n].fill(""):{},i=(0,r.default.createStore)(n.length,{name:"$counter",sid:"-dszn9a"}),u=(0,r.default.createStore)(a,{name:"$results",sid:"boz3x7"});i.reset((0,r.default.sample)({and:[o],or:{sid:"-8yzcn6"}})),u.reset(o),t&&(i.reset((0,r.default.sample)({and:[t],or:{sid:"-72suil"}})),u.reset(t));for(const a of n){const n=(0,r.default.createStore)(!1,{name:"$isDone",sid:"ucs7nc"}).on(e[a],(()=>!0)).reset(o);t&&n.reset(t),i.on(n,(e=>e-1)),u.on(e[a],((e,t)=>{const n=Array.isArray(e)?[...e]:{...e};return n[a]=t,n}))}(0,r.default.guard)({and:[{source:(0,r.default.sample)({and:[u,(0,r.default.merge)(Object.values(e),{name:"and",sid:"-l8g4ey"})],or:{name:"source",sid:"uf92v9"}}),filter:i.map((e=>0===e)),target:o}],or:{sid:"ciekm0"}})})),o}})),u=o((function(e,t){function n(e){return r.default.is.unit(e)?e.map((e=>!e)):t=>!e(t)}Object.defineProperty(t,"__esModule",{value:!0}),t.condition=function({if:e,then:t,else:o,source:a=(0,r.default.createEvent)({name:"source",sid:"epke23"})}){const i=r.default.is.unit(e)||(u=e,"function"==typeof u)?e:t=>t===e;var u;t&&o?(0,r.default.split)({and:[{source:a,match:{then:i,else:n(i)},cases:{then:t,else:o}}],or:{sid:"9tug3k"}}):t?(0,r.default.guard)({and:[{source:a,filter:i,target:t}],or:{sid:"abznoh"}}):o&&(0,r.default.guard)({and:[{source:a,filter:n(i),target:o}],or:{sid:"-eb29qp"}});return a}})),s=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.debounce=function({source:e,timeout:t,target:n}){if(!r.default.is.unit(e))throw new TypeError("source must be unit from effector");if(r.default.is.domain(e,{sid:"jne2ft"}))throw new TypeError("source cannot be domain");const o=function(e){if(r.default.is.store(e,{sid:"-2xmoh9"}))return e;if("number"==typeof e){if(e<0||!Number.isFinite(e))throw new Error(`timeout must be positive number or zero. Received: "${e}"`);return(0,r.default.createStore)(e,{and:{name:"$timeout"},sid:"-757cx6"})}throw new TypeError(`timeout parameter in interval method should be number or Store. "${typeof e}" was passed`)}(t),a=(0,r.default.createEvent)({name:"saveTimeoutId",sid:"eqtrwk"}),i=(0,r.default.createStore)(null,{and:{serialize:"ignore"},name:"$timeoutId",sid:"-5hlcyp"}).on(a,((e,t)=>t)),u=(0,r.default.createEvent)({name:"saveReject",sid:"-m6vk0"}),s=(0,r.default.createStore)(null,{and:{serialize:"ignore"},name:"$rejecter",sid:"tqvf32"}).on(u,((e,t)=>t)),d=null!=n?n:(0,r.default.createEvent)({name:"tick",sid:"-6wklwe"}),f=(0,r.default.createEffect)((({parameter:e,timeout:t,timeoutId:n,rejectPromise:r})=>(n&&clearTimeout(n),r&&r(),new Promise(((n,r)=>{u(r),a(setTimeout(n,t,e))})))),{name:"timerBaseFx",sid:"-xd98qa"}),l=(0,r.default.attach)({and:{source:{timeoutId:i,rejectPromise:s},mapParams:({parameter:e,timeout:t},{timeoutId:n,rejectPromise:r})=>({parameter:e,timeout:t,timeoutId:n,rejectPromise:r}),effect:f},or:{name:"timerFx",sid:"-4ab544"}});return s.reset(l.done),i.reset(l.done),(0,r.default.sample)({and:[{source:o,clock:e,fn:(e,t)=>({timeout:e,parameter:t}),target:l}],or:{sid:"m29k3f"}}),(0,r.default.forward)({and:{from:l.done.map((({result:e})=>e)),to:d},or:{sid:"-32ktwy"}}),d}})),d=o((function(e,t){function n(e){return r.default.is.store(e,{sid:"-i74wsd"})?"store":r.default.is.effect(e,{sid:"-i5hj0a"})?"effect":r.default.is.event(e,{sid:"-i3u587"})?"event":r.default.is.domain(e,{sid:"-i26rg4"})?"domain":r.default.is.unit(e)?"unit":"unknown"}function o(e,t,n=""){const r=n+i(e);e.watch((e=>{console.info(`[${t}] ${r}`,e)}))}function a(e){o(e.done,"effect",i(e)+"."),o(e.fail,"effect",i(e)+".")}function i(e){return e.compositeName&&e.compositeName.fullName?e.compositeName.fullName:e.shortName?e.shortName:e.name?e.name:""}function u(e){var t;const n=function({meta:e}){return"config"in e?e.config.loc:e.loc}(e);return n?`${null!==(t=n.file)&&void 0!==t?t:""}:${n.line}:${n.column}`:null}function s(e,t){const i=n(e);(r.default.is.store(e,{sid:"voorwi"})||r.default.is.effect(e,{sid:"-c68ujk"})||r.default.is.event(e,{sid:"-c68t31"}))&&(o(e,i),null!=t&&t.trace&&f(e)),r.default.is.effect(e,{sid:"w4mt3z"})&&a(e),r.default.is.domain(e,{sid:"w6tzhf"})&&(e.onCreateEvent((e=>{o(e,"event"),null!=t&&t.trace&&f(e)})),e.onCreateStore((e=>{o(e,"store"),null!=t&&t.trace&&f(e)})),e.onCreateEffect(a))}function d(e){if(!e)return"";const{meta:t}=e;if(!function(e){const t=function(e){return"graphite"in e?e.graphite:e}(e),{sid:n,named:r}=t.meta;return Boolean(!n&&("finally"===r||"done"===r||"doneData"===r||"fail"===r||"failData"===r||"inFlight"===r||"pending"===r))}(e))return t.name;const n=e.family.owners.find((e=>"effect"===e.meta.op));return n?`${d(n)}.${t.named}`:t.named}function f(e){const t=n(e),o=i(e);(0,r.default.createNode)({parent:[e],meta:{op:"watch"},family:{owners:e},regional:!0,node:[r.default.step.run({fn(e,n,r){let a=null==r?void 0:r.parent;const i=`[${t}] ${o} trace`;for(console.groupCollapsed(i);a;){var s;const{node:e,value:t}=a,{meta:n}=e;let r=n.op,o=d(e);var f;if(!o)o=null!==(f=u(e))&&void 0!==f?f:"";if("on"===r){var l,c,m;const t=d(null==e||null===(l=e.next)||void 0===l?void 0:l[0]);r=`${t}.${n.op}`,o=`${t}.${n.op}(${d(null===(c=a)||void 0===c||null===(m=c.parent)||void 0===m?void 0:m.node)})`}console.info(`<- [${r}] ${o}`,t),a=null===(s=a)||void 0===s?void 0:s.parent}console.groupEnd()}})]})}Object.defineProperty(t,"__esModule",{value:!0}),t.debug=function(...e){let t={trace:!1};const[n,...o]=e;r.default.is.unit(n)?s(n):t=n;for(const e of o)r.default.is.unit(e)&&s(e,t)}})),f=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.delay=function({source:e,timeout:t,target:n=(0,r.default.createEvent)({name:"target",sid:"-z2vw3w"})}){if(!r.default.is.unit(e))throw new TypeError("source must be a unit from effector");if(!r.default.is.unit(n))throw new TypeError("target must be a unit from effector");const o=function(e){if(r.default.is.store(e,{sid:"-va560a"})||"function"==typeof e||"number"==typeof e)return e;throw new TypeError(`'timeout' argument must be a function, Store, or a number. Passed "${typeof e}"`)}(t),a=(0,r.default.createEffect)((({payload:e,milliseconds:t})=>new Promise((n=>{setTimeout(n,t,e)}))),{name:"timerFx",sid:"-584o7j"});return(0,r.default.sample)({and:[{source:(0,r.default.combine)({and:[{milliseconds:o}],or:{name:"source",sid:"9rbdjo"}}),clock:e,fn:({milliseconds:e},t)=>({payload:t,milliseconds:"function"==typeof e?e(t):e}),target:a}],or:{sid:"-wmj29s"}}),(0,r.default.forward)({and:{from:a.doneData,to:n},or:{sid:"-vsadmx"}}),n}})),l=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.either=function e(t,n,o){if(r.default.is.store(t,{sid:"n60kh0"}))return(0,r.default.combine)({and:[t,n,o,(e,t,n)=>e?t:n],or:{sid:"8ceklb"}});return e(t)}})),c=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.empty=function(e){return e.map((e=>null===e))}})),m=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.equals=function(e,t){return(0,r.default.combine)({and:[e,t,(e,t)=>e===t],or:{sid:"jvku5g"}})}})),p=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.every=function(e,t){let n,o=[],a=()=>!1;Array.isArray(e)?(o=e,a=t):Array.isArray(e.stores)&&(o=e.stores,a=e.predicate);i=a,n="function"==typeof i?a:r.default.is.store(a,{sid:"sid3ut"})?a.map((e=>t=>e===t)):e=>e===a;var i;const u=(0,r.default.combine)({and:[o],or:{name:"$values",sid:"h09uhg"}}),s=n;return(0,r.default.combine)({and:[s,u,(e,t)=>t.every(e)],or:{sid:"hfkdw9"}})}})),y=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.format=function(e,...t){return(0,r.default.combine)({and:[t,t=>e.reduce(((n,r,o)=>n.concat(function(e,t){return t===e.length-1}(e,o)?r:`${r}${function(e){if(Array.isArray(e))return e.map((e=>String(e))).join(", ");return String(e)}(t[o])}`)),"")],or:{sid:"-yrbthp"}})}})),v=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.inFlight=function({effects:e,domain:t}){if(t){const e=t.createStore(0,{name:"$inFlight",sid:"-y7vg7t"});return t.onCreateEffect((t=>{e.on(t,(e=>e+1)).on(t.finally,(e=>e-1))})),e}return(0,r.default.combine)({and:[e.map((e=>e.inFlight)),e=>e.reduce(((e,t)=>e+t),0)],or:{sid:"ubqxa7"}})}})),b=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.interval=function({timeout:e,start:t,stop:n,leading:o=!1,trailing:a=!1}){const i=(0,r.default.createEvent)({name:"tick",sid:"uo9p3s"}),u=(0,r.default.createStore)(!1,{name:"$isRunning",sid:"-wxesi8"}),s=function(e){if(r.default.is.store(e,{sid:"6p7767"}))return e;if("number"==typeof e)return(0,r.default.createStore)(e,{and:{name:"$timeout"},sid:"5hw6se"});throw new TypeError(`timeout parameter in interval method should be number or Store. "${typeof e}" was passed`)}(e),d=u.map((e=>!e)),f=(0,r.default.createEvent)({name:"saveTimeout",sid:"as5clk"}),l=(0,r.default.createStore)(null,{name:"$timeoutId",sid:"-bh90bo"}).on(f,((e,t)=>t)),c=(0,r.default.createEvent)({name:"saveReject",sid:"-64swis"}),m=(0,r.default.createStore)((()=>{}),{name:"$rejecter",sid:"eabbu7"}).on(c,((e,t)=>t)),p=(0,r.default.createEffect)((e=>new Promise(((t,n)=>{const r=setTimeout(t,e);f(r),c(n)}))),{name:"timeoutFx",sid:"7lc3mj"}),y=(0,r.default.attach)({and:{source:[l,m],effect:([e,t])=>{t(),e&&clearTimeout(e)}},or:{name:"cleanupFx",sid:"pcn5jq"}});(0,r.default.guard)({and:[{clock:t,source:s,filter:d,target:p}],or:{sid:"-w5qmwp"}}),o&&(0,r.default.guard)({and:[{clock:t,filter:d,target:i}],or:{sid:"-vpslni"}});(0,r.default.sample)({and:[{clock:t,fn:()=>!0,target:u}],or:{sid:"-vaed34"}}),(0,r.default.guard)({and:[{clock:p.done,source:s,filter:u,target:p}],or:{sid:"-v73liy"}}),(0,r.default.sample)({and:[{clock:p.done,fn:()=>{},target:i}],or:{sid:"-urpcwu"}}),n&&(a&&(0,r.default.sample)({and:[{clock:n,target:i}],or:{sid:"-uanqf7"}}),u.on(n,(()=>!1)),(0,r.default.sample)({and:[{clock:n,target:y}],or:{sid:"6lcmyy"}}));return{tick:i,isRunning:u}}})),g=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.not=function(e){return e.map((e=>!e))}})),h=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.or=function(...e){return(0,r.default.combine)({and:[e,e=>e.reduce(((e,t)=>Boolean(e)||Boolean(t)))],or:{sid:"-44722k"}})}})),w=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.pending=function({effects:e,domain:t,of:o="some"}){if(!r.default.is.domain(t,{sid:"97b92c"})&&!e)throw new TypeError("domain or effects should be passed");if("some"!==o&&"every"!==o)throw new TypeError(`strategy parameter "of" can be "every" or "some". Passed: "${o}"`);let a=null!=e?e:[];const i=n[o];t&&(a=[],t.onCreateEffect((e=>a.push(e))));return(0,r.default.combine)({and:[a.map((e=>e.pending)),i],or:{sid:"a37bj0"}})};const n={some:e=>e.some(Boolean),every:e=>e.every(Boolean)}})),j=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.reset=function({clock:e,target:t}){const n=Array.isArray(t)?t:[t],r=Array.isArray(e)?e:[e];n.forEach((e=>{e.reset.call(e,r)}))}})),_=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.reshape=function({source:e,shape:t}){const n={};for(const r in t)if(r in t){const o=t[r];n[r]=e.map((e=>{const t=o(e);return void 0===t?null:t}))}return n}})),$=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.snapshot=function({source:e,clock:t,fn:n=(e=>e)}){const o=n(e.defaultState),a=t?(0,r.default.sample)({and:[e,t,n],or:{name:"onSnapshot",sid:"-auitd0"}}):(0,r.default.sample)({and:[{source:e,fn:n}],or:{name:"onSnapshot",sid:"-auir6n"}}),i=(0,r.default.createStore)(o,{name:"$snapshot",sid:"-7zyoaf"});return i.on(a,((e,t)=>t)),i}})),k=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.some=function(e,t){let n,o=[],a=()=>!1;Array.isArray(e)?(o=e,a=t):Array.isArray(e.stores)&&(o=e.stores,a=e.predicate);i=a,n="function"==typeof i?a:r.default.is.store(a,{sid:"zbwu0l"})?a.map((e=>t=>e===t)):e=>e===a;var i;const u=(0,r.default.combine)({and:[o],or:{name:"$values",sid:"-lv5do0"}}),s=n;return(0,r.default.combine)({and:[s,u,(e,t)=>t.some(e)],or:{sid:"-efc5w7"}})}})),E=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.splitMap=function({source:e,cases:t}){const n={};let o=r.default.is.store(e,{name:"current",sid:"-htjkz7"})?e.updates:e;for(const e in t)if(e in t){const r=t[e];n[e]=o.filterMap(r),o=o.filter({fn:e=>!r(e)})}return n.__=o,n}})),P=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.spread=function({targets:e,source:t=(0,r.default.createEvent)({name:"source",sid:"-fkbi3c"})}){for(const i in e)if(o=e,a=i,n.call(o,a)){const n=e[i],o=(0,r.default.guard)({and:[{source:t,greedy:!0,filter:e=>"object"==typeof e&&null!==e&&i in e}],or:{name:"hasTargetKey",sid:"-cov4g4"}});(0,r.default.sample)({and:[{greedy:!0,clock:o,fn:e=>e[i],target:n}],or:{sid:"lpn34j"}})}var o,a;return t};const n={}.hasOwnProperty})),M=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.status=function({effect:e,defaultValue:t="initial"}){const n=(0,r.default.createStore)(t,{name:"$status",sid:"abrgim"});return n.on(e,(()=>"pending")).on(e.done,(()=>"done")).on(e.fail,(()=>"fail")),n}})),O=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.throttle=function({source:e,timeout:t,target:n=(0,r.default.createEvent)({name:"target",sid:"r328r6"})}){if(!r.default.is.unit(e))throw new TypeError("source must be unit from effector");const o=function(e){if(r.default.is.store(e,{sid:"-hl6vqh"}))return e;if("number"==typeof e){if(e<0||!Number.isFinite(e))throw new Error(`timeout must be positive number or zero. Received: "${e}"`);return(0,r.default.createStore)(e,{and:{name:"$timeout"},sid:"pu8pon"})}throw new TypeError(`timeout parameter should be number or Store. "${typeof e}" was passed`)}(t),a=(0,r.default.createEffect)((e=>new Promise((t=>setTimeout(t,e)))),{name:"timerFx",sid:"-pyjx8k"}),i=(0,r.default.guard)({and:[{clock:e,filter:a.pending.map((e=>!e))}],or:{name:"start",sid:"-p67kgr"}});return(0,r.default.sample)({and:[{source:o,clock:i,target:a}],or:{sid:"-ievrvf"}}),(0,r.default.sample)({and:[{source:e,clock:a.done,target:n}],or:{sid:"-i01buo"}}),n}})),S=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.time=function({clock:e,getNow:t,initial:o}){const a=null!=t?t:n,i=(0,r.default.createEffect)(a,{name:"readNowFx",sid:"459ysb"}),u=(0,r.default.restore)(i,null!=o?o:a(),{name:"$time",sid:"-ys9vce"});return(0,r.default.forward)({and:{from:e,to:i},or:{sid:"rdje9v"}}),u};const n=()=>Date.now()})),x=a.and,T=i.combineEvents,A=u.condition,q=s.debounce,F=d.debug,z=f.delay,N=l.either,B=c.empty,I=m.equals,R=p.every,C=y.format,D=v.inFlight,K=b.interval,V=g.not,G=h.or,H=w.pending,J=j.reset,L=_.reshape,Q=$.snapshot,U=k.some,W=E.splitMap,X=P.spread,Y=M.status,Z=O.throttle,ee=S.time,te={and:x,combineEvents:T,condition:A,debounce:q,debug:F,delay:z,either:N,empty:B,equals:I,every:R,format:C,inFlight:D,interval:K,not:V,or:G,pending:H,reset:J,reshape:L,snapshot:Q,some:U,splitMap:W,spread:X,status:Y,throttle:Z,time:ee};e.and=x,e.combineEvents=T,e.condition=A,e.debounce=q,e.debug=F,e.default=te,e.delay=z,e.either=N,e.empty=B,e.equals=I,e.every=R,e.format=C,e.inFlight=D,e.interval=K,e.not=V,e.or=G,e.pending=H,e.reset=J,e.reshape=L,e.snapshot=Q,e.some=U,e.splitMap=W,e.spread=X,e.status=Y,e.throttle=Z,e.time=ee,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("effector")):"function"==typeof define&&define.amd?define(["exports","effector"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).patronum={},e.effector)}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(t);function o(e,t,n){return e(n={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&n.path)}},n.exports),n.exports}var a=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.and=function(...e){return(0,r.default.combine)({and:[e,e=>e.reduce(((e,t)=>Boolean(e)&&Boolean(t)))],or:{sid:"-rbm5ks"}})}})),i=o((function(e,t){function n(e){throw new Error(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.combineEvents=function({events:e,reset:t,target:o=(0,r.default.createEvent)({name:"target",sid:"3pez5"})}){r.default.is.unit(o)||n("target should be a unit");t&&!r.default.is.unit(t)&&n("reset should be a unit");return(0,r.default.withRegion)(o,(()=>{const n=Object.keys(e),a=Array.isArray(e)?[...n].fill(""):{},i=(0,r.default.createStore)(n.length,{name:"$counter",sid:"-dszn9a"}),u=(0,r.default.createStore)(a,{name:"$results",sid:"boz3x7"});i.reset((0,r.default.sample)({and:[o],or:{sid:"-8yzcn6"}})),u.reset(o),t&&(i.reset((0,r.default.sample)({and:[t],or:{sid:"-72suil"}})),u.reset(t));for(const a of n){const n=(0,r.default.createStore)(!1,{name:"$isDone",sid:"ucs7nc"}).on(e[a],(()=>!0)).reset(o);t&&n.reset(t),i.on(n,(e=>e-1)),u.on(e[a],((e,t)=>{const n=Array.isArray(e)?[...e]:{...e};return n[a]=t,n}))}(0,r.default.guard)({and:[{source:(0,r.default.sample)({and:[u,(0,r.default.merge)(Object.values(e),{name:"and",sid:"-l8g4ey"})],or:{name:"source",sid:"uf92v9"}}),filter:i.map((e=>0===e)),target:o}],or:{sid:"ciekm0"}})})),o}})),u=o((function(e,t){function n(e){return r.default.is.unit(e)?e.map((e=>!e)):t=>!e(t)}Object.defineProperty(t,"__esModule",{value:!0}),t.condition=function({if:e,then:t,else:o,source:a=(0,r.default.createEvent)({name:"source",sid:"epke23"})}){const i=r.default.is.unit(e)||(u=e,"function"==typeof u)?e:t=>t===e;var u;t&&o?(0,r.default.split)({and:[{source:a,match:{then:i,else:n(i)},cases:{then:t,else:o}}],or:{sid:"9tug3k"}}):t?(0,r.default.guard)({and:[{source:a,filter:i,target:t}],or:{sid:"abznoh"}}):o&&(0,r.default.guard)({and:[{source:a,filter:n(i),target:o}],or:{sid:"-eb29qp"}});return a}})),s=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.debounce=function({source:e,timeout:t,target:n}){if(!r.default.is.unit(e))throw new TypeError("source must be unit from effector");if(r.default.is.domain(e,{sid:"jne2ft"}))throw new TypeError("source cannot be domain");const o=function(e){if(r.default.is.store(e,{sid:"-2xmoh9"}))return e;if("number"==typeof e){if(e<0||!Number.isFinite(e))throw new Error(`timeout must be positive number or zero. Received: "${e}"`);return(0,r.default.createStore)(e,{and:{name:"$timeout"},sid:"-757cx6"})}throw new TypeError(`timeout parameter in interval method should be number or Store. "${typeof e}" was passed`)}(t),a=(0,r.default.createEvent)({name:"saveTimeoutId",sid:"eqtrwk"}),i=(0,r.default.createStore)(null,{and:{serialize:"ignore"},name:"$timeoutId",sid:"-5hlcyp"}).on(a,((e,t)=>t)),u=(0,r.default.createEvent)({name:"saveReject",sid:"-m6vk0"}),s=(0,r.default.createStore)(null,{and:{serialize:"ignore"},name:"$rejecter",sid:"tqvf32"}).on(u,((e,t)=>t)),d=null!=n?n:(0,r.default.createEvent)({name:"tick",sid:"-6wklwe"}),f=(0,r.default.createEffect)((({parameter:e,timeout:t,timeoutId:n,rejectPromise:r})=>(n&&clearTimeout(n),r&&r(),new Promise(((n,r)=>{u(r),a(setTimeout(n,t,e))})))),{name:"timerBaseFx",sid:"-xd98qa"}),l=(0,r.default.attach)({and:{source:{timeoutId:i,rejectPromise:s},mapParams:({parameter:e,timeout:t},{timeoutId:n,rejectPromise:r})=>({parameter:e,timeout:t,timeoutId:n,rejectPromise:r}),effect:f},or:{name:"timerFx",sid:"-4ab544"}});return s.reset(l.done),i.reset(l.done),(0,r.default.sample)({and:[{source:o,clock:e,fn:(e,t)=>({timeout:e,parameter:t}),target:l}],or:{sid:"m29k3f"}}),(0,r.default.forward)({and:{from:l.done.map((({result:e})=>e)),to:d},or:{sid:"-32ktwy"}}),d}})),d=o((function(e,t){function n(e){return r.default.is.store(e,{sid:"-i74wsd"})?"store":r.default.is.effect(e,{sid:"-i5hj0a"})?"effect":r.default.is.event(e,{sid:"-i3u587"})?"event":r.default.is.domain(e,{sid:"-i26rg4"})?"domain":r.default.is.unit(e)?"unit":"unknown"}function o(e,t,n=""){const r=n+i(e);e.watch((e=>{console.info(`[${t}] ${r}`,e)}))}function a(e){o(e.done,"effect",i(e)+"."),o(e.fail,"effect",i(e)+".")}function i(e){return e.compositeName&&e.compositeName.fullName?e.compositeName.fullName:e.shortName?e.shortName:e.name?e.name:""}function u(e){var t;const n=function({meta:e}){return"config"in e?e.config.loc:e.loc}(e);return n?`${null!==(t=n.file)&&void 0!==t?t:""}:${n.line}:${n.column}`:null}function s(e,t){const i=n(e);(r.default.is.store(e,{sid:"voorwi"})||r.default.is.effect(e,{sid:"-c68ujk"})||r.default.is.event(e,{sid:"-c68t31"}))&&(o(e,i),null!=t&&t.trace&&f(e)),r.default.is.effect(e,{sid:"w4mt3z"})&&a(e),r.default.is.domain(e,{sid:"w6tzhf"})&&(e.onCreateEvent((e=>{o(e,"event"),null!=t&&t.trace&&f(e)})),e.onCreateStore((e=>{o(e,"store"),null!=t&&t.trace&&f(e)})),e.onCreateEffect(a))}function d(e){if(!e)return"";const{meta:t}=e;if(!function(e){const t=function(e){return"graphite"in e?e.graphite:e}(e),{sid:n,named:r}=t.meta;return Boolean(!n&&("finally"===r||"done"===r||"doneData"===r||"fail"===r||"failData"===r||"inFlight"===r||"pending"===r))}(e))return t.name;const n=e.family.owners.find((e=>"effect"===e.meta.op));return n?`${d(n)}.${t.named}`:t.named}function f(e){const t=n(e),o=i(e);(0,r.default.createNode)({parent:[e],meta:{op:"watch"},family:{owners:e},regional:!0,node:[r.default.step.run({fn(e,n,r){let a=null==r?void 0:r.parent;const i=`[${t}] ${o} trace`;for(console.groupCollapsed(i);a;){var s;const{node:e,value:t}=a,{meta:n}=e;let r=n.op,o=d(e);var f;if(!o)o=null!==(f=u(e))&&void 0!==f?f:"";if("on"===r){var l,c,m;const t=d(null==e||null===(l=e.next)||void 0===l?void 0:l[0]);r=`${t}.${n.op}`,o=`${t}.${n.op}(${d(null===(c=a)||void 0===c||null===(m=c.parent)||void 0===m?void 0:m.node)})`}console.info(`<- [${r}] ${o}`,t),a=null===(s=a)||void 0===s?void 0:s.parent}console.groupEnd()}})]})}Object.defineProperty(t,"__esModule",{value:!0}),t.debug=function(...e){let t={trace:!1};const[n,...o]=e;r.default.is.unit(n)?s(n):t=n;for(const e of o)r.default.is.unit(e)&&s(e,t)}})),f=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.delay=function({source:e,timeout:t,target:n=(0,r.default.createEvent)({name:"target",sid:"-z2vw3w"})}){if(!r.default.is.unit(e))throw new TypeError("source must be a unit from effector");if(!r.default.is.unit(n))throw new TypeError("target must be a unit from effector");const o=function(e){if(r.default.is.store(e,{sid:"-va560a"})||"function"==typeof e||"number"==typeof e)return e;throw new TypeError(`'timeout' argument must be a function, Store, or a number. Passed "${typeof e}"`)}(t),a=(0,r.default.createEffect)((({payload:e,milliseconds:t})=>new Promise((n=>{setTimeout(n,t,e)}))),{name:"timerFx",sid:"-584o7j"});return(0,r.default.sample)({and:[{source:(0,r.default.combine)({and:[{milliseconds:o}],or:{name:"source",sid:"9rbdjo"}}),clock:e,fn:({milliseconds:e},t)=>({payload:t,milliseconds:"function"==typeof e?e(t):e}),target:a}],or:{sid:"-wmj29s"}}),(0,r.default.forward)({and:{from:a.doneData,to:n},or:{sid:"-vsadmx"}}),n}})),l=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.either=function e(t,n,o){if(r.default.is.store(t,{sid:"n60kh0"}))return(0,r.default.combine)({and:[t,n,o,(e,t,n)=>e?t:n],or:{sid:"8ceklb"}});return e(t)}})),c=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.empty=function(e){return e.map((e=>null===e))}})),m=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.equals=function(e,t){return(0,r.default.combine)({and:[e,t,(e,t)=>e===t],or:{sid:"jvku5g"}})}})),p=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.every=function(e,t){let n,o=[],a=()=>!1;Array.isArray(e)?(o=e,a=t):Array.isArray(e.stores)&&(o=e.stores,a=e.predicate);i=a,n="function"==typeof i?a:r.default.is.store(a,{sid:"sid3ut"})?a.map((e=>t=>e===t)):e=>e===a;var i;const u=(0,r.default.combine)({and:[o],or:{name:"$values",sid:"h09uhg"}}),s=n;return(0,r.default.combine)({and:[s,u,(e,t)=>t.every(e)],or:{sid:"hfkdw9"}})}})),y=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.format=function(e,...t){return(0,r.default.combine)({and:[t,t=>e.reduce(((n,r,o)=>n.concat(function(e,t){return t===e.length-1}(e,o)?r:`${r}${function(e){if(Array.isArray(e))return e.map((e=>String(e))).join(", ");return String(e)}(t[o])}`)),"")],or:{sid:"-yrbthp"}})}})),v=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.inFlight=function({effects:e,domain:t}){if(t){const e=t.createStore(0,{name:"$inFlight",sid:"-y7vg7t"});return t.onCreateEffect((t=>{e.on(t,(e=>e+1)).on(t.finally,(e=>e-1))})),e}return(0,r.default.combine)({and:[e.map((e=>e.inFlight)),e=>e.reduce(((e,t)=>e+t),0)],or:{sid:"ubqxa7"}})}})),b=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.interval=function({timeout:e,start:t,stop:n,leading:o=!1,trailing:a=!1}){const i=(0,r.default.createEvent)({name:"tick",sid:"uo9p3s"}),u=(0,r.default.createStore)(!1,{name:"$isRunning",sid:"-wxesi8"}),s=function(e){if(r.default.is.store(e,{sid:"71ao85"}))return e;if("number"==typeof e)return(0,r.default.createStore)(e,{and:{name:"$timeout"},sid:"5yxt6l"});throw new TypeError(`timeout parameter in interval method should be number or Store. "${typeof e}" was passed`)}(e),d=u.map((e=>!e)),f=(0,r.default.createEvent)({name:"saveTimeout",sid:"as5clk"}),l=(0,r.default.createStore)(null,{name:"$timeoutId",sid:"-bh90bo"}).on(f,((e,t)=>t)),c=(0,r.default.createEvent)({name:"saveReject",sid:"-64swis"}),m=(0,r.default.createStore)((()=>{}),{name:"$rejecter",sid:"eabbu7"}).on(c,((e,t)=>t)),p=(0,r.default.createEffect)((e=>new Promise(((t,n)=>{const r=setTimeout(t,e);f(r),c(n)}))),{name:"timeoutFx",sid:"7lc3mj"}),y=(0,r.default.attach)({and:{source:[l,m],effect:([e,t])=>{t(),e&&clearTimeout(e)}},or:{name:"cleanupFx",sid:"pcn5jq"}});(0,r.default.guard)({and:[{clock:t,source:s,filter:d,target:p}],or:{sid:"-w5qmwp"}}),o&&(0,r.default.guard)({and:[{clock:t,filter:d,target:i}],or:{sid:"-vpslni"}});(0,r.default.sample)({and:[{clock:t,fn:()=>!0,target:u}],or:{sid:"-vaed34"}}),(0,r.default.guard)({and:[{clock:p.done,source:s,filter:u,target:p}],or:{sid:"-v73liy"}}),(0,r.default.sample)({and:[{clock:p.done,filter:u,fn:()=>{},target:i}],or:{sid:"-urpcwu"}}),n&&(a&&(0,r.default.sample)({and:[{clock:n,target:i}],or:{sid:"-ua3xtu"}}),u.on(n,(()=>!1)),(0,r.default.sample)({and:[{clock:n,target:y}],or:{sid:"6lwfkb"}}));return{tick:i,isRunning:u}}})),g=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.not=function(e){return e.map((e=>!e))}})),h=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.or=function(...e){return(0,r.default.combine)({and:[e,e=>e.reduce(((e,t)=>Boolean(e)||Boolean(t)))],or:{sid:"-44722k"}})}})),w=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.pending=function({effects:e,domain:t,of:o="some"}){if(!r.default.is.domain(t,{sid:"97b92c"})&&!e)throw new TypeError("domain or effects should be passed");if("some"!==o&&"every"!==o)throw new TypeError(`strategy parameter "of" can be "every" or "some". Passed: "${o}"`);let a=null!=e?e:[];const i=n[o];t&&(a=[],t.onCreateEffect((e=>a.push(e))));return(0,r.default.combine)({and:[a.map((e=>e.pending)),i],or:{sid:"a37bj0"}})};const n={some:e=>e.some(Boolean),every:e=>e.every(Boolean)}})),j=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.reset=function({clock:e,target:t}){const n=Array.isArray(t)?t:[t],r=Array.isArray(e)?e:[e];n.forEach((e=>{e.reset(r)}))}})),_=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.reshape=function({source:e,shape:t}){const n={};for(const r in t)if(r in t){const o=t[r];n[r]=e.map((e=>{const t=o(e);return void 0===t?null:t}))}return n}})),k=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.snapshot=function({source:e,clock:t,fn:n=(e=>e)}){const o=n(e.defaultState),a=t?(0,r.default.sample)({and:[e,t,n],or:{name:"onSnapshot",sid:"-auitd0"}}):(0,r.default.sample)({and:[{source:e,fn:n}],or:{name:"onSnapshot",sid:"-auir6n"}}),i=(0,r.default.createStore)(o,{name:"$snapshot",sid:"-7zyoaf"});return i.on(a,((e,t)=>t)),i}})),$=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.some=function(e,t){let n,o=[],a=()=>!1;Array.isArray(e)?(o=e,a=t):Array.isArray(e.stores)&&(o=e.stores,a=e.predicate);i=a,n="function"==typeof i?a:r.default.is.store(a,{sid:"zbwu0l"})?a.map((e=>t=>e===t)):e=>e===a;var i;const u=(0,r.default.combine)({and:[o],or:{name:"$values",sid:"-lv5do0"}}),s=n;return(0,r.default.combine)({and:[s,u,(e,t)=>t.some(e)],or:{sid:"-efc5w7"}})}})),E=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.splitMap=function({source:e,cases:t}){const n={};let o=r.default.is.store(e,{name:"current",sid:"-htjkz7"})?e.updates:e;for(const e in t)if(e in t){const r=t[e];n[e]=o.filterMap(r),o=o.filter({fn:e=>!r(e)})}return n.__=o,n}})),P=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.spread=function({targets:e,source:t=(0,r.default.createEvent)({name:"source",sid:"-fkbi3c"})}){for(const i in e)if(o=e,a=i,n.call(o,a)){const n=e[i],o=(0,r.default.guard)({and:[{source:t,greedy:!0,filter:e=>"object"==typeof e&&null!==e&&i in e}],or:{name:"hasTargetKey",sid:"-cov4g4"}});(0,r.default.sample)({and:[{greedy:!0,clock:o,fn:e=>e[i],target:n}],or:{sid:"lpn34j"}})}var o,a;return t};const n={}.hasOwnProperty})),M=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.status=function({effect:e,defaultValue:t="initial"}){const n=(0,r.default.createStore)(t,{name:"$status",sid:"abrgim"});return n.on(e,(()=>"pending")).on(e.done,(()=>"done")).on(e.fail,(()=>"fail")),n}})),O=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.throttle=function({source:e,timeout:t,target:n=(0,r.default.createEvent)({name:"target",sid:"r328r6"})}){if(!r.default.is.unit(e))throw new TypeError("source must be unit from effector");const o=function(e){if(r.default.is.store(e,{sid:"-hl6vqh"}))return e;if("number"==typeof e){if(e<0||!Number.isFinite(e))throw new Error(`timeout must be positive number or zero. Received: "${e}"`);return(0,r.default.createStore)(e,{and:{name:"$timeout"},sid:"pu8pon"})}throw new TypeError(`timeout parameter should be number or Store. "${typeof e}" was passed`)}(t),a=(0,r.default.createEffect)((e=>new Promise((t=>setTimeout(t,e)))),{name:"timerFx",sid:"-pyjx8k"}),i=(0,r.default.guard)({and:[{clock:e,filter:a.pending.map((e=>!e))}],or:{name:"start",sid:"-p67kgr"}});return(0,r.default.sample)({and:[{source:o,clock:i,target:a}],or:{sid:"-ievrvf"}}),(0,r.default.sample)({and:[{source:e,clock:a.done,target:n}],or:{sid:"-i01buo"}}),n}})),x=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.time=function({clock:e,getNow:t,initial:o}){const a=null!=t?t:n,i=(0,r.default.createEffect)(a,{name:"readNowFx",sid:"459ysb"}),u=(0,r.default.restore)(i,null!=o?o:a(),{name:"$time",sid:"-ys9vce"});return(0,r.default.forward)({and:{from:e,to:i},or:{sid:"rdje9v"}}),u};const n=()=>Date.now()})),S=a.and,T=i.combineEvents,A=u.condition,F=s.debounce,q=d.debug,z=f.delay,N=l.either,B=c.empty,I=m.equals,R=p.every,C=y.format,D=v.inFlight,K=b.interval,V=g.not,G=h.or,H=w.pending,J=j.reset,L=_.reshape,Q=k.snapshot,U=$.some,W=E.splitMap,X=P.spread,Y=M.status,Z=O.throttle,ee=x.time,te={and:S,combineEvents:T,condition:A,debounce:F,debug:q,delay:z,either:N,empty:B,equals:I,every:R,format:C,inFlight:D,interval:K,not:V,or:G,pending:H,reset:J,reshape:L,snapshot:Q,some:U,splitMap:W,spread:X,status:Y,throttle:Z,time:ee};e.and=S,e.combineEvents=T,e.condition=A,e.debounce=F,e.debug=q,e.default=te,e.delay=z,e.either=N,e.empty=B,e.equals=I,e.every=R,e.format=C,e.inFlight=D,e.interval=K,e.not=V,e.or=G,e.pending=H,e.reset=J,e.reshape=L,e.snapshot=Q,e.some=U,e.splitMap=W,e.spread=X,e.status=Y,e.throttle=Z,e.time=ee,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=patronum.umd.js.map |
751
README.md
@@ -10,5 +10,6 @@ # <img src="logo.svg" title="effector patronum" alt="Effector Patronum logo" width="640px"> | ||
- 🎲 Try it online: [StackBlitz](stackblitz) | [Codesandbox](codesandbox) | [Playground](try-patronum-share) | ||
- 📦 Source: [JSdeliver](jsdelivr) | [Unpkg](unpkg) | [NPM](npm) | [GitHub](github) | ||
- 🦉 Say about it: [Twitter](twitter-share) | ||
- 🎲 Try it online: [StackBlitz][stackblitz] | [Codesandbox][codesandbox] | [Playground][try-patronum-share] | ||
- 📚 Read documentation: [patronum.effector.dev][documentation] | ||
- 📦 Source: [JSdeliver][jsdelivr] | [Unpkg][unpkg] | [NPM][npm] | [GitHub][github] | ||
- 🦉 Say about it: [Twitter][twitter-share] | ||
@@ -23,39 +24,4 @@ [stackblitz]: https://stackblitz.com/edit/effector-react | ||
[twitter-share]: https://twitter.com/intent/tweet?text=I%20used%20patronum!%0AGoing%20to%20Mars%20with%20%40effectorjs%20-%20data-flow%20powered%20tool%20to%20implement%20business%20logic.%0A%0Ahttps%3A%2F%2Fgithub.com%2Feffector%2Fpatronum%0A | ||
[documentation]: https://patronum.effector.dev | ||
## Table of contents | ||
### Predicate | ||
- [Condition](#condition) — Trigger then or else by condition. | ||
- [Some](#some) — Checks that state in at least one store passes the predicate test. | ||
- [Every](#every) — Checks that state in each store passes the predicate test. | ||
- [Reset](#reset) — Reset all passed stores by clock. | ||
### Effect | ||
- [Pending](#pending) — Checks that has effects in pending state. | ||
- [InFlight](#inflight) — Counts all pending effects | ||
- [Status](#status) — Return text representation of effect state. | ||
### Timeouts | ||
- [Debounce](#debounce) — Creates event which waits until time passes after previous trigger. | ||
- [Delay](#delay) — Delays the call of the event by defined timeout. | ||
- [Throttle](#throttle) — Creates event which triggers at most once per timeout. | ||
- [Interval](#interval) — Creates a dynamic interval with any timeout. | ||
- [Time](#time) — Allows reading current timestamp by triggering clock. | ||
### Combination/Decomposition | ||
- [CombineEvents](#combineevents) — Wait for all passed events is triggered. | ||
- [Reshape](#reshape) — Destructure one store to different stores | ||
- [SplitMap](#splitmap) — Split event to different events and map data. | ||
- [Spread](#spread) — Send fields from object to same targets. | ||
- [Snapshot](#snapshot) — Create store value snapshot. | ||
- [Format](#format) — Combine stores to a string literal. | ||
### Debug | ||
- [Debug](#debug) — Log triggers of passed units. | ||
## 💿 Install now | ||
@@ -67,2 +33,6 @@ | ||
npm install patronum | ||
# or | ||
yarn add patronum | ||
# or | ||
pnpm add patronum | ||
``` | ||
@@ -73,706 +43,17 @@ | ||
```ts | ||
import { createEffect } from "effector" | ||
import { status } from "patronum" | ||
import { createEffect } from 'effector'; | ||
import { status } from 'patronum'; | ||
const userLoadFx = createEffect() | ||
const $status = status({ effect: userLoadFx }) | ||
const userLoadFx = createEffect(); | ||
const $status = status({ effect: userLoadFx }); | ||
``` | ||
## 🐞 Debug and log | ||
You can read more at [documentation](https://patronum.effector.dev/docs/installation). | ||
Sometimes we need to log each event and change in our application, here we need to install [`effector-logger`](https://github.com/effector/logger): | ||
```bash | ||
npm install --dev effector-logger | ||
``` | ||
We have some variants how to use logger to debug our applications. Please, don't merge all variants, **it's not compatible**! | ||
### 1. Temporarily change imports in certain modules | ||
If we need to debug just some list of modules, we can just replace `effector` import to `effector-logger`: | ||
```diff | ||
-import { createStore, createEvent, sample } from 'effector' | ||
+import { createStore, createEvent, sample } from 'effector-logger' | ||
import { spread } from 'patronum' | ||
``` | ||
Next just open the Console in browser DevTools. But here we see strange names of the stores and events like "ashg7d". | ||
This means we need to use [effector babel plugin](https://effector.dev/docs/api/effector/babel-plugin/). | ||
> Note: You don't need to install it separately, because its bundled into effector package. | ||
```json5 | ||
// .babelrc | ||
{ | ||
"plugins": [ | ||
["effector/babel-plugin", { "importName": "effector-logger" }], // Just add this line into your .babelrc or babel.config.js plugins section. | ||
], | ||
"presets": [ | ||
"patronum/babel-preset" // Add this line at the end of the all presets | ||
] | ||
} | ||
``` | ||
### 2. Use `effector-logger/babel-plugin` to automatically replace all imports in development | ||
But some projects already use `effector/babel-plugin`, and for correct work with `effector-logger` we need **just one** instance of babel plugin. | ||
This means that [effector-logger has its own babel-plugin](https://github.com/effector/logger#usage).<br/> | ||
**Don't use `effector/babel-plugin` simultaneously with `effector-logger/babel-plugin`!** Use just one at the time, for example: for the dev environment use `effector-logger/babel-plugin`, but for production use `effector/babel-plugin`. | ||
<details> | ||
<summary> | ||
How to setup `.babelrc` | ||
</summary> | ||
```json5 | ||
// .babelrc | ||
{ | ||
"presets": [ | ||
"patronum/babel-preset" // Add this line at the end of the all presets in the root of the file | ||
], | ||
"env": { | ||
"development": { | ||
"plugins": [ | ||
["effector-logger/babel-plugin", {}] // In the curly brackets you can pass options for logger AND effector | ||
] | ||
}, | ||
"production": { | ||
"plugins": [ | ||
["effector/babel-plugin", {}] // In the curly brackets you can pass options for effector | ||
] | ||
}, | ||
}, | ||
} | ||
``` | ||
If you need to pass factories, here you need to duplicate your array: | ||
```json5 | ||
// .babelrc | ||
{ | ||
"env": { | ||
"development": { | ||
"plugins": [ | ||
["effector-logger/babel-plugin", { | ||
"effector": { "factories": ["src/shared/lib/compare", "src/shared/lib/timing"] } | ||
}] | ||
] | ||
}, | ||
"production": { | ||
"plugins": [ | ||
["effector/babel-plugin", { "factories": ["src/shared/lib/compare", "src/shared/lib/timing"] }] | ||
] | ||
}, | ||
}, | ||
} | ||
``` | ||
Also, you need to build your project with `BABEL_ENV=development` for dev and `BABEL_ENV=production` for prod, to choose the appropriate option in the `"env"` section. | ||
Relative links: | ||
- https://babeljs.io/docs/en/options#env | ||
- https://babeljs.io/docs/en/config-files | ||
</details> | ||
<details> | ||
<summary> | ||
How to setup `babel.config.js` | ||
</summary> | ||
```js | ||
module.exports = (api) => { | ||
const isDev = api.env("development") | ||
return { | ||
presets: [ | ||
// Add next line at the end of presets list | ||
"patronum/babel-preset", | ||
], | ||
plugins: [ | ||
// Add next lines at the end of the plugins list | ||
isDev | ||
? ["effector-logger/babel-plugin", {}] | ||
: ["effector/babel-plugin", {}] | ||
] | ||
} | ||
} | ||
``` | ||
If you want to pass factories to the effector plugin, you need just put it to the variable: | ||
```js | ||
module.exports = (api) => { | ||
const isDev = api.env("development") | ||
// Here your factories | ||
const factories = ["src/shared/lib/compare", "src/shared/lib/timing"] | ||
return { | ||
plugins: [ | ||
isDev | ||
// All effector options passed into `effector` property | ||
? ["effector-logger/babel-plugin", { effector: { factories } }] | ||
: ["effector/babel-plugin", { factories }] | ||
] | ||
} | ||
} | ||
``` | ||
Also, you need to build your project with `BABEL_ENV=development` for dev and `BABEL_ENV=production` for prod, to choose the appropriate option in the `"env"` section. | ||
Relative links: | ||
- https://babeljs.io/docs/en/options#env | ||
- https://babeljs.io/docs/en/config-files | ||
</details> | ||
### 3. CRA support with [macros](https://github.com/kentcdodds/babel-plugin-macros) | ||
[`babel-plugin-macros`](https://github.com/kentcdodds/babel-plugin-macros) is bundled into CRA, so we can use it due CRA don't support adding babel plugins into `.babelrc` or `babel.config.js`. | ||
Just import from `patronum/macro` and `effector-logger/macro`, and use as early: | ||
```ts | ||
import { createStore, createEffect, sample } from "effector-logger/macro" | ||
import { status, splitMap, combineEvents } from "patronum/macro"; | ||
``` | ||
> - Warning: babel-plugin-macros do not support `import * as name`! | ||
> - Note: Since release of patronum@2.0.0 it is required to use babel-plugin-macros@3.0.0 or higher. | ||
> - Please note, that react-scripts@4.0.3 and older **uses outdated version** of this plugin - you can either use [yarn resolutions](https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/) or use react-scripts@5.0.0 or higher. | ||
## Migration guide | ||
<details> | ||
<summary> | ||
show / hide | ||
</summary> | ||
Patronum had 3 breaking changes: 1) from `0.14` to `0.100`, 2) from `0.100` to `0.110`, 3) from `0.110` to `1.0` | ||
We have [migration guide](https://patronum.effector.dev/docs/migration-guide). | ||
### v2.0.0 | ||
Removed support of effector v21. Now the minimum supported version is `v22.1.2`. | ||
### v0.110 | ||
From `v0.110.0` patronum removed support of effector v20. Now minimum supported version is `v21.4`. | ||
Please, before upgrade review release notes of [`effector v21`](https://github.com/effector/effector/releases/tag/effector%4021.0.0). | ||
### v0.100 | ||
From `v0.100.0` patronum introduced object arguments form with **BREAKING CHANGES**. Please, review [migration guide](./MIGRATION.md) before upgrade from `v0.14.x` on your project. | ||
</details> | ||
--- | ||
## Condition | ||
[Method documentation & API](/src/condition) | ||
```ts | ||
import { createEvent } from 'effector'; | ||
import { condition } from 'patronum/condition'; | ||
const trigger = createEvent<string>(); | ||
const longString = createEvent<string>(); | ||
const shortString = createEvent<string>(); | ||
condition({ | ||
source: trigger, | ||
if: (string) => string.length > 6, | ||
then: longString, | ||
else: shortString, | ||
}); | ||
longString.watch((str) => console.log('long', str)); | ||
shortString.watch((str) => console.log('short', str)); | ||
trigger('hi'); // => short hi | ||
trigger('welcome'); // => long welcome | ||
``` | ||
[Try it](https://share.effector.dev/vGMekp9H 'in playground') | ||
## Delay | ||
[Method documentation & API](/src/delay) | ||
```ts | ||
import { createEvent } from 'effector'; | ||
import { delay } from 'patronum/delay'; | ||
const trigger = createEvent<string>(); // createStore or createEffect | ||
// `timeout` also supports (payload) => number and Store<number> | ||
const delayed = delay({ source: trigger, timeout: 300 }); | ||
delayed.watch((payload) => console.info('triggered', payload)); | ||
trigger('hello'); | ||
// after 300ms | ||
// => triggered hello | ||
``` | ||
[Try it](https://share.effector.dev/vWwXoL4n) | ||
## Debounce | ||
[Method documentation & API](/src/debounce) | ||
```ts | ||
import { createEvent } from 'effector'; | ||
import { debounce } from 'patronum/debounce'; | ||
// You should call this event | ||
const trigger = createEvent<number>(); | ||
const target = debounce({ source: trigger, timeout: 200 }); | ||
target.watch((payload) => console.info('debounced', payload)); | ||
trigger(1); | ||
trigger(2); | ||
trigger(3); | ||
trigger(4); | ||
// after 200ms | ||
// => debounced 4 | ||
``` | ||
[Try it](https://share.effector.dev/ZFXJbv1b) | ||
## Throttle | ||
[Method documentation & API](/src/throttle) | ||
```ts | ||
import { createEvent } from 'effector'; | ||
import { throttle } from 'patronum/throttle'; | ||
// You should call this event | ||
const trigger = createEvent<number>(); | ||
const target = throttle({ source: trigger, timeout: 200 }); | ||
target.watch((payload) => console.info('throttled', payload)); | ||
trigger(1); | ||
trigger(2); | ||
trigger(3); | ||
trigger(4); | ||
// 200ms after trigger(1) | ||
// => throttled 4 | ||
``` | ||
[Try it](https://share.effector.dev/OH0TUJUH) | ||
## Interval | ||
[Method documentation & API](/src/interval) | ||
```ts | ||
import { createStore, createEvent } from 'effector'; | ||
import { interval } from 'patronum'; | ||
const startCounter = createEvent(); | ||
const stopCounter = createEvent(); | ||
const $counter = createStore(0); | ||
const { tick } = interval({ | ||
timeout: 500, | ||
start: startCounter, | ||
stop: stopCounter, | ||
}); | ||
$counter.on(tick, (number) => number + 1); | ||
$counter.watch((value) => console.log('COUNTER', value)); | ||
startCounter(); | ||
setTimeout(() => stopCounter(), 5000); | ||
``` | ||
[Try it](https://share.effector.dev/EOVzc3df) | ||
## Debug | ||
[Method documentation & API](/src/debug) | ||
```ts | ||
import { createStore, createEvent, createEffect } from 'effector'; | ||
import { debug } from 'patronum/debug'; | ||
const event = createEvent(); | ||
const effect = createEffect().use((payload) => Promise.resolve('result' + payload)); | ||
const $store = createStore(0) | ||
.on(event, (state, value) => state + value) | ||
.on(effect.done, (state) => state * 10); | ||
debug($store, event, effect); | ||
event(5); | ||
effect('demo'); | ||
// => [store] $store 1 | ||
// => [event] event 5 | ||
// => [store] $store 6 | ||
// => [effect] effect demo | ||
// => [effect] effect.done {"params":"demo", "result": "resultdemo"} | ||
// => [store] $store 60 | ||
``` | ||
[Try it](https://share.effector.dev/iFi3CahC) | ||
## Status | ||
[Method documentation & API](/src/status) | ||
```ts | ||
import { createEvent, createEffect } from 'effector'; | ||
import { status } from 'patronum/status'; | ||
const effect = createEffect().use(() => Promise.resolve(null)); | ||
const $status = status({ effect }); | ||
$status.watch((value) => console.log(`status: ${value}`)); | ||
// => status: "initial" | ||
effect(); | ||
// => status: "pending" | ||
// => status: "done" | ||
``` | ||
[Try it](https://share.effector.dev/6VRR39iC) | ||
## Spread | ||
[Method documentation & API](/src/spread) | ||
```ts | ||
import { createEvent, createStore } from 'effector'; | ||
import { spread } from 'patronum/spread'; | ||
const trigger = createEvent<{ first: string; second: string }>(); | ||
const $first = createStore(''); | ||
const $second = createStore(''); | ||
spread({ | ||
source: trigger, | ||
targets: { | ||
first: $first, | ||
second: $second, | ||
}, | ||
}); | ||
trigger({ first: 'Hello', second: 'World' }); | ||
$first.watch(console.log); // => Hello | ||
$second.watch(console.log); // => World | ||
``` | ||
[Try it](https://share.effector.dev/DmiLrYAC) | ||
## Snapshot | ||
[Method documentation & API](/src/snapshot) | ||
```ts | ||
import { restore, createEvent } from 'effector'; | ||
import { snapshot } from 'patronum/snapshot'; | ||
const changeText = createEvent<string>(); | ||
const createSnapshot = createEvent(); | ||
const $original = restore(changeText, 'Example'); | ||
const $snapshot = snapshot({ | ||
source: $original, | ||
clock: createSnapshot, | ||
}); | ||
changeText('New text'); | ||
// $original -> Store with "New text" | ||
// $snapshot -> Store with "Example" | ||
createSnapshot(); | ||
// $original -> Store with "New text" | ||
// $snapshot -> Store with "New text" | ||
``` | ||
[Try it](https://share.effector.dev/HcsNyGfM) | ||
## CombineEvents | ||
[Method documentation & API](/src/combine-events) | ||
Call target event when all event from object/array is triggered | ||
```ts | ||
import { createEvent } from 'effector'; | ||
import { combineEvents } from 'patronum/combine-events'; | ||
const event1 = createEvent(); | ||
const event2 = createEvent(); | ||
const event3 = createEvent(); | ||
const reset = createEvent(); | ||
const event = combineEvents({ | ||
reset, | ||
events: { | ||
event1, | ||
event2, | ||
event3, | ||
}, | ||
}); | ||
event.watch((object) => console.log('triggered', object)); | ||
event1(true); // nothing | ||
event2('demo'); // nothing | ||
event3(5); // => triggered { event1: true, event2: "demo", event3: 5 } | ||
event1(true); // nothing | ||
event2('demo'); // nothing | ||
reset(); | ||
event3(5); // nothing | ||
event1(true); // nothing | ||
event2('demo'); // nothing | ||
event3(5); // => triggered { event1: true, event2: "demo", event3: 5 } | ||
``` | ||
[Try it](https://share.effector.dev/nzc276i0) | ||
## Every | ||
[Method documentation & API](/src/every) | ||
```ts | ||
import { createStore } from 'effector'; | ||
import { every } from 'patronum/every'; | ||
const $isPasswordCorrect = createStore(true); | ||
const $isEmailCorrect = createStore(true); | ||
const $isFormCorrect = every([$isPasswordCorrect, $isEmailCorrect], true); | ||
$isFormCorrect.watch(console.log); // => true | ||
``` | ||
[Try it](https://share.effector.dev/Q9ZZSXoZ) | ||
## InFlight | ||
[Method documentation & API](/src/in-flight) | ||
```ts | ||
import { createEffect } from 'effector'; | ||
import { inFlight } from 'patronum/in-flight'; | ||
const firstFx = createEffect().use(() => Promise.resolve(1)); | ||
const secondFx = createEffect().use(() => Promise.resolve(2)); | ||
const $allInFlight = inFlight({ effects: [firstFx, secondFx] }); | ||
firstFx(); | ||
secondFx(); | ||
firstFx(); | ||
$allInFlight.watch(console.log); | ||
// => 3 | ||
// => 2 | ||
// => 1 | ||
// => 0 | ||
``` | ||
[Try it](https://share.effector.dev/NYNJEbpH) | ||
## Pending | ||
[Method documentation & API](/src/pending) | ||
```ts | ||
import { createEffect } from 'effector'; | ||
import { pending } from 'patronum/pending'; | ||
const loadFirst = createEffect().use(() => Promise.resolve(null)); | ||
const loadSecond = createEffect().use(() => Promise.resolve(2)); | ||
const $processing = pending({ effects: [loadFirst, loadSecond] }); | ||
$processing.watch((processing) => console.info(`processing: ${processing}`)); | ||
// => processing: false | ||
loadFirst(); | ||
loadSecond(); | ||
// => processing: true | ||
// => processing: false | ||
``` | ||
[Try it](https://share.effector.dev/TaxOi6nT) | ||
## Some | ||
[Method documentation & API](/src/some) | ||
```ts | ||
import { createStore, restore, createEvent } from 'effector'; | ||
import { some } from 'patronum/some'; | ||
const widthSet = createEvent<number>(); | ||
const $width = restore(widthSet, 820); | ||
const $height = createStore(620); | ||
const $tooBig = some({ | ||
predicate: (size) => size > 800, | ||
stores: [$width, $height], | ||
}); | ||
$tooBig.watch((big) => console.log('big', big)); // => big true | ||
widthSet(200); | ||
// => big false | ||
``` | ||
[Try it](https://share.effector.dev/NBxHl8xR) | ||
## Reshape | ||
[Method documentation & API](/src/reshape) | ||
```ts | ||
import { createStore } from 'effector'; | ||
import { reshape } from 'patronum/reshape'; | ||
const $original = createStore<string>('Hello world'); | ||
const parts = reshape({ | ||
source: $original, | ||
shape: { | ||
length: (string) => string.length, | ||
first: (string) => string.split(' ')[0] || '', | ||
second: (string) => string.split(' ')[1] || '', | ||
}, | ||
}); | ||
parts.length.watch(console.info); // 11 | ||
parts.first.watch(console.log); // "Hello" | ||
parts.second.watch(console.log); // "world" | ||
``` | ||
[Try it](https://share.effector.dev/VbNg7nlV) | ||
## SplitMap | ||
[Method documentation & API](/src/split-map) | ||
```ts | ||
import { createEvent } from 'effector'; | ||
import { splitMap } from 'patronum/split-map'; | ||
type Action = | ||
| { type: 'update'; content: string } | ||
| { type: 'created'; value: number } | ||
| { type: 'another' }; | ||
const serverActionReceived = createEvent<Action>(); | ||
const received = splitMap({ | ||
source: serverActionReceived, | ||
cases: { | ||
update: (action) => (action.type === 'update' ? action.content : undefined), | ||
created: (action) => (action.type === 'created' ? action.value : undefined), | ||
}, | ||
}); | ||
received.update.watch((payload) => | ||
console.info('update received with content:', payload), | ||
); | ||
received.created.watch((payload) => console.info('created with value:', payload)); | ||
received.__.watch((payload) => console.info('unknown action received:', payload)); | ||
serverActionReceived({ type: 'created', value: 1 }); | ||
// => created with value: 1 | ||
serverActionReceived({ type: 'update', content: 'demo' }); | ||
// => update received with content: "demo" | ||
serverActionReceived({ type: 'another' }); | ||
// => unknown action received: { type: "another" } | ||
``` | ||
[Try it](https://share.effector.dev/RRf57lK4) | ||
## Time | ||
[Method documentation & API](/src/time) | ||
```ts | ||
import { createEvent } from 'effector'; | ||
import { time } from 'patronum/time'; | ||
const readTime = createEvent(); | ||
const $now = time({ clock: readTime }); | ||
$now.watch((now) => console.log('Now is:', now)); | ||
// => Now is: 1636914286675 | ||
readTime(); | ||
// => Now is: 1636914300691 | ||
``` | ||
[Try it](https://share.effector.dev/BFlhNGvk) | ||
## Format | ||
[Method documentation & API](/src/format) | ||
```ts | ||
import { createStore } from 'effector'; | ||
import { format } from 'patronum'; | ||
const $firstName = createStore('John'); | ||
const $lastName = createStore('Doe'); | ||
const $fullName = format`${$firstName} ${$lastName}`; | ||
$fullName.watch(console.log); | ||
// => John Doe | ||
``` | ||
[Try it](https://share.effector.dev/IafeiFkF) | ||
## Reset | ||
```ts | ||
import { createEvent, createStore } from 'effector'; | ||
import { reset } from 'patronum/reset'; | ||
const pageUnmounted = createEvent(); | ||
const userSessionFinished = createEvent(); | ||
const $post = createStore(null); | ||
const $comments = createStore([]); | ||
const $draftComment = createStore(''); | ||
reset({ | ||
clock: [pageUnmounted, userSessionFinished], | ||
target: [$post, $comments, $draftComment], | ||
}); | ||
``` | ||
[Try it](https://share.effector.dev/06hpVftG) | ||
# Development | ||
@@ -779,0 +60,0 @@ |
@@ -9,4 +9,4 @@ export function reset(_ref) { | ||
targets.forEach(target => { | ||
target.reset.call(target, clocks); | ||
target.reset(clocks); | ||
}); | ||
} |
import { Effect, Event, Store } from 'effector'; | ||
export declare function time<T = number>({ clock, getNow, initial, }: { | ||
export declare function time<Time = number>({ clock, getNow, initial, }: { | ||
clock: Event<any> | Effect<any, any, any> | Store<any>; | ||
getNow?: () => T; | ||
initial?: T; | ||
}): Store<T>; | ||
getNow?: () => Time; | ||
initial?: Time; | ||
}): Store<Time>; |
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
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
2989
292755
116
66