Comparing version 1.7.0 to 1.8.0
{ | ||
"name": "patronum", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "☄️ Effector utility library delivering modularity and convenience", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("effector"));function r(e,t,r){return e(r={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&r.path)}},r.exports),r.exports}var n=r((function(e,r){function n(e){throw new Error(e)}Object.defineProperty(r,"__esModule",{value:!0}),r.combineEvents=function({events:e,reset:r,target:o=(0,t.createEvent)({name:"target",sid:"3pez5"})}){t.is.unit(o)||n("target should be a unit");r&&!t.is.unit(r)&&n("reset should be a unit");return(0,t.withRegion)(o,(()=>{const n=Object.keys(e),i=Array.isArray(e)?[...n].fill(""):{},s=(0,t.createStore)(n.length,{name:"$counter",sid:"-dszn9a"}),a=(0,t.createStore)(i,{name:"$results",sid:"boz3x7"});s.reset((0,t.sample)({and:[o],or:{sid:"-8yzcn6"}})),a.reset(o),r&&(s.reset((0,t.sample)({and:[r],or:{sid:"-72suil"}})),a.reset(r));for(const i of n){const n=(0,t.createStore)(!1,{name:"$isDone",sid:"ucs7nc"}).on(e[i],(()=>!0)).reset(o);r&&n.reset(r),s.on(n,(e=>e-1)),a.on(e[i],((e,t)=>{const r=Array.isArray(e)?[...e]:{...e};return r[i]=t,r}))}(0,t.guard)({and:[{source:(0,t.sample)({and:[a,(0,t.merge)(Object.values(e),{name:"and",sid:"-l8g4ey"})],or:{name:"source",sid:"uf92v9"}}),filter:s.map((e=>0===e)),target:o}],or:{sid:"ciekm0"}})})),o}})),o=r((function(e,r){function n(e){return t.is.unit(e)?e.map((e=>!e)):t=>!e(t)}Object.defineProperty(r,"__esModule",{value:!0}),r.condition=function({if:e,then:r,else:o,source:i=(0,t.createEvent)({name:"source",sid:"epke23"})}){const s=t.is.unit(e)||(a=e,"function"==typeof a)?e:t=>t===e;var a;r&&(0,t.guard)({and:[{source:i,filter:s,target:r}],or:{sid:"9tug3k"}});o&&(0,t.guard)({and:[{source:i,filter:n(s),target:o}],or:{sid:"a9shb1"}});return i}})),i=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.debounce=function({source:e,timeout:r,target:n}){if(!t.is.unit(e))throw new TypeError("source must be unit from effector");if(t.is.domain(e,{sid:"iu8yzo"}))throw new TypeError("source cannot be domain");if("number"!=typeof r||r<0||!Number.isFinite(r))throw new Error(`timeout must be positive number or zero. Received: "${r}"`);let o,i;const s=n??(0,t.createEvent)({name:"tick",sid:"-xw52dh"}),a=(0,t.createEffect)((e=>(clearTimeout(i),o&&o(),new Promise(((t,n)=>{o=n,i=setTimeout(t,r,e)})))),{name:"timerFx",sid:"m8kfsq"});return(0,t.forward)({and:{from:e,to:a},or:{sid:"k4foqk"}}),(0,t.forward)({and:{from:a.done.map((({result:e})=>e)),to:s},or:{sid:"k76npd"}}),s}})),s=r((function(e,r){function n(e){return t.is.store(e,{sid:"-j30z7b"})?"store":t.is.effect(e,{sid:"-j1dlf8"})?"effect":t.is.event(e,{sid:"-io6j6k"})?"event":t.is.domain(e,{sid:"-imj5eh"})?"domain":t.is.unit(e)?"unit":"unknown"}function o(e,t,r=""){const n=r+s(e);e.watch((e=>{console.info(`[${t}] ${n}`,e)}))}function i(e){o(e.done,"effect",s(e)+"."),o(e.fail,"effect",s(e)+".")}function s(e){return e.compositeName&&e.compositeName.fullName?e.compositeName.fullName:e.shortName?e.shortName:e.name?e.name:""}Object.defineProperty(r,"__esModule",{value:!0}),r.debug=function(...e){for(const r of e){const e=n(r);(t.is.store(r,{sid:"8mdztw"})||t.is.effect(r,{sid:"-gueih2"})||t.is.event(r,{sid:"-gueh0j"}))&&o(r,e),t.is.effect(r,{sid:"-jlpzbv"})&&i(r),t.is.domain(r,{sid:"-jjisyf"})&&(r.onCreateEvent((e=>o(e,"event"))),r.onCreateStore((e=>o(e,"store"))),r.onCreateEffect(i))}}})),a=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.delay=function({source:e,timeout:r,target:n=(0,t.createEvent)({name:"target",sid:"-z2vw3w"})}){if(!t.is.unit(e))throw new TypeError("source must be a unit from effector");if(!t.is.unit(n))throw new TypeError("target must be a unit from effector");const o=function(e){if(t.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}"`)}(r),i=(0,t.createEffect)((({payload:e,milliseconds:t})=>new Promise((r=>{setTimeout(r,t,e)}))),{name:"timerFx",sid:"-584o7j"});return(0,t.sample)({and:[{source:(0,t.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:i}],or:{sid:"-wmj29s"}}),(0,t.forward)({and:{from:i.doneData,to:n},or:{sid:"-vsadmx"}}),n}})),u=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.every=function(e,r){let n,o=[],i=()=>!1;Array.isArray(e)?(o=e,i=r):Array.isArray(e.stores)&&(o=e.stores,i=e.predicate);s=i,n="function"==typeof s?i:t.is.store(i,{sid:"sid3ut"})?i.map((e=>t=>e===t)):e=>e===i;var s;const a=(0,t.combine)({and:[o],or:{name:"$values",sid:"h09uhg"}}),u=n;return(0,t.combine)({and:[u,a,(e,t)=>t.every(e)],or:{sid:"hfkdw9"}})}})),c=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.format=function(e,...r){return(0,t.combine)({and:[r,t=>e.reduce(((r,n,o)=>r.concat(function(e,t){return t===e.length-1}(e,o)?n:`${n}${function(e){if(Array.isArray(e))return e.map((e=>String(e))).join(", ");return String(e)}(t[o])}`)),"")],or:{sid:"-yrbthp"}})}})),d=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.inFlight=function({effects:e,domain:r}){if(r){const e=r.createStore(0,{name:"$inFlight",sid:"-y7vg7t"});return r.onCreateEffect((t=>{e.on(t,(e=>e+1)).on(t.finally,(e=>e-1))})),e}return(0,t.combine)({and:[e.map((e=>e.inFlight)),e=>e.reduce(((e,t)=>e+t),0)],or:{sid:"ubqxa7"}})}})),f=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.interval=function({timeout:e,start:r,stop:n,leading:o=!1,trailing:i=!1}){const s=(0,t.createEvent)({name:"tick",sid:"uo9p3s"}),a=(0,t.createStore)(!1,{name:"$isRunning",sid:"-wxesi8"}),u=function(e){if(t.is.store(e,{sid:"6p7767"}))return e;if("number"==typeof e)return(0,t.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),c=a.map((e=>!e)),d=(0,t.createEvent)({name:"saveTimeout",sid:"as5clk"}),f=(0,t.createStore)(null,{name:"$timeoutId",sid:"-bh90bo"}).on(d,((e,t)=>t)),m=(0,t.createEvent)({name:"saveReject",sid:"-64swis"}),l=(0,t.createStore)((()=>{}),{name:"$rejecter",sid:"eabbu7"}).on(m,((e,t)=>t)),p=(0,t.createEffect)((e=>new Promise(((t,r)=>{const n=setTimeout(t,e);d(n),m(r)}))),{name:"timeoutFx",sid:"7lc3mj"}),y=(0,t.attach)({and:{source:[f,l],effect:([e,t])=>{t(),e&&clearTimeout(e)}},or:{name:"cleanupFx",sid:"pcn5jq"}});(0,t.guard)({and:[{clock:r,source:u,filter:c,target:p}],or:{sid:"-w5qmwp"}}),o&&(0,t.guard)({and:[{clock:r,filter:c,target:s}],or:{sid:"-vpslni"}});(0,t.sample)({and:[{clock:r,fn:()=>!0,target:a}],or:{sid:"-vaed34"}}),(0,t.guard)({and:[{clock:p.done,source:u,filter:a,target:p}],or:{sid:"-v73liy"}}),(0,t.sample)({and:[{clock:p.done,fn:()=>{},target:s}],or:{sid:"-urpcwu"}}),n&&(i&&(0,t.sample)({and:[{clock:n,target:s}],or:{sid:"-uanqf7"}}),a.on(n,(()=>!1)),(0,t.sample)({and:[{clock:n,target:y}],or:{sid:"6lcmyy"}}));return{tick:s,isRunning:a}}})),m=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.pending=function({effects:e,domain:r,of:o="some"}){if(!t.is.domain(r,{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 i=e??[];const s=n[o];r&&(i=[],r.onCreateEffect((e=>i.push(e))));return(0,t.combine)({and:[i.map((e=>e.pending)),s],or:{sid:"a37bj0"}})};const n={some:e=>e.some(Boolean),every:e=>e.every(Boolean)}})),l=r((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.reset=function({clock:e,target:t}){const r=Array.isArray(t)?t:[t],n=Array.isArray(e)?e:[e];r.forEach((e=>{e.reset.call(e,n)}))}})),p=r((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.reshape=function({source:e,shape:t}){const r={};for(const n in t)if(n in t){const o=t[n];r[n]=e.map((e=>{const t=o(e);return void 0===t?null:t}))}return r}})),y=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.snapshot=function({source:e,clock:r,fn:n=(e=>e)}){const o=n(e.defaultState),i=r?(0,t.sample)({and:[e,r,n],or:{name:"onSnapshot",sid:"-auitd0"}}):(0,t.sample)({and:[{source:e,fn:n}],or:{name:"onSnapshot",sid:"-auir6n"}}),s=(0,t.createStore)(o,{name:"$snapshot",sid:"-7zyoaf"});return s.on(i,((e,t)=>t)),s}})),b=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.some=function({predicate:e,stores:r}){const n=(o=e,"function"==typeof o?e:t=>t===e);var o;return(0,t.combine)({and:[r,e=>e.some(n)],or:{sid:"-g8roi6"}})}})),v=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.splitMap=function({source:e,cases:r}){const n={};let o=t.is.store(e,{name:"current",sid:"-htjkz7"})?e.updates:e;for(const e in r)if(e in r){const t=r[e];n[e]=o.filterMap(t),o=o.filter({fn:e=>!t(e)})}return n.__=o,n}})),g=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.spread=function({targets:e,source:r=(0,t.createEvent)({name:"source",sid:"-iel8gi"})}){for(const n in e)if(n in e){const o=(0,t.guard)({and:[{source:r,filter:e=>"object"==typeof e&&null!==e&&n in e}],or:{name:"hasTargetKey",sid:"-gh83lo"}});t.is.store(e[n],{sid:"jliekw"})?e[n].on(o,((e,t)=>t[n])):(0,t.sample)({and:[{source:o,fn:e=>e[n],target:e[n]}],or:{sid:"lnzpe6"}})}return r}})),h=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.status=function({effect:e,defaultValue:r="initial"}){const n=(0,t.createStore)(r,{name:"$status",sid:"abrgim"});return n.on(e,(()=>"pending")).on(e.done,(()=>"done")).on(e.fail,(()=>"fail")),n}})),w=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.throttle=function({source:e,timeout:r,target:n=(0,t.createEvent)({name:"target",sid:"cenyj5"})}){if(!t.is.unit(e))throw new TypeError("source must be unit from effector");if("number"!=typeof r||r<0)throw new Error("timeout must be positive number or zero");const o=(0,t.createEffect)((()=>new Promise((e=>setTimeout(e,r)))),{name:"timerFx",sid:"uv7gwq"});return(0,t.guard)({and:[{source:e,filter:o.pending.map((e=>!e)),target:o}],or:{sid:"-iy4kn2"}}),(0,t.sample)({and:[{source:e,clock:o.done,target:n}],or:{sid:"-ija4mb"}}),n}})),j=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.time=function({clock:e,getNow:r,initial:o}){const i=r??n,s=(0,t.createEffect)(i,{name:"readNowFx",sid:"459ysb"}),a=(0,t.restore)(s,o??i(),{name:"$time",sid:"-ys9vce"});return(0,t.forward)({and:{from:e,to:s},or:{sid:"rdje9v"}}),a};const n=()=>Date.now()})),_=n.combineEvents,E=o.condition,x=i.debounce,k=s.debug,P=a.delay,M=u.every,O=c.format,$=d.inFlight,S=f.interval,T=m.pending,z=l.reset,A=p.reshape,F=y.snapshot,q=b.some,N=v.splitMap,C=g.spread,R=h.status,D=w.throttle,B=j.time,I={combineEvents:_,condition:E,debounce:x,debug:k,delay:P,every:M,format:O,inFlight:$,interval:S,pending:T,reset:z,reshape:A,snapshot:F,some:q,splitMap:N,spread:C,status:R,throttle:D,time:B};exports.combineEvents=_,exports.condition=E,exports.debounce=x,exports.debug=k,exports.default=I,exports.delay=P,exports.every=M,exports.format=O,exports.inFlight=$,exports.interval=S,exports.pending=T,exports.reset=z,exports.reshape=A,exports.snapshot=F,exports.some=q,exports.splitMap=N,exports.spread=C,exports.status=R,exports.throttle=D,exports.time=B; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("effector"));function r(e,t,r){return e(r={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&r.path)}},r.exports),r.exports}var n=r((function(e,r){function n(e){throw new Error(e)}Object.defineProperty(r,"__esModule",{value:!0}),r.combineEvents=function({events:e,reset:r,target:o=(0,t.createEvent)({name:"target",sid:"3pez5"})}){t.is.unit(o)||n("target should be a unit");r&&!t.is.unit(r)&&n("reset should be a unit");return(0,t.withRegion)(o,(()=>{const n=Object.keys(e),i=Array.isArray(e)?[...n].fill(""):{},s=(0,t.createStore)(n.length,{name:"$counter",sid:"-dszn9a"}),a=(0,t.createStore)(i,{name:"$results",sid:"boz3x7"});s.reset((0,t.sample)({and:[o],or:{sid:"-8yzcn6"}})),a.reset(o),r&&(s.reset((0,t.sample)({and:[r],or:{sid:"-72suil"}})),a.reset(r));for(const i of n){const n=(0,t.createStore)(!1,{name:"$isDone",sid:"ucs7nc"}).on(e[i],(()=>!0)).reset(o);r&&n.reset(r),s.on(n,(e=>e-1)),a.on(e[i],((e,t)=>{const r=Array.isArray(e)?[...e]:{...e};return r[i]=t,r}))}(0,t.guard)({and:[{source:(0,t.sample)({and:[a,(0,t.merge)(Object.values(e),{name:"and",sid:"-l8g4ey"})],or:{name:"source",sid:"uf92v9"}}),filter:s.map((e=>0===e)),target:o}],or:{sid:"ciekm0"}})})),o}})),o=r((function(e,r){function n(e){return t.is.unit(e)?e.map((e=>!e)):t=>!e(t)}Object.defineProperty(r,"__esModule",{value:!0}),r.condition=function({if:e,then:r,else:o,source:i=(0,t.createEvent)({name:"source",sid:"epke23"})}){const s=t.is.unit(e)||(a=e,"function"==typeof a)?e:t=>t===e;var a;r&&(0,t.guard)({and:[{source:i,filter:s,target:r}],or:{sid:"9tug3k"}});o&&(0,t.guard)({and:[{source:i,filter:n(s),target:o}],or:{sid:"a9shb1"}});return i}})),i=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.debounce=function({source:e,timeout:r,target:n}){if(!t.is.unit(e))throw new TypeError("source must be unit from effector");if(t.is.domain(e,{sid:"iu8yzo"}))throw new TypeError("source cannot be domain");if("number"!=typeof r||r<0||!Number.isFinite(r))throw new Error(`timeout must be positive number or zero. Received: "${r}"`);let o,i;const s=n??(0,t.createEvent)({name:"tick",sid:"-xw52dh"}),a=(0,t.createEffect)((e=>(clearTimeout(i),o&&o(),new Promise(((t,n)=>{o=n,i=setTimeout(t,r,e)})))),{name:"timerFx",sid:"m8kfsq"});return(0,t.forward)({and:{from:e,to:a},or:{sid:"k4foqk"}}),(0,t.forward)({and:{from:a.done.map((({result:e})=>e)),to:s},or:{sid:"k76npd"}}),s}})),s=r((function(e,r){function n(e){return t.is.store(e,{sid:"-j30z7b"})?"store":t.is.effect(e,{sid:"-j1dlf8"})?"effect":t.is.event(e,{sid:"-io6j6k"})?"event":t.is.domain(e,{sid:"-imj5eh"})?"domain":t.is.unit(e)?"unit":"unknown"}function o(e,t,r=""){const n=r+s(e);e.watch((e=>{console.info(`[${t}] ${n}`,e)}))}function i(e){o(e.done,"effect",s(e)+"."),o(e.fail,"effect",s(e)+".")}function s(e){return e.compositeName&&e.compositeName.fullName?e.compositeName.fullName:e.shortName?e.shortName:e.name?e.name:""}Object.defineProperty(r,"__esModule",{value:!0}),r.debug=function(...e){for(const r of e){const e=n(r);(t.is.store(r,{sid:"8mdztw"})||t.is.effect(r,{sid:"-gueih2"})||t.is.event(r,{sid:"-gueh0j"}))&&o(r,e),t.is.effect(r,{sid:"-jlpzbv"})&&i(r),t.is.domain(r,{sid:"-jjisyf"})&&(r.onCreateEvent((e=>o(e,"event"))),r.onCreateStore((e=>o(e,"store"))),r.onCreateEffect(i))}}})),a=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.delay=function({source:e,timeout:r,target:n=(0,t.createEvent)({name:"target",sid:"-z2vw3w"})}){if(!t.is.unit(e))throw new TypeError("source must be a unit from effector");if(!t.is.unit(n))throw new TypeError("target must be a unit from effector");const o=function(e){if(t.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}"`)}(r),i=(0,t.createEffect)((({payload:e,milliseconds:t})=>new Promise((r=>{setTimeout(r,t,e)}))),{name:"timerFx",sid:"-584o7j"});return(0,t.sample)({and:[{source:(0,t.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:i}],or:{sid:"-wmj29s"}}),(0,t.forward)({and:{from:i.doneData,to:n},or:{sid:"-vsadmx"}}),n}})),u=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.every=function(e,r){let n,o=[],i=()=>!1;Array.isArray(e)?(o=e,i=r):Array.isArray(e.stores)&&(o=e.stores,i=e.predicate);s=i,n="function"==typeof s?i:t.is.store(i,{sid:"sid3ut"})?i.map((e=>t=>e===t)):e=>e===i;var s;const a=(0,t.combine)({and:[o],or:{name:"$values",sid:"h09uhg"}}),u=n;return(0,t.combine)({and:[u,a,(e,t)=>t.every(e)],or:{sid:"hfkdw9"}})}})),c=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.format=function(e,...r){return(0,t.combine)({and:[r,t=>e.reduce(((r,n,o)=>r.concat(function(e,t){return t===e.length-1}(e,o)?n:`${n}${function(e){if(Array.isArray(e))return e.map((e=>String(e))).join(", ");return String(e)}(t[o])}`)),"")],or:{sid:"-yrbthp"}})}})),d=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.inFlight=function({effects:e,domain:r}){if(r){const e=r.createStore(0,{name:"$inFlight",sid:"-y7vg7t"});return r.onCreateEffect((t=>{e.on(t,(e=>e+1)).on(t.finally,(e=>e-1))})),e}return(0,t.combine)({and:[e.map((e=>e.inFlight)),e=>e.reduce(((e,t)=>e+t),0)],or:{sid:"ubqxa7"}})}})),f=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.interval=function({timeout:e,start:r,stop:n,leading:o=!1,trailing:i=!1}){const s=(0,t.createEvent)({name:"tick",sid:"uo9p3s"}),a=(0,t.createStore)(!1,{name:"$isRunning",sid:"-wxesi8"}),u=function(e){if(t.is.store(e,{sid:"6p7767"}))return e;if("number"==typeof e)return(0,t.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),c=a.map((e=>!e)),d=(0,t.createEvent)({name:"saveTimeout",sid:"as5clk"}),f=(0,t.createStore)(null,{name:"$timeoutId",sid:"-bh90bo"}).on(d,((e,t)=>t)),m=(0,t.createEvent)({name:"saveReject",sid:"-64swis"}),l=(0,t.createStore)((()=>{}),{name:"$rejecter",sid:"eabbu7"}).on(m,((e,t)=>t)),p=(0,t.createEffect)((e=>new Promise(((t,r)=>{const n=setTimeout(t,e);d(n),m(r)}))),{name:"timeoutFx",sid:"7lc3mj"}),y=(0,t.attach)({and:{source:[f,l],effect:([e,t])=>{t(),e&&clearTimeout(e)}},or:{name:"cleanupFx",sid:"pcn5jq"}});(0,t.guard)({and:[{clock:r,source:u,filter:c,target:p}],or:{sid:"-w5qmwp"}}),o&&(0,t.guard)({and:[{clock:r,filter:c,target:s}],or:{sid:"-vpslni"}});(0,t.sample)({and:[{clock:r,fn:()=>!0,target:a}],or:{sid:"-vaed34"}}),(0,t.guard)({and:[{clock:p.done,source:u,filter:a,target:p}],or:{sid:"-v73liy"}}),(0,t.sample)({and:[{clock:p.done,fn:()=>{},target:s}],or:{sid:"-urpcwu"}}),n&&(i&&(0,t.sample)({and:[{clock:n,target:s}],or:{sid:"-uanqf7"}}),a.on(n,(()=>!1)),(0,t.sample)({and:[{clock:n,target:y}],or:{sid:"6lcmyy"}}));return{tick:s,isRunning:a}}})),m=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.pending=function({effects:e,domain:r,of:o="some"}){if(!t.is.domain(r,{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 i=e??[];const s=n[o];r&&(i=[],r.onCreateEffect((e=>i.push(e))));return(0,t.combine)({and:[i.map((e=>e.pending)),s],or:{sid:"a37bj0"}})};const n={some:e=>e.some(Boolean),every:e=>e.every(Boolean)}})),l=r((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.reset=function({clock:e,target:t}){const r=Array.isArray(t)?t:[t],n=Array.isArray(e)?e:[e];r.forEach((e=>{e.reset.call(e,n)}))}})),p=r((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.reshape=function({source:e,shape:t}){const r={};for(const n in t)if(n in t){const o=t[n];r[n]=e.map((e=>{const t=o(e);return void 0===t?null:t}))}return r}})),y=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.snapshot=function({source:e,clock:r,fn:n=(e=>e)}){const o=n(e.defaultState),i=r?(0,t.sample)({and:[e,r,n],or:{name:"onSnapshot",sid:"-auitd0"}}):(0,t.sample)({and:[{source:e,fn:n}],or:{name:"onSnapshot",sid:"-auir6n"}}),s=(0,t.createStore)(o,{name:"$snapshot",sid:"-7zyoaf"});return s.on(i,((e,t)=>t)),s}})),b=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.some=function(e,r){let n,o=[],i=()=>!1;Array.isArray(e)?(o=e,i=r):Array.isArray(e.stores)&&(o=e.stores,i=e.predicate);s=i,n="function"==typeof s?i:t.is.store(i,{sid:"zbwu0l"})?i.map((e=>t=>e===t)):e=>e===i;var s;const a=(0,t.combine)({and:[o],or:{name:"$values",sid:"-lv5do0"}}),u=n;return(0,t.combine)({and:[u,a,(e,t)=>t.some(e)],or:{sid:"-efc5w7"}})}})),v=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.splitMap=function({source:e,cases:r}){const n={};let o=t.is.store(e,{name:"current",sid:"-htjkz7"})?e.updates:e;for(const e in r)if(e in r){const t=r[e];n[e]=o.filterMap(t),o=o.filter({fn:e=>!t(e)})}return n.__=o,n}})),g=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.spread=function({targets:e,source:r=(0,t.createEvent)({name:"source",sid:"-iel8gi"})}){for(const n in e)if(n in e){const o=(0,t.guard)({and:[{source:r,filter:e=>"object"==typeof e&&null!==e&&n in e}],or:{name:"hasTargetKey",sid:"-gh83lo"}});t.is.store(e[n],{sid:"jliekw"})?e[n].on(o,((e,t)=>t[n])):(0,t.sample)({and:[{source:o,fn:e=>e[n],target:e[n]}],or:{sid:"lnzpe6"}})}return r}})),h=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.status=function({effect:e,defaultValue:r="initial"}){const n=(0,t.createStore)(r,{name:"$status",sid:"abrgim"});return n.on(e,(()=>"pending")).on(e.done,(()=>"done")).on(e.fail,(()=>"fail")),n}})),w=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.throttle=function({source:e,timeout:r,target:n=(0,t.createEvent)({name:"target",sid:"cenyj5"})}){if(!t.is.unit(e))throw new TypeError("source must be unit from effector");if("number"!=typeof r||r<0)throw new Error("timeout must be positive number or zero");const o=(0,t.createEffect)((()=>new Promise((e=>setTimeout(e,r)))),{name:"timerFx",sid:"uv7gwq"});return(0,t.guard)({and:[{source:e,filter:o.pending.map((e=>!e)),target:o}],or:{sid:"-iy4kn2"}}),(0,t.sample)({and:[{source:e,clock:o.done,target:n}],or:{sid:"-ija4mb"}}),n}})),j=r((function(e,r){Object.defineProperty(r,"__esModule",{value:!0}),r.time=function({clock:e,getNow:r,initial:o}){const i=r??n,s=(0,t.createEffect)(i,{name:"readNowFx",sid:"459ysb"}),a=(0,t.restore)(s,o??i(),{name:"$time",sid:"-ys9vce"});return(0,t.forward)({and:{from:e,to:s},or:{sid:"rdje9v"}}),a};const n=()=>Date.now()})),_=n.combineEvents,E=o.condition,x=i.debounce,k=s.debug,P=a.delay,M=u.every,O=c.format,$=d.inFlight,A=f.interval,S=m.pending,T=l.reset,z=p.reshape,F=y.snapshot,q=b.some,N=v.splitMap,C=g.spread,R=h.status,D=w.throttle,B=j.time,I={combineEvents:_,condition:E,debounce:x,debug:k,delay:P,every:M,format:O,inFlight:$,interval:A,pending:S,reset:T,reshape:z,snapshot:F,some:q,splitMap:N,spread:C,status:R,throttle:D,time:B};exports.combineEvents=_,exports.condition=E,exports.debounce=x,exports.debug=k,exports.default=I,exports.delay=P,exports.every=M,exports.format=O,exports.inFlight=$,exports.interval=A,exports.pending=S,exports.reset=T,exports.reshape=z,exports.snapshot=F,exports.some=q,exports.splitMap=N,exports.spread=C,exports.status=R,exports.throttle=D,exports.time=B; | ||
//# sourceMappingURL=patronum.cjs.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){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"}),s=(0,r.default.createStore)(a,{name:"$results",sid:"boz3x7"});i.reset((0,r.default.sample)({and:[o],or:{sid:"-8yzcn6"}})),s.reset(o),t&&(i.reset((0,r.default.sample)({and:[t],or:{sid:"-72suil"}})),s.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)),s.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:[s,(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}})),i=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)||(s=e,"function"==typeof s)?e:t=>t===e;var s;t&&(0,r.default.guard)({and:[{source:a,filter:i,target:t}],or:{sid:"9tug3k"}});o&&(0,r.default.guard)({and:[{source:a,filter:n(i),target:o}],or:{sid:"a9shb1"}});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:"iu8yzo"}))throw new TypeError("source cannot be domain");if("number"!=typeof t||t<0||!Number.isFinite(t))throw new Error(`timeout must be positive number or zero. Received: "${t}"`);let o,a;const i=n??(0,r.default.createEvent)({name:"tick",sid:"-xw52dh"}),s=(0,r.default.createEffect)((e=>(clearTimeout(a),o&&o(),new Promise(((n,r)=>{o=r,a=setTimeout(n,t,e)})))),{name:"timerFx",sid:"m8kfsq"});return(0,r.default.forward)({and:{from:e,to:s},or:{sid:"k4foqk"}}),(0,r.default.forward)({and:{from:s.done.map((({result:e})=>e)),to:i},or:{sid:"k76npd"}}),i}})),u=o((function(e,t){function n(e){return r.default.is.store(e,{sid:"-j30z7b"})?"store":r.default.is.effect(e,{sid:"-j1dlf8"})?"effect":r.default.is.event(e,{sid:"-io6j6k"})?"event":r.default.is.domain(e,{sid:"-imj5eh"})?"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:""}Object.defineProperty(t,"__esModule",{value:!0}),t.debug=function(...e){for(const t of e){const e=n(t);(r.default.is.store(t,{sid:"8mdztw"})||r.default.is.effect(t,{sid:"-gueih2"})||r.default.is.event(t,{sid:"-gueh0j"}))&&o(t,e),r.default.is.effect(t,{sid:"-jlpzbv"})&&a(t),r.default.is.domain(t,{sid:"-jjisyf"})&&(t.onCreateEvent((e=>o(e,"event"))),t.onCreateStore((e=>o(e,"store"))),t.onCreateEffect(a))}}})),d=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}})),f=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 s=(0,r.default.combine)({and:[o],or:{name:"$values",sid:"h09uhg"}}),u=n;return(0,r.default.combine)({and:[u,s,(e,t)=>t.every(e)],or:{sid:"hfkdw9"}})}})),c=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"}})}})),l=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"}})}})),m=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"}),s=(0,r.default.createStore)(!1,{name:"$isRunning",sid:"-wxesi8"}),u=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=s.map((e=>!e)),f=(0,r.default.createEvent)({name:"saveTimeout",sid:"as5clk"}),c=(0,r.default.createStore)(null,{name:"$timeoutId",sid:"-bh90bo"}).on(f,((e,t)=>t)),l=(0,r.default.createEvent)({name:"saveReject",sid:"-64swis"}),m=(0,r.default.createStore)((()=>{}),{name:"$rejecter",sid:"eabbu7"}).on(l,((e,t)=>t)),p=(0,r.default.createEffect)((e=>new Promise(((t,n)=>{const r=setTimeout(t,e);f(r),l(n)}))),{name:"timeoutFx",sid:"7lc3mj"}),y=(0,r.default.attach)({and:{source:[c,m],effect:([e,t])=>{t(),e&&clearTimeout(e)}},or:{name:"cleanupFx",sid:"pcn5jq"}});(0,r.default.guard)({and:[{clock:t,source:u,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:s}],or:{sid:"-vaed34"}}),(0,r.default.guard)({and:[{clock:p.done,source:u,filter:s,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"}}),s.on(n,(()=>!1)),(0,r.default.sample)({and:[{clock:n,target:y}],or:{sid:"6lcmyy"}}));return{tick:i,isRunning:s}}})),p=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=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)}})),y=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)}))}})),b=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}})),g=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}})),v=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.some=function({predicate:e,stores:t}){const n=(o=e,"function"==typeof o?e:t=>t===e);var o;return(0,r.default.combine)({and:[t,e=>e.some(n)],or:{sid:"-g8roi6"}})}})),h=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}})),w=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.spread=function({targets:e,source:t=(0,r.default.createEvent)({name:"source",sid:"-iel8gi"})}){for(const n in e)if(n in e){const o=(0,r.default.guard)({and:[{source:t,filter:e=>"object"==typeof e&&null!==e&&n in e}],or:{name:"hasTargetKey",sid:"-gh83lo"}});r.default.is.store(e[n],{sid:"jliekw"})?e[n].on(o,((e,t)=>t[n])):(0,r.default.sample)({and:[{source:o,fn:e=>e[n],target:e[n]}],or:{sid:"lnzpe6"}})}return t}})),j=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((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:"cenyj5"})}){if(!r.default.is.unit(e))throw new TypeError("source must be unit from effector");if("number"!=typeof t||t<0)throw new Error("timeout must be positive number or zero");const o=(0,r.default.createEffect)((()=>new Promise((e=>setTimeout(e,t)))),{name:"timerFx",sid:"uv7gwq"});return(0,r.default.guard)({and:[{source:e,filter:o.pending.map((e=>!e)),target:o}],or:{sid:"-iy4kn2"}}),(0,r.default.sample)({and:[{source:e,clock:o.done,target:n}],or:{sid:"-ija4mb"}}),n}})),E=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.time=function({clock:e,getNow:t,initial:o}){const a=t??n,i=(0,r.default.createEffect)(a,{name:"readNowFx",sid:"459ysb"}),s=(0,r.default.restore)(i,o??a(),{name:"$time",sid:"-ys9vce"});return(0,r.default.forward)({and:{from:e,to:i},or:{sid:"rdje9v"}}),s};const n=()=>Date.now()})),k=a.combineEvents,P=i.condition,M=s.debounce,O=u.debug,$=d.delay,T=f.every,S=c.format,x=l.inFlight,z=m.interval,A=p.pending,F=y.reset,q=b.reshape,N=g.snapshot,C=v.some,R=h.splitMap,D=w.spread,B=j.status,I=_.throttle,K=E.time,V={combineEvents:k,condition:P,debounce:M,debug:O,delay:$,every:T,format:S,inFlight:x,interval:z,pending:A,reset:F,reshape:q,snapshot:N,some:C,splitMap:R,spread:D,status:B,throttle:I,time:K};e.combineEvents=k,e.condition=P,e.debounce=M,e.debug=O,e.default=V,e.delay=$,e.every=T,e.format=S,e.inFlight=x,e.interval=z,e.pending=A,e.reset=F,e.reshape=q,e.snapshot=N,e.some=C,e.splitMap=R,e.spread=D,e.status=B,e.throttle=I,e.time=K,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){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"}),s=(0,r.default.createStore)(a,{name:"$results",sid:"boz3x7"});i.reset((0,r.default.sample)({and:[o],or:{sid:"-8yzcn6"}})),s.reset(o),t&&(i.reset((0,r.default.sample)({and:[t],or:{sid:"-72suil"}})),s.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)),s.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:[s,(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}})),i=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)||(s=e,"function"==typeof s)?e:t=>t===e;var s;t&&(0,r.default.guard)({and:[{source:a,filter:i,target:t}],or:{sid:"9tug3k"}});o&&(0,r.default.guard)({and:[{source:a,filter:n(i),target:o}],or:{sid:"a9shb1"}});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:"iu8yzo"}))throw new TypeError("source cannot be domain");if("number"!=typeof t||t<0||!Number.isFinite(t))throw new Error(`timeout must be positive number or zero. Received: "${t}"`);let o,a;const i=n??(0,r.default.createEvent)({name:"tick",sid:"-xw52dh"}),s=(0,r.default.createEffect)((e=>(clearTimeout(a),o&&o(),new Promise(((n,r)=>{o=r,a=setTimeout(n,t,e)})))),{name:"timerFx",sid:"m8kfsq"});return(0,r.default.forward)({and:{from:e,to:s},or:{sid:"k4foqk"}}),(0,r.default.forward)({and:{from:s.done.map((({result:e})=>e)),to:i},or:{sid:"k76npd"}}),i}})),u=o((function(e,t){function n(e){return r.default.is.store(e,{sid:"-j30z7b"})?"store":r.default.is.effect(e,{sid:"-j1dlf8"})?"effect":r.default.is.event(e,{sid:"-io6j6k"})?"event":r.default.is.domain(e,{sid:"-imj5eh"})?"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:""}Object.defineProperty(t,"__esModule",{value:!0}),t.debug=function(...e){for(const t of e){const e=n(t);(r.default.is.store(t,{sid:"8mdztw"})||r.default.is.effect(t,{sid:"-gueih2"})||r.default.is.event(t,{sid:"-gueh0j"}))&&o(t,e),r.default.is.effect(t,{sid:"-jlpzbv"})&&a(t),r.default.is.domain(t,{sid:"-jjisyf"})&&(t.onCreateEvent((e=>o(e,"event"))),t.onCreateStore((e=>o(e,"store"))),t.onCreateEffect(a))}}})),d=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}})),f=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 s=(0,r.default.combine)({and:[o],or:{name:"$values",sid:"h09uhg"}}),u=n;return(0,r.default.combine)({and:[u,s,(e,t)=>t.every(e)],or:{sid:"hfkdw9"}})}})),c=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"}})}})),l=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"}})}})),m=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"}),s=(0,r.default.createStore)(!1,{name:"$isRunning",sid:"-wxesi8"}),u=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=s.map((e=>!e)),f=(0,r.default.createEvent)({name:"saveTimeout",sid:"as5clk"}),c=(0,r.default.createStore)(null,{name:"$timeoutId",sid:"-bh90bo"}).on(f,((e,t)=>t)),l=(0,r.default.createEvent)({name:"saveReject",sid:"-64swis"}),m=(0,r.default.createStore)((()=>{}),{name:"$rejecter",sid:"eabbu7"}).on(l,((e,t)=>t)),p=(0,r.default.createEffect)((e=>new Promise(((t,n)=>{const r=setTimeout(t,e);f(r),l(n)}))),{name:"timeoutFx",sid:"7lc3mj"}),y=(0,r.default.attach)({and:{source:[c,m],effect:([e,t])=>{t(),e&&clearTimeout(e)}},or:{name:"cleanupFx",sid:"pcn5jq"}});(0,r.default.guard)({and:[{clock:t,source:u,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:s}],or:{sid:"-vaed34"}}),(0,r.default.guard)({and:[{clock:p.done,source:u,filter:s,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"}}),s.on(n,(()=>!1)),(0,r.default.sample)({and:[{clock:n,target:y}],or:{sid:"6lcmyy"}}));return{tick:i,isRunning:s}}})),p=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=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)}})),y=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)}))}})),b=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}})),v=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}})),g=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 s=(0,r.default.combine)({and:[o],or:{name:"$values",sid:"-lv5do0"}}),u=n;return(0,r.default.combine)({and:[u,s,(e,t)=>t.some(e)],or:{sid:"-efc5w7"}})}})),h=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}})),w=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.spread=function({targets:e,source:t=(0,r.default.createEvent)({name:"source",sid:"-iel8gi"})}){for(const n in e)if(n in e){const o=(0,r.default.guard)({and:[{source:t,filter:e=>"object"==typeof e&&null!==e&&n in e}],or:{name:"hasTargetKey",sid:"-gh83lo"}});r.default.is.store(e[n],{sid:"jliekw"})?e[n].on(o,((e,t)=>t[n])):(0,r.default.sample)({and:[{source:o,fn:e=>e[n],target:e[n]}],or:{sid:"lnzpe6"}})}return t}})),j=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((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:"cenyj5"})}){if(!r.default.is.unit(e))throw new TypeError("source must be unit from effector");if("number"!=typeof t||t<0)throw new Error("timeout must be positive number or zero");const o=(0,r.default.createEffect)((()=>new Promise((e=>setTimeout(e,t)))),{name:"timerFx",sid:"uv7gwq"});return(0,r.default.guard)({and:[{source:e,filter:o.pending.map((e=>!e)),target:o}],or:{sid:"-iy4kn2"}}),(0,r.default.sample)({and:[{source:e,clock:o.done,target:n}],or:{sid:"-ija4mb"}}),n}})),E=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.time=function({clock:e,getNow:t,initial:o}){const a=t??n,i=(0,r.default.createEffect)(a,{name:"readNowFx",sid:"459ysb"}),s=(0,r.default.restore)(i,o??a(),{name:"$time",sid:"-ys9vce"});return(0,r.default.forward)({and:{from:e,to:i},or:{sid:"rdje9v"}}),s};const n=()=>Date.now()})),k=a.combineEvents,P=i.condition,M=s.debounce,O=u.debug,$=d.delay,T=f.every,A=c.format,S=l.inFlight,x=m.interval,z=p.pending,F=y.reset,q=b.reshape,N=v.snapshot,C=g.some,R=h.splitMap,D=w.spread,B=j.status,I=_.throttle,K=E.time,V={combineEvents:k,condition:P,debounce:M,debug:O,delay:$,every:T,format:A,inFlight:S,interval:x,pending:z,reset:F,reshape:q,snapshot:N,some:C,splitMap:R,spread:D,status:B,throttle:I,time:K};e.combineEvents=k,e.condition=P,e.debounce=M,e.debug=O,e.default=V,e.delay=$,e.every=T,e.format=A,e.inFlight=S,e.interval=x,e.pending=z,e.reset=F,e.reshape=q,e.snapshot=N,e.some=C,e.splitMap=R,e.spread=D,e.status=B,e.throttle=I,e.time=K,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=patronum.umd.js.map |
210
README.md
# <img src="logo.svg" title="effector patronum" alt="Effector Patronum logo" width="640px"> | ||
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) ![Node.js CI](https://github.com/effector/patronum/workflows/Node.js%20CI/badge.svg) [![Rate on Openbase](https://badges.openbase.com/js/rating/patronum.svg)](https://openbase.com/js/patronum?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge) | ||
[![LICENSE](https://badgen.net/github/license/effector/patronum?color=green)](/LICENSE) | ||
[![Stars](https://badgen.net/github/stars/effector/patronum?color=green)](https://github.com/effector/patronum) | ||
[![Downloads](https://badgen.net/npm/dt/patronum)](https://npmjs.com/package/patronum) | ||
☄️ Effector operators library delivering modularity and convenience | ||
- 🎲 Try it online: [Codesandbox](codesandbox) | [Playground](try-patronum-share) | ||
- 📦 Source: [JSdeliver](jsdelivr) | [Unpkg](unpkg) | [NPM](npm) | [GitHub](github) | ||
- 🦉 Say about it: [Twitter](twitter-share) | ||
[codesandbox]: https://codesandbox.io/s/effector-patronum-playground-zuqjx | ||
[try-patronum-share]: https://share.effector.dev/Neewtbz3 | ||
[jsdelivr]: https://www.jsdelivr.com/package/npm/patronum | ||
[unpkg]: https://unpkg.com/browse/patronum@1.7.0/ | ||
[npm]: https://www.npmjs.com/package/patronum | ||
[github]: https://github.com/effector/patronum | ||
[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 | ||
## Table of contents | ||
@@ -43,41 +58,200 @@ | ||
## Usage | ||
## 💿 Install now | ||
> Please, review documentation for YOUR version of patronum not the latest. Find and open tag/release for your version. | ||
> Please, review documentation for **YOUR** version of patronum not the latest. Find and [open tag/release](https://github.com/effector/patronum/releases) for your version and click on the tag [vA.B.C](https://github.com/effector/patronum/tree/v1.7.0) to view repo and documentation for that version, or use "Switch branches/tags" selector. | ||
```bash | ||
npm install patronum | ||
# or | ||
yarn add patronum | ||
``` | ||
Import function by its name from `patronum`: | ||
Next just import methods from `"patronum"` and use it: | ||
```ts | ||
import { delay } from 'patronum/delay'; | ||
import { inFlight } from 'patronum/in-flight'; | ||
import { createEffect } from "effector" | ||
import { status } from "patronum" | ||
const userLoadFx = createEffect() | ||
const $status = status({ effect: userLoadFx }) | ||
``` | ||
Also use can import it from index: | ||
## 🐞 Debug and log | ||
```ts | ||
import { delay, inFlight } from 'patronum'; | ||
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 | ||
``` | ||
### Create React App and Macros support | ||
We have some variants how to use logger to debug our applications. Please, don't merge all variants, **it's not compatible**! | ||
Just import from `patronum/macro`, and imports will be replaced to full qualified: | ||
### 1. Temporarily change imports in certain modules | ||
```ts | ||
import { status, splitMap, combineEvents } from 'patronum/macro'; | ||
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' | ||
``` | ||
> Warning: babel-plugin-macros do not support `import * as name`! | ||
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/). | ||
Since release of patronum@2.0.0 it is required to use babel-plugin-macros@3.0.0 or higher. | ||
> Note: You don't need to install it separately, because its bundled into effector package. | ||
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. | ||
```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> | ||
### v2.0.0 | ||
@@ -96,2 +270,4 @@ | ||
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> | ||
@@ -98,0 +274,0 @@ --- |
import { Store } from 'effector'; | ||
export declare function some<T>(_: { | ||
predicate: Store<T>; | ||
stores: Array<Store<T>>; | ||
}): Store<boolean>; | ||
export declare function some<T>(_: { | ||
predicate: (value: T) => boolean; | ||
@@ -14,1 +18,4 @@ stores: Array<Store<T>>; | ||
}): Store<boolean>; | ||
export declare function some<T>(stores: Store<T>[], predicate: Store<T>): Store<boolean>; | ||
export declare function some<T>(stores: Store<T>[], predicate: T): Store<boolean>; | ||
export declare function some<T>(stores: Store<T>[], predicate: (value: T) => boolean): Store<boolean>; |
@@ -10,11 +10,40 @@ "use strict"; | ||
function some({ | ||
predicate, | ||
stores | ||
}) { | ||
const checker = isFunction(predicate) ? predicate : value => value === predicate; | ||
function some(configOrStores, predicateOrNone) { | ||
let stores = []; | ||
let predicate = () => false; | ||
if (Array.isArray(configOrStores)) { | ||
stores = configOrStores; | ||
predicate = predicateOrNone; | ||
} else if (Array.isArray(configOrStores.stores)) { | ||
stores = configOrStores.stores; | ||
predicate = configOrStores.predicate; | ||
} | ||
let checker; | ||
if (isFunction(predicate)) { | ||
checker = predicate; | ||
} else if (_effector.is.store(predicate, { | ||
sid: "zbwu0l" | ||
})) { | ||
checker = predicate.map(value => required => value === required); | ||
} else { | ||
checker = value => value === predicate; | ||
} | ||
const $values = (0, _effector.combine)({ | ||
and: [stores], | ||
or: { | ||
name: "$values", | ||
sid: "-lv5do0" | ||
} | ||
}); // Combine pass simple values as is | ||
const $checker = checker; | ||
return (0, _effector.combine)({ | ||
and: [stores, values => values.some(checker)], | ||
and: [$checker, $values, (checker, values) => values.some(checker)], | ||
or: { | ||
sid: "-g8roi6" | ||
sid: "-efc5w7" | ||
} | ||
@@ -21,0 +50,0 @@ }); |
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
240478
2313
784