Comparing version 1.8.5 to 1.9.0
@@ -1,6 +0,6 @@ | ||
import { Event, Unit } from 'effector'; | ||
import { Event, Store, Unit } from 'effector'; | ||
declare type EventAsReturnType<Payload> = any extends Payload ? Event<Payload> : never; | ||
export declare function debounce<T>(_: { | ||
source: Unit<T>; | ||
timeout: number; | ||
timeout: number | Store<number>; | ||
name?: string; | ||
@@ -10,3 +10,3 @@ }): EventAsReturnType<T>; | ||
source: Unit<T>; | ||
timeout: number; | ||
timeout: number | Store<number>; | ||
target: Target; | ||
@@ -13,0 +13,0 @@ name?: string; |
@@ -1,2 +0,2 @@ | ||
import { createEffect, createEvent, forward, is } from 'effector'; | ||
import { createEffect, createEvent, createStore, forward, is, sample, attach } from 'effector'; | ||
export function debounce(_ref) { | ||
@@ -10,37 +10,100 @@ var { | ||
if (is.domain(source, { | ||
sid: "iu8yzo" | ||
sid: "jne2ft" | ||
})) throw new TypeError('source cannot be domain'); | ||
if (typeof timeout !== 'number' || timeout < 0 || !Number.isFinite(timeout)) throw new Error("timeout must be positive number or zero. Received: \"".concat(timeout, "\"")); | ||
var rejectPromise; | ||
var timeoutId; | ||
var $timeout = toStoreNumber(timeout); | ||
var saveTimeoutId = createEvent({ | ||
name: "saveTimeoutId", | ||
sid: "eqtrwk" | ||
}); | ||
var $timeoutId = createStore(null, { | ||
and: { | ||
serialize: 'ignore' | ||
}, | ||
name: "$timeoutId", | ||
sid: "-5hlcyp" | ||
}).on(saveTimeoutId, (_, id) => id); | ||
var saveReject = createEvent({ | ||
name: "saveReject", | ||
sid: "-m6vk0" | ||
}); // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
var $rejecter = createStore(null, { | ||
and: { | ||
serialize: 'ignore' | ||
}, | ||
name: "$rejecter", | ||
sid: "tqvf32" | ||
}).on(saveReject, (_, rj) => rj); | ||
var tick = target !== null && target !== void 0 ? target : createEvent({ | ||
name: "tick", | ||
sid: "-xw52dh" | ||
sid: "-6wklwe" | ||
}); | ||
var timerFx = createEffect(parameter => { | ||
clearTimeout(timeoutId); | ||
var timerBaseFx = createEffect(_ref2 => { | ||
var { | ||
parameter, | ||
timeout, | ||
timeoutId, | ||
rejectPromise | ||
} = _ref2; | ||
if (timeoutId) clearTimeout(timeoutId); | ||
if (rejectPromise) rejectPromise(); | ||
return new Promise((resolve, reject) => { | ||
rejectPromise = reject; | ||
timeoutId = setTimeout(resolve, timeout, parameter); | ||
saveReject(reject); | ||
saveTimeoutId(setTimeout(resolve, timeout, parameter)); | ||
}); | ||
}, { | ||
name: "timerFx", | ||
sid: "m8kfsq" | ||
name: "timerBaseFx", | ||
sid: "-xd98qa" | ||
}); | ||
forward({ | ||
var timerFx = attach({ | ||
and: { | ||
from: source, | ||
to: timerFx | ||
source: { | ||
timeoutId: $timeoutId, | ||
rejectPromise: $rejecter | ||
}, | ||
mapParams: (_ref3, _ref4) => { | ||
var { | ||
parameter, | ||
timeout | ||
} = _ref3; | ||
var { | ||
timeoutId, | ||
rejectPromise | ||
} = _ref4; | ||
return { | ||
parameter, | ||
timeout, | ||
timeoutId, | ||
rejectPromise | ||
}; | ||
}, | ||
effect: timerBaseFx | ||
}, | ||
or: { | ||
sid: "k4foqk" | ||
name: "timerFx", | ||
sid: "-4ab544" | ||
} | ||
}); | ||
$rejecter.reset(timerFx.done); | ||
$timeoutId.reset(timerFx.done); | ||
sample({ | ||
and: [{ | ||
source: $timeout, | ||
clock: source, | ||
fn: (timeout, parameter) => ({ | ||
timeout, | ||
parameter | ||
}), | ||
target: timerFx | ||
}], | ||
or: { | ||
sid: "m29k3f" | ||
} | ||
}); | ||
forward({ | ||
and: { | ||
from: timerFx.done.map(_ref2 => { | ||
from: timerFx.done.map(_ref5 => { | ||
var { | ||
result | ||
} = _ref2; | ||
} = _ref5; | ||
return result; | ||
@@ -51,6 +114,24 @@ }), | ||
or: { | ||
sid: "k76npd" | ||
sid: "-32ktwy" | ||
} | ||
}); | ||
return tick; | ||
} | ||
function toStoreNumber(value) { | ||
if (is.store(value, { | ||
sid: "-2xmoh9" | ||
})) return value; | ||
if (typeof value === 'number') { | ||
if (value < 0 || !Number.isFinite(value)) throw new Error("timeout must be positive number or zero. Received: \"".concat(value, "\"")); | ||
return createStore(value, { | ||
and: { | ||
name: '$timeout' | ||
}, | ||
sid: "-757cx6" | ||
}); | ||
} | ||
throw new TypeError("timeout parameter in interval method should be number or Store. \"".concat(typeof value, "\" was passed")); | ||
} |
import { Unit } from 'effector'; | ||
export declare function debug(...units: Unit<any>[]): void; | ||
export declare function debug(...units: Unit<any>[] | [ | ||
{ | ||
trace: boolean; | ||
}, | ||
...Unit<any>[] | ||
]): void; |
@@ -1,3 +0,7 @@ | ||
import { is } from 'effector'; | ||
import { is, createNode, step } from 'effector'; | ||
export function debug() { | ||
var config = { | ||
trace: false | ||
}; | ||
for (var _len = arguments.length, units = new Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -7,28 +11,14 @@ units[_key] = arguments[_key]; | ||
for (var unit of units) { | ||
var type = getType(unit); | ||
var [maybeConfig, ...restUnits] = units; | ||
if (is.store(unit, { | ||
sid: "8mdztw" | ||
}) || is.effect(unit, { | ||
sid: "-gueih2" | ||
}) || is.event(unit, { | ||
sid: "-gueh0j" | ||
})) { | ||
log(unit, type); | ||
} | ||
if (!is.unit(maybeConfig)) { | ||
config = maybeConfig; | ||
} else { | ||
logUnit(maybeConfig); | ||
} | ||
if (is.effect(unit, { | ||
sid: "-jlpzbv" | ||
})) { | ||
logEffect(unit); | ||
for (var unit of restUnits) { | ||
if (is.unit(unit)) { | ||
logUnit(unit, config); | ||
} | ||
if (is.domain(unit, { | ||
sid: "-jjisyf" | ||
})) { | ||
unit.onCreateEvent(event => log(event, 'event')); | ||
unit.onCreateStore(store => log(store, 'store')); | ||
unit.onCreateEffect(logEffect); | ||
} | ||
} | ||
@@ -39,3 +29,3 @@ } | ||
if (is.store(unit, { | ||
sid: "-j30z7b" | ||
sid: "-i74wsd" | ||
})) { | ||
@@ -46,3 +36,3 @@ return 'store'; | ||
if (is.effect(unit, { | ||
sid: "-j1dlf8" | ||
sid: "-i5hj0a" | ||
})) { | ||
@@ -53,3 +43,3 @@ return 'effect'; | ||
if (is.event(unit, { | ||
sid: "-io6j6k" | ||
sid: "-i3u587" | ||
})) { | ||
@@ -60,3 +50,3 @@ return 'event'; | ||
if (is.domain(unit, { | ||
sid: "-imj5eh" | ||
sid: "-i26rg4" | ||
})) { | ||
@@ -86,2 +76,7 @@ return 'domain'; | ||
function getNode(node) { | ||
var actualNode = 'graphite' in node ? node.graphite : node; | ||
return actualNode; | ||
} | ||
function getName(unit) { | ||
@@ -101,2 +96,147 @@ if (unit.compositeName && unit.compositeName.fullName) { | ||
return ''; | ||
} | ||
function readLoc(_ref) { | ||
var { | ||
meta | ||
} = _ref; | ||
var loc = 'config' in meta ? meta.config.loc : meta.loc; | ||
return loc; | ||
} | ||
function getLoc(unit) { | ||
var _loc$file; | ||
var loc = readLoc(unit); | ||
if (!loc) return null; | ||
return "".concat((_loc$file = loc.file) !== null && _loc$file !== void 0 ? _loc$file : '', ":").concat(loc.line, ":").concat(loc.column); | ||
} | ||
function logUnit(unit, config) { | ||
var type = getType(unit); | ||
if (is.store(unit, { | ||
sid: "voorwi" | ||
}) || is.effect(unit, { | ||
sid: "-c68ujk" | ||
}) || is.event(unit, { | ||
sid: "-c68t31" | ||
})) { | ||
log(unit, type); | ||
if (config !== null && config !== void 0 && config.trace) { | ||
logTrace(unit); | ||
} | ||
} | ||
if (is.effect(unit, { | ||
sid: "w4mt3z" | ||
})) { | ||
logEffect(unit); | ||
} | ||
if (is.domain(unit, { | ||
sid: "w6tzhf" | ||
})) { | ||
unit.onCreateEvent(event => { | ||
log(event, 'event'); | ||
if (config !== null && config !== void 0 && config.trace) { | ||
logTrace(event); | ||
} | ||
}); | ||
unit.onCreateStore(store => { | ||
log(store, 'store'); | ||
if (config !== null && config !== void 0 && config.trace) { | ||
logTrace(store); | ||
} | ||
}); | ||
unit.onCreateEffect(logEffect); | ||
} | ||
} | ||
function isEffectChild(node) { | ||
var actualNode = getNode(node); | ||
var { | ||
sid, | ||
named | ||
} = actualNode.meta; | ||
return Boolean(!sid && (named === 'finally' || named === 'done' || named === 'doneData' || named === 'fail' || named === 'failData' || named === 'inFlight' || named === 'pending')); | ||
} | ||
function getNodeName(node) { | ||
if (!node) return ''; | ||
var { | ||
meta | ||
} = node; | ||
if (!isEffectChild(node)) { | ||
return meta.name; | ||
} | ||
var parentEffect = node.family.owners.find(n => n.meta.op === 'effect'); | ||
if (parentEffect) { | ||
return "".concat(getNodeName(parentEffect), ".").concat(meta.named); | ||
} | ||
return meta.named; | ||
} | ||
function logTrace(unit) { | ||
var type = getType(unit); | ||
var name = getName(unit); | ||
createNode({ | ||
parent: [unit], | ||
meta: { | ||
op: 'watch' | ||
}, | ||
family: { | ||
owners: unit | ||
}, | ||
regional: true, | ||
node: [step.run({ | ||
fn(_data, _scope, stack) { | ||
var parent = stack === null || stack === void 0 ? void 0 : stack.parent; | ||
var groupName = "[".concat(type, "] ").concat(name, " trace"); // eslint-disable-next-line no-console | ||
console.groupCollapsed(groupName); | ||
while (parent) { | ||
var _parent2; | ||
var { | ||
node, | ||
value | ||
} = parent; | ||
var { | ||
meta | ||
} = node; | ||
var opName = meta.op; | ||
var unitName = getNodeName(node); | ||
if (!unitName) { | ||
var _getLoc; | ||
unitName = (_getLoc = getLoc(node)) !== null && _getLoc !== void 0 ? _getLoc : ''; | ||
} | ||
if (opName === 'on') { | ||
var _node$next, _parent, _parent$parent; | ||
var parentStore = getNodeName(node === null || node === void 0 ? void 0 : (_node$next = node.next) === null || _node$next === void 0 ? void 0 : _node$next[0]); | ||
opName = "".concat(parentStore, ".").concat(meta.op); | ||
unitName = "".concat(parentStore, ".").concat(meta.op, "(").concat(getNodeName((_parent = parent) === null || _parent === void 0 ? void 0 : (_parent$parent = _parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.node), ")"); | ||
} | ||
console.info("<- [".concat(opName, "] ").concat(unitName), value); | ||
parent = (_parent2 = parent) === null || _parent2 === void 0 ? void 0 : _parent2.parent; | ||
} | ||
console.groupEnd(); | ||
} | ||
})] | ||
}); | ||
} |
{ | ||
"name": "patronum", | ||
"version": "1.8.5", | ||
"version": "1.9.0", | ||
"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,forward as d,attach as f,restore as m}from"effector";function l(){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 v(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 p(e,r,n){return r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function y(e){var{events:u,reset:c,target:d=r({name:"target",sid:"3pez5"},{name:"target",sid:"3pez5"})}=e;return n.unit(d)||g("target should be a unit"),c&&!n.unit(c)&&g("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?v(Object(n),!0).forEach((function(r){p(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):v(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 g(e){throw new Error(e)}function b(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:w(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:w(c),target:a}],or:{sid:"-eb29qp"}}),s}function w(e){return n.unit(e)?e.map((e=>!e)):r=>!e(r)}function h(e){var t,o,{source:a,timeout:i,target:s}=e;if(!n.unit(a))throw new TypeError("source must be unit from effector");if(n.domain(a,{sid:"iu8yzo"}))throw new TypeError("source cannot be domain");if("number"!=typeof i||i<0||!Number.isFinite(i))throw new Error('timeout must be positive number or zero. Received: "'.concat(i,'"'));var u=null!=s?s:r({name:"tick",sid:"-xw52dh"}),f=c((e=>(clearTimeout(o),t&&t(),new Promise(((r,n)=>{t=n,o=setTimeout(r,i,e)})))),{name:"timerFx",sid:"m8kfsq"});return d({and:{from:a,to:f},or:{sid:"k4foqk"}}),d({and:{from:f.done.map((e=>{var{result:r}=e;return r})),to:u},or:{sid:"k76npd"}}),u}function j(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];for(var o of r){var a=k(o);(n.store(o,{sid:"8mdztw"})||n.effect(o,{sid:"-gueih2"})||n.event(o,{sid:"-gueh0j"}))&&A(o,a),n.effect(o,{sid:"-jlpzbv"})&&O(o),n.domain(o,{sid:"-jjisyf"})&&(o.onCreateEvent((e=>A(e,"event"))),o.onCreateStore((e=>A(e,"store"))),o.onCreateEffect(O))}}function k(e){return n.store(e,{sid:"-j30z7b"})?"store":n.effect(e,{sid:"-j1dlf8"})?"effect":n.event(e,{sid:"-io6j6k"})?"event":n.domain(e,{sid:"-imj5eh"})?"domain":n.unit(e)?"unit":"unknown"}function A(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",t=n+E(e);e.watch((e=>{console.info("[".concat(r,"] ").concat(t),e)}))}function O(e){A(e.done,"effect",E(e)+"."),A(e.fail,"effect",E(e)+".")}function E(e){return e.compositeName&&e.compositeName.fullName?e.compositeName.fullName:e.shortName?e.shortName:e.name?e.name:""}function z(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),f=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:f}],or:{sid:"-wmj29s"}}),d({and:{from:f.doneData,to:s},or:{sid:"-vsadmx"}}),s}function T(r,t,o){return n.store(r,{sid:"n60kh0"})?e({and:[r,t,o,(e,r,n)=>e?r:n],or:{sid:"8ceklb"}}):T(r)}function P(r,n){return e({and:[r,n,(e,r)=>e===r],or:{sid:"jvku5g"}})}function $(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 x(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(N(r,o)?t:"".concat(t).concat(S(e[o])))),"")],or:{sid:"-yrbthp"}})}function S(e){return Array.isArray(e)?e.map((e=>String(e))).join(", "):String(e)}function N(e,r){return r===e.length-1}function F(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 q(e){var{timeout:t,start:s,stop:u,leading:d=!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"}),b=o(null,{name:"$timeoutId",sid:"-bh90bo"}).on(g,((e,r)=>r)),w=r({name:"saveReject",sid:"-64swis"}),h=o((()=>{}),{name:"$rejecter",sid:"eabbu7"}).on(w,((e,r)=>r)),j=c((e=>new Promise(((r,n)=>{var t=setTimeout(r,e);g(t),w(n)}))),{name:"timeoutFx",sid:"7lc3mj"}),k=f({and:{source:[b,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:j}],or:{sid:"-w5qmwp"}}),d&&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:j.done,source:p,filter:v,target:j}],or:{sid:"-v73liy"}}),a({and:[{clock:j.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:k}],or:{sid:"6lcmyy"}})),{tick:l,isRunning:v}}function D(e){return e.map((e=>!e))}function B(){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 C={some:e=>e.some(Boolean),every:e=>e.every(Boolean)};function R(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=C[a];return o&&(i=[],o.onCreateEffect((e=>i.push(e)))),e({and:[i.map((e=>e.pending)),s],or:{sid:"a37bj0"}})}function _(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 I(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 K(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 M(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 V(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}function G(e){var{targets:t,source:o=r({name:"source",sid:"-iel8gi"},{name:"source",sid:"-iel8gi"})}=e,s=function(e){if(e in t){var r=i({and:[{source:o,filter:r=>"object"==typeof r&&null!==r&&e in r}],or:{name:"hasTargetKey",sid:"-gh83lo"}});n.store(t[e],{sid:"jliekw"})?t[e].on(r,((r,n)=>n[e])):a({and:[{source:r,fn:r=>r[e],target:t[e]}],or:{sid:"lnzpe6"}})}};for(var u in t)s(u);return o}function H(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 J(e){var{source:t,timeout:o,target:s=r({name:"target",sid:"cenyj5"},{name:"target",sid:"cenyj5"})}=e;if(!n.unit(t))throw new TypeError("source must be unit from effector");if("number"!=typeof o||o<0)throw new Error("timeout must be positive number or zero");var u=c((()=>new Promise((e=>setTimeout(e,o)))),{name:"timerFx",sid:"uv7gwq"});return i({and:[{source:t,filter:u.pending.map((e=>!e)),target:u}],or:{sid:"-iy4kn2"}}),a({and:[{source:t,clock:u.done,target:s}],or:{sid:"-ija4mb"}}),s}var L=()=>Date.now();function Q(e){var{clock:r,getNow:n,initial:t}=e,o=null!=n?n:L,a=c(o,{name:"readNowFx",sid:"459ysb"}),i=m(a,null!=t?t:o(),{name:"$time",sid:"-ys9vce"});return d({and:{from:r,to:a},or:{sid:"rdje9v"}}),i}export{l as and,y as combineEvents,b as condition,h as debounce,j as debug,z as delay,T as either,P as equals,$ as every,x as format,F as inFlight,q as interval,D as not,B as or,R as pending,_ as reset,I as reshape,K as snapshot,M as some,V as splitMap,G as spread,H as status,J as throttle,Q 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 q(r,n){return e({and:[r,n,(e,r)=>e===r],or:{sid:"jvku5g"}})}function D(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 B(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(C(r,o)?t:"".concat(t).concat(I(e[o])))),"")],or:{sid:"-yrbthp"}})}function I(e){return Array.isArray(e)?e.map((e=>String(e))).join(", "):String(e)}function C(e,r){return r===e.length-1}function R(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 _(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 K(e){return e.map((e=>!e))}function M(){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 V={some:e=>e.some(Boolean),every:e=>e.every(Boolean)};function G(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=V[a];return o&&(i=[],o.onCreateEffect((e=>i.push(e)))),e({and:[i.map((e=>e.pending)),s],or:{sid:"a37bj0"}})}function H(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 J(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 L(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 Q(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 U(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 W={}.hasOwnProperty;function X(e){var{targets:n,source:t=r({name:"source",sid:"-fkbi3c"},{name:"source",sid:"-fkbi3c"})}=e,o=function(e){if(s=n,u=e,W.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 Y(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 Z(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 ee=()=>Date.now();function re(e){var{clock:r,getNow:n,initial:t}=e,o=null!=n?n:ee,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 equals,D as every,B as format,R as inFlight,_ as interval,K as not,M as or,G as pending,H as reset,J as reshape,L as snapshot,Q as some,U as splitMap,X as spread,Y as status,Z as throttle,re 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:"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=null!=n?n:(0,r.default.createEvent)({name:"tick",sid:"-xw52dh"}),u=(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:u},or:{sid:"k4foqk"}}),(0,r.default.forward)({and:{from:u.done.map((({result:e})=>e)),to:i},or:{sid:"k76npd"}}),i}})),d=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))}}})),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}})),c=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)}})),l=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"}})}})),m=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"}})}})),p=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"}})}})),y=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"}),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: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}}})),v=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.not=function(e){return e.map((e=>!e))}})),g=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"}})}})),h=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)}})),w=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)}))}})),j=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}})),E=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"}})}})),k=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:"-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}})),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:"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}})),$=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()})),T=a.and,A=i.combineEvents,S=u.condition,x=s.debounce,z=d.debug,q=f.delay,F=c.either,N=l.equals,B=m.every,C=p.format,R=y.inFlight,D=b.interval,I=v.not,K=g.or,V=h.pending,G=w.reset,H=j.reshape,J=_.snapshot,L=E.some,Q=k.splitMap,U=P.spread,W=M.status,X=O.throttle,Y=$.time,Z={and:T,combineEvents:A,condition:S,debounce:x,debug:z,delay:q,either:F,equals:N,every:B,format:C,inFlight:R,interval:D,not:I,or:K,pending:V,reset:G,reshape:H,snapshot:J,some:L,splitMap:Q,spread:U,status:W,throttle:X,time:Y};e.and=T,e.combineEvents=A,e.condition=S,e.debounce=x,e.debug=z,e.default=Z,e.delay=q,e.either=F,e.equals=N,e.every=B,e.format=C,e.inFlight=R,e.interval=D,e.not=I,e.or=K,e.pending=V,e.reset=G,e.reshape=H,e.snapshot=J,e.some=L,e.splitMap=Q,e.spread=U,e.status=W,e.throttle=X,e.time=Y,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.equals=function(e,t){return(0,r.default.combine)({and:[e,t,(e,t)=>e===t],or:{sid:"jvku5g"}})}})),m=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"}})}})),p=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"}})}})),y=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"}})}})),v=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}}})),b=o((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.not=function(e){return e.map((e=>!e))}})),g=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"}})}})),h=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)}})),w=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)}))}})),j=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}})),$=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"}})}})),k=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}})),E=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})),P=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}})),M=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}})),O=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,x=i.combineEvents,T=u.condition,A=s.debounce,q=d.debug,F=f.delay,z=l.either,N=c.equals,B=m.every,I=p.format,R=y.inFlight,C=v.interval,D=b.not,K=g.or,V=h.pending,G=w.reset,H=j.reshape,J=_.snapshot,L=$.some,Q=k.splitMap,U=E.spread,W=P.status,X=M.throttle,Y=O.time,Z={and:S,combineEvents:x,condition:T,debounce:A,debug:q,delay:F,either:z,equals:N,every:B,format:I,inFlight:R,interval:C,not:D,or:K,pending:V,reset:G,reshape:H,snapshot:J,some:L,splitMap:Q,spread:U,status:W,throttle:X,time:Y};e.and=S,e.combineEvents=x,e.condition=T,e.debounce=A,e.debug=q,e.default=Z,e.delay=F,e.either=z,e.equals=N,e.every=B,e.format=I,e.inFlight=R,e.interval=C,e.not=D,e.or=K,e.pending=V,e.reset=G,e.reshape=H,e.snapshot=J,e.some=L,e.splitMap=Q,e.spread=U,e.status=W,e.throttle=X,e.time=Y,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=patronum.umd.js.map |
@@ -10,6 +10,7 @@ # <img src="logo.svg" title="effector patronum" alt="Effector Patronum logo" width="640px"> | ||
- 🎲 Try it online: [Codesandbox](codesandbox) | [Playground](try-patronum-share) | ||
- 🎲 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) | ||
[stackblitz]: https://stackblitz.com/edit/effector-react | ||
[codesandbox]: https://codesandbox.io/s/effector-patronum-playground-zuqjx | ||
@@ -16,0 +17,0 @@ [try-patronum-share]: https://share.effector.dev/Neewtbz3 |
@@ -12,5 +12,5 @@ import { Event, Unit } from 'effector'; | ||
targets: { | ||
[Key in keyof Payload]?: Unit<NoInfer<Payload[Key]>>; | ||
[Key in keyof Payload]?: EventAsReturnType<Partial<Payload[Key]>> | Unit<NoInfer<Payload[Key]>>; | ||
}; | ||
}): Source; | ||
export {}; |
@@ -1,3 +0,6 @@ | ||
import { is, createEvent, guard, sample } from 'effector'; | ||
import { createEvent, guard, sample } from 'effector'; | ||
var hasPropBase = {}.hasOwnProperty; | ||
var hasOwnProp = (object, key) => hasPropBase.call(object, key); | ||
/** | ||
@@ -15,6 +18,6 @@ * @example | ||
name: "source", | ||
sid: "-iel8gi" | ||
sid: "-fkbi3c" | ||
}, { | ||
name: "source", | ||
sid: "-iel8gi" | ||
sid: "-fkbi3c" | ||
}) | ||
@@ -24,6 +27,8 @@ } = _ref; | ||
var _loop = function _loop(targetKey) { | ||
if (targetKey in targets) { | ||
if (hasOwnProp(targets, targetKey)) { | ||
var currentTarget = targets[targetKey]; | ||
var hasTargetKey = guard({ | ||
and: [{ | ||
source, | ||
greedy: true, | ||
filter: object => typeof object === 'object' && object !== null && targetKey in object | ||
@@ -33,22 +38,16 @@ }], | ||
name: "hasTargetKey", | ||
sid: "-gh83lo" | ||
sid: "-cov4g4" | ||
} | ||
}); | ||
if (is.store(targets[targetKey], { | ||
sid: "jliekw" | ||
})) { | ||
targets[targetKey].on(hasTargetKey, (prev, object) => object[targetKey]); | ||
} else { | ||
sample({ | ||
and: [{ | ||
source: hasTargetKey, | ||
fn: object => object[targetKey], | ||
target: targets[targetKey] | ||
}], | ||
or: { | ||
sid: "lnzpe6" | ||
} | ||
}); | ||
} | ||
sample({ | ||
and: [{ | ||
greedy: true, | ||
clock: hasTargetKey, | ||
fn: object => object[targetKey], | ||
target: currentTarget | ||
}], | ||
or: { | ||
sid: "lpn34j" | ||
} | ||
}); | ||
} | ||
@@ -55,0 +54,0 @@ }; |
@@ -1,6 +0,6 @@ | ||
import { Event, Unit } from 'effector'; | ||
import { Event, Store, Unit } from 'effector'; | ||
declare type EventAsReturnType<Payload> = any extends Payload ? Event<Payload> : never; | ||
export declare function throttle<T>(_: { | ||
source: Unit<T>; | ||
timeout: number; | ||
timeout: number | Store<number>; | ||
name?: string; | ||
@@ -10,3 +10,3 @@ }): EventAsReturnType<T>; | ||
source: Unit<T>; | ||
timeout: number; | ||
timeout: number | Store<number>; | ||
target: Target; | ||
@@ -13,0 +13,0 @@ name?: string; |
@@ -1,2 +0,2 @@ | ||
import { createEffect, createEvent, guard, is, sample } from 'effector'; | ||
import { createEffect, createEvent, createStore, guard, is, sample } from 'effector'; | ||
export function throttle(_ref) { | ||
@@ -8,22 +8,32 @@ var { | ||
name: "target", | ||
sid: "cenyj5" | ||
sid: "r328r6" | ||
}, { | ||
name: "target", | ||
sid: "cenyj5" | ||
sid: "r328r6" | ||
}) | ||
} = _ref; | ||
if (!is.unit(source)) throw new TypeError('source must be unit from effector'); | ||
if (typeof timeout !== 'number' || timeout < 0) throw new Error('timeout must be positive number or zero'); | ||
var timerFx = createEffect(() => new Promise(resolve => setTimeout(resolve, timeout)), { | ||
var $timeout = toStoreNumber(timeout); | ||
var timerFx = createEffect(timeout => new Promise(resolve => setTimeout(resolve, timeout)), { | ||
name: "timerFx", | ||
sid: "uv7gwq" | ||
sid: "-pyjx8k" | ||
}); | ||
guard({ | ||
var start = guard({ | ||
and: [{ | ||
source, | ||
filter: timerFx.pending.map(pending => !pending), | ||
clock: source, | ||
filter: timerFx.pending.map(pending => !pending) | ||
}], | ||
or: { | ||
name: "start", | ||
sid: "-p67kgr" | ||
} | ||
}); | ||
sample({ | ||
and: [{ | ||
source: $timeout, | ||
clock: start, | ||
target: timerFx | ||
}], | ||
or: { | ||
sid: "-iy4kn2" | ||
sid: "-ievrvf" | ||
} | ||
@@ -38,6 +48,24 @@ }); | ||
or: { | ||
sid: "-ija4mb" | ||
sid: "-i01buo" | ||
} | ||
}); | ||
return target; | ||
} | ||
function toStoreNumber(value) { | ||
if (is.store(value, { | ||
sid: "-hl6vqh" | ||
})) return value; | ||
if (typeof value === 'number') { | ||
if (value < 0 || !Number.isFinite(value)) throw new Error("timeout must be positive number or zero. Received: \"".concat(value, "\"")); | ||
return createStore(value, { | ||
and: { | ||
name: '$timeout' | ||
}, | ||
sid: "pu8pon" | ||
}); | ||
} | ||
throw new TypeError("timeout parameter should be number or Store. \"".concat(typeof value, "\" was passed")); | ||
} |
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
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
314731
2969
785