@reatom/timer
Advanced tools
Comparing version 3.2.0 to 3.3.0
import { Action, AtomMut } from '@reatom/core'; | ||
export interface TimerAtom extends AtomMut<number> { | ||
/** interval in ms */ | ||
intervalAtom: AtomMut<number> & { | ||
setSeconds: Action<[seconds: number], number>; | ||
}; | ||
/** start timer by passed interval */ | ||
startTimer: Action<[delayInSeconds: number], Promise<void>>; | ||
/** stop timer manually */ | ||
stopTimer: Action<[], void>; | ||
/** track end of timer, do not call manually */ | ||
endTimer: Action<[], void>; | ||
/** track every interval tick, do not call manually */ | ||
tick: Action<[remains: number], number>; | ||
} | ||
@@ -10,0 +16,0 @@ export declare const reatomTimer: (options?: string | { |
@@ -1,2 +0,2 @@ | ||
var t=require("@reatom/core");function n(t,r,i){if(!t.s){if(i instanceof e){if(!i.s)return void(i.o=n.bind(null,t,r));1&r&&(r=i.s),i=i.v}if(i&&i.then)return void i.then(n.bind(null,t,r),n.bind(null,t,2));t.s=r,t.v=i;const o=t.o;o&&o(t)}}const e=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,r){const i=new t,o=this.s;if(o){const t=1&o?e:r;if(t){try{n(i,1,t(this.v))}catch(t){n(i,2,t)}return i}return this}return this.o=function(t){try{const o=t.v;1&t.s?n(i,1,e?e(o):o):r?n(i,1,r(o)):n(i,2,o)}catch(t){n(i,2,t)}},i},t}();function r(t){return t instanceof e&&1&t.s}exports.reatomTimer=(i={})=>{const{name:o=t.__count("timerAtom"),interval:c=1e3}="string"==typeof i?{name:i}:i,s=t.atom(0,`${o}Atom`),u=t.atom(c,`${o}.intervalAtom`).pipe((a={setSeconds:(t,n)=>1e3*n},n=>Object.keys(a).reduce((n,e)=>(n[e]=t.action(function(t){return n(t,a[e](t.get(n),...[].slice.call(arguments,1)))},`${n.__reatom.name}._${e}`),n),n)));var a;const h=t.atom(0,`${o}._versionAtom`),f=t.action((t,i)=>{const o=h(t,t=>t+1),c=1e3*i,a=c+Date.now();let f=c;return s(t,f),t.schedule(function(){try{let c;function i(n){if(c)return n;m(t)}const v=function(t,i,o){for(var c;;){var s=t();if(r(s)&&(s=s.v),!s)return u;if(s.then){c=0;break}var u=o();if(u&&u.then){if(!r(u)){c=1;break}u=u.s}}var a=new e,h=n.bind(null,a,2);return(0===c?s.then(v):1===c?u.then(f):(void 0).then(function(){(s=t())?s.then?s.then(v).then(void 0,h):v(s):n(a,1,u)})).then(void 0,h),a;function f(e){u=e;do{if(!(s=t())||r(s)&&!s.v)return void n(a,1,u);if(s.then)return void s.then(v).then(void 0,h);r(u=o())&&(u=u.v)}while(!u||!u.then);u.then(f).then(void 0,h)}function v(t){t?(u=o())&&u.then?u.then(f).then(void 0,h):f(u):n(a,1,u)}}(function(){return!c&&f>0},0,function(){return Promise.resolve(((t=0)=>new Promise(n=>setTimeout(n,t)))(Math.min(f,t.get(u)))).then(function(){o===t.get(h)?s(t,f=a-Date.now()):c=1})});return Promise.resolve(v&&v.then?v.then(i):i(v))}catch(d){return Promise.reject(d)}})},`${o}.startTimer`),v=t.action(t=>{h(t,t=>t+1),m(t)},`${o}.stopTimer`),m=t.action(t=>{s(t,0)},`${o}.endTimer`);return Object.assign(s,{endTimer:m,intervalAtom:u,startTimer:f,stopTimer:v})}; | ||
var t=require("@reatom/core");function n(t,r,i){if(!t.s){if(i instanceof e){if(!i.s)return void(i.o=n.bind(null,t,r));1&r&&(r=i.s),i=i.v}if(i&&i.then)return void i.then(n.bind(null,t,r),n.bind(null,t,2));t.s=r,t.v=i;const o=t.o;o&&o(t)}}const e=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,r){const i=new t,o=this.s;if(o){const t=1&o?e:r;if(t){try{n(i,1,t(this.v))}catch(t){n(i,2,t)}return i}return this}return this.o=function(t){try{const o=t.v;1&t.s?n(i,1,e?e(o):o):r?n(i,1,r(o)):n(i,2,o)}catch(t){n(i,2,t)}},i},t}();function r(t){return t instanceof e&&1&t.s}exports.reatomTimer=(i={})=>{const{name:o=t.__count("timerAtom"),interval:c=1e3}="string"==typeof i?{name:i}:i,s=t.atom(0,`${o}Atom`),u=t.atom(c,`${o}.intervalAtom`).pipe((a={setSeconds:(t,n)=>1e3*n},n=>Object.keys(a).reduce((n,e)=>(n[e]=t.action(function(t){return n(t,a[e](t.get(n),...[].slice.call(arguments,1)))},`${n.__reatom.name}._${e}`),n),n)));var a;const h=t.atom(0,`${o}._versionAtom`),f=t.action((t,n)=>n,`${o}.tick`),v=t.action((t,i)=>{const o=h(t,t=>t+1),c=1e3*i,a=c+Date.now();let v=c;return s(t,v),t.schedule(function(){try{let c;function i(n){if(c)return n;d(t)}const m=function(t,i,o){for(var c;;){var s=t();if(r(s)&&(s=s.v),!s)return u;if(s.then){c=0;break}var u=o();if(u&&u.then){if(!r(u)){c=1;break}u=u.s}}var a=new e,h=n.bind(null,a,2);return(0===c?s.then(v):1===c?u.then(f):(void 0).then(function(){(s=t())?s.then?s.then(v).then(void 0,h):v(s):n(a,1,u)})).then(void 0,h),a;function f(e){u=e;do{if(!(s=t())||r(s)&&!s.v)return void n(a,1,u);if(s.then)return void s.then(v).then(void 0,h);r(u=o())&&(u=u.v)}while(!u||!u.then);u.then(f).then(void 0,h)}function v(t){t?(u=o())&&u.then?u.then(f).then(void 0,h):f(u):n(a,1,u)}}(function(){return!c&&v>0},0,function(){return Promise.resolve(((t=0)=>new Promise(n=>setTimeout(n,t)))(Math.min(v,t.get(u)))).then(function(){o===t.get(h)?(v=s(t,a-Date.now()),f(t,v)):c=1})});return Promise.resolve(m&&m.then?m.then(i):i(m))}catch(l){return Promise.reject(l)}})},`${o}.startTimer`),m=t.action(t=>{h(t,t=>t+1),d(t)},`${o}.stopTimer`),d=t.action(t=>{s(t,0)},`${o}.endTimer`);return Object.assign(s,{endTimer:d,intervalAtom:u,startTimer:v,stopTimer:m,tick:f})}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{action as t,__count as n,atom as e}from"@reatom/core";function r(t,n,e){if(!t.s){if(e instanceof i){if(!e.s)return void(e.o=r.bind(null,t,n));1&n&&(n=e.s),e=e.v}if(e&&e.then)return void e.then(r.bind(null,t,n),r.bind(null,t,2));t.s=n,t.v=e;const o=t.o;o&&o(t)}}const i=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(n,e){const i=new t,o=this.s;if(o){const t=1&o?n:e;if(t){try{r(i,1,t(this.v))}catch(t){r(i,2,t)}return i}return this}return this.o=function(t){try{const o=t.v;1&t.s?r(i,1,n?n(o):o):e?r(i,1,e(o)):r(i,2,o)}catch(t){r(i,2,t)}},i},t}();function o(t){return t instanceof i&&1&t.s}const s=(s={})=>{const{name:c=n("timerAtom"),interval:u=1e3}="string"==typeof s?{name:s}:s,f=e(0,`${c}Atom`),h=e(u,`${c}.intervalAtom`).pipe((v={setSeconds:(t,n)=>1e3*n},n=>Object.keys(v).reduce((n,e)=>(n[e]=t(function(t){return n(t,v[e](t.get(n),...[].slice.call(arguments,1)))},`${n.__reatom.name}._${e}`),n),n)));var v;const a=e(0,`${c}._versionAtom`),m=t((t,n)=>{const e=a(t,t=>t+1),s=1e3*n,c=s+Date.now();let u=s;return f(t,u),t.schedule(function(){try{let s;function n(n){if(s)return n;l(t)}const v=function(t,n,e){for(var s;;){var c=t();if(o(c)&&(c=c.v),!c)return u;if(c.then){s=0;break}var u=e();if(u&&u.then){if(!o(u)){s=1;break}u=u.s}}var f=new i,h=r.bind(null,f,2);return(0===s?c.then(a):1===s?u.then(v):(void 0).then(function(){(c=t())?c.then?c.then(a).then(void 0,h):a(c):r(f,1,u)})).then(void 0,h),f;function v(n){u=n;do{if(!(c=t())||o(c)&&!c.v)return void r(f,1,u);if(c.then)return void c.then(a).then(void 0,h);o(u=e())&&(u=u.v)}while(!u||!u.then);u.then(v).then(void 0,h)}function a(t){t?(u=e())&&u.then?u.then(v).then(void 0,h):v(u):r(f,1,u)}}(function(){return!s&&u>0},0,function(){return Promise.resolve(((t=0)=>new Promise(n=>setTimeout(n,t)))(Math.min(u,t.get(h)))).then(function(){e===t.get(a)?f(t,u=c-Date.now()):s=1})});return Promise.resolve(v&&v.then?v.then(n):n(v))}catch(m){return Promise.reject(m)}})},`${c}.startTimer`),d=t(t=>{a(t,t=>t+1),l(t)},`${c}.stopTimer`),l=t(t=>{f(t,0)},`${c}.endTimer`);return Object.assign(f,{endTimer:l,intervalAtom:h,startTimer:m,stopTimer:d})};export{s as reatomTimer}; | ||
import{action as t,__count as n,atom as e}from"@reatom/core";function r(t,n,e){if(!t.s){if(e instanceof i){if(!e.s)return void(e.o=r.bind(null,t,n));1&n&&(n=e.s),e=e.v}if(e&&e.then)return void e.then(r.bind(null,t,n),r.bind(null,t,2));t.s=n,t.v=e;const o=t.o;o&&o(t)}}const i=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(n,e){const i=new t,o=this.s;if(o){const t=1&o?n:e;if(t){try{r(i,1,t(this.v))}catch(t){r(i,2,t)}return i}return this}return this.o=function(t){try{const o=t.v;1&t.s?r(i,1,n?n(o):o):e?r(i,1,e(o)):r(i,2,o)}catch(t){r(i,2,t)}},i},t}();function o(t){return t instanceof i&&1&t.s}const c=(c={})=>{const{name:s=n("timerAtom"),interval:u=1e3}="string"==typeof c?{name:c}:c,f=e(0,`${s}Atom`),h=e(u,`${s}.intervalAtom`).pipe((v={setSeconds:(t,n)=>1e3*n},n=>Object.keys(v).reduce((n,e)=>(n[e]=t(function(t){return n(t,v[e](t.get(n),...[].slice.call(arguments,1)))},`${n.__reatom.name}._${e}`),n),n)));var v;const a=e(0,`${s}._versionAtom`),m=t((t,n)=>n,`${s}.tick`),d=t((t,n)=>{const e=a(t,t=>t+1),c=1e3*n,s=c+Date.now();let u=c;return f(t,u),t.schedule(function(){try{let c;function n(n){if(c)return n;p(t)}const v=function(t,n,e){for(var c;;){var s=t();if(o(s)&&(s=s.v),!s)return u;if(s.then){c=0;break}var u=e();if(u&&u.then){if(!o(u)){c=1;break}u=u.s}}var f=new i,h=r.bind(null,f,2);return(0===c?s.then(a):1===c?u.then(v):(void 0).then(function(){(s=t())?s.then?s.then(a).then(void 0,h):a(s):r(f,1,u)})).then(void 0,h),f;function v(n){u=n;do{if(!(s=t())||o(s)&&!s.v)return void r(f,1,u);if(s.then)return void s.then(a).then(void 0,h);o(u=e())&&(u=u.v)}while(!u||!u.then);u.then(v).then(void 0,h)}function a(t){t?(u=e())&&u.then?u.then(v).then(void 0,h):v(u):r(f,1,u)}}(function(){return!c&&u>0},0,function(){return Promise.resolve(((t=0)=>new Promise(n=>setTimeout(n,t)))(Math.min(u,t.get(h)))).then(function(){e===t.get(a)?(u=f(t,s-Date.now()),m(t,u)):c=1})});return Promise.resolve(v&&v.then?v.then(n):n(v))}catch(d){return Promise.reject(d)}})},`${s}.startTimer`),l=t(t=>{a(t,t=>t+1),p(t)},`${s}.stopTimer`),p=t(t=>{f(t,0)},`${s}.endTimer`);return Object.assign(f,{endTimer:p,intervalAtom:h,startTimer:d,stopTimer:l,tick:m})};export{c as reatomTimer}; | ||
//# sourceMappingURL=index.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@reatom/core")):"function"==typeof define&&define.amd?define(["exports","@reatom/core"],e):e((t||self).timer={},t.core)}(this,function(t,e){function n(t,e,i){if(!t.s){if(i instanceof o){if(!i.s)return void(i.o=n.bind(null,t,e));1&e&&(e=i.s),i=i.v}if(i&&i.then)return void i.then(n.bind(null,t,e),n.bind(null,t,2));t.s=e,t.v=i;const r=t.o;r&&r(t)}}const o=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,o){const i=new t,r=this.s;if(r){const t=1&r?e:o;if(t){try{n(i,1,t(this.v))}catch(t){n(i,2,t)}return i}return this}return this.o=function(t){try{const r=t.v;1&t.s?n(i,1,e?e(r):r):o?n(i,1,o(r)):n(i,2,r)}catch(t){n(i,2,t)}},i},t}();function i(t){return t instanceof o&&1&t.s}t.reatomTimer=(t={})=>{const{name:r=e.__count("timerAtom"),interval:c=1e3}="string"==typeof t?{name:t}:t,s=e.atom(0,`${r}Atom`),u=e.atom(c,`${r}.intervalAtom`).pipe((f={setSeconds:(t,e)=>1e3*e},t=>Object.keys(f).reduce((t,n)=>(t[n]=e.action(function(e){return t(e,f[n](e.get(t),...[].slice.call(arguments,1)))},`${t.__reatom.name}._${n}`),t),t)));var f;const a=e.atom(0,`${r}._versionAtom`),h=e.action((t,e)=>{const r=a(t,t=>t+1),c=1e3*e,f=c+Date.now();let h=c;return s(t,h),t.schedule(function(){try{let c;function e(e){if(c)return e;d(t)}const m=function(t,e,r){for(var c;;){var s=t();if(i(s)&&(s=s.v),!s)return u;if(s.then){c=0;break}var u=r();if(u&&u.then){if(!i(u)){c=1;break}u=u.s}}var f=new o,a=n.bind(null,f,2);return(0===c?s.then(m):1===c?u.then(h):(void 0).then(function(){(s=t())?s.then?s.then(m).then(void 0,a):m(s):n(f,1,u)})).then(void 0,a),f;function h(e){u=e;do{if(!(s=t())||i(s)&&!s.v)return void n(f,1,u);if(s.then)return void s.then(m).then(void 0,a);i(u=r())&&(u=u.v)}while(!u||!u.then);u.then(h).then(void 0,a)}function m(t){t?(u=r())&&u.then?u.then(h).then(void 0,a):h(u):n(f,1,u)}}(function(){return!c&&h>0},0,function(){return Promise.resolve(((t=0)=>new Promise(e=>setTimeout(e,t)))(Math.min(h,t.get(u)))).then(function(){r===t.get(a)?s(t,h=f-Date.now()):c=1})});return Promise.resolve(m&&m.then?m.then(e):e(m))}catch(v){return Promise.reject(v)}})},`${r}.startTimer`),m=e.action(t=>{a(t,t=>t+1),d(t)},`${r}.stopTimer`),d=e.action(t=>{s(t,0)},`${r}.endTimer`);return Object.assign(s,{endTimer:d,intervalAtom:u,startTimer:h,stopTimer:m})}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@reatom/core")):"function"==typeof define&&define.amd?define(["exports","@reatom/core"],e):e((t||self).timer={},t.core)}(this,function(t,e){function n(t,e,i){if(!t.s){if(i instanceof o){if(!i.s)return void(i.o=n.bind(null,t,e));1&e&&(e=i.s),i=i.v}if(i&&i.then)return void i.then(n.bind(null,t,e),n.bind(null,t,2));t.s=e,t.v=i;const r=t.o;r&&r(t)}}const o=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,o){const i=new t,r=this.s;if(r){const t=1&r?e:o;if(t){try{n(i,1,t(this.v))}catch(t){n(i,2,t)}return i}return this}return this.o=function(t){try{const r=t.v;1&t.s?n(i,1,e?e(r):r):o?n(i,1,o(r)):n(i,2,r)}catch(t){n(i,2,t)}},i},t}();function i(t){return t instanceof o&&1&t.s}t.reatomTimer=(t={})=>{const{name:r=e.__count("timerAtom"),interval:c=1e3}="string"==typeof t?{name:t}:t,s=e.atom(0,`${r}Atom`),u=e.atom(c,`${r}.intervalAtom`).pipe((f={setSeconds:(t,e)=>1e3*e},t=>Object.keys(f).reduce((t,n)=>(t[n]=e.action(function(e){return t(e,f[n](e.get(t),...[].slice.call(arguments,1)))},`${t.__reatom.name}._${n}`),t),t)));var f;const a=e.atom(0,`${r}._versionAtom`),h=e.action((t,e)=>e,`${r}.tick`),m=e.action((t,e)=>{const r=a(t,t=>t+1),c=1e3*e,f=c+Date.now();let m=c;return s(t,m),t.schedule(function(){try{let c;function e(e){if(c)return e;v(t)}const d=function(t,e,r){for(var c;;){var s=t();if(i(s)&&(s=s.v),!s)return u;if(s.then){c=0;break}var u=r();if(u&&u.then){if(!i(u)){c=1;break}u=u.s}}var f=new o,a=n.bind(null,f,2);return(0===c?s.then(m):1===c?u.then(h):(void 0).then(function(){(s=t())?s.then?s.then(m).then(void 0,a):m(s):n(f,1,u)})).then(void 0,a),f;function h(e){u=e;do{if(!(s=t())||i(s)&&!s.v)return void n(f,1,u);if(s.then)return void s.then(m).then(void 0,a);i(u=r())&&(u=u.v)}while(!u||!u.then);u.then(h).then(void 0,a)}function m(t){t?(u=r())&&u.then?u.then(h).then(void 0,a):h(u):n(f,1,u)}}(function(){return!c&&m>0},0,function(){return Promise.resolve(((t=0)=>new Promise(e=>setTimeout(e,t)))(Math.min(m,t.get(u)))).then(function(){r===t.get(a)?(m=s(t,f-Date.now()),h(t,m)):c=1})});return Promise.resolve(d&&d.then?d.then(e):e(d))}catch(l){return Promise.reject(l)}})},`${r}.startTimer`),d=e.action(t=>{a(t,t=>t+1),v(t)},`${r}.stopTimer`),v=e.action(t=>{s(t,0)},`${r}.endTimer`);return Object.assign(s,{endTimer:v,intervalAtom:u,startTimer:m,stopTimer:d,tick:h})}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@reatom/timer", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -5,2 +5,4 @@ Simple timer model to manage some countdown. | ||
import { reatomTimer } from '@reatom/timer' | ||
const timer = reatomTimer({ interval: 1000 }) | ||
``` | ||
@@ -10,13 +12,15 @@ | ||
export interface TimerAtom extends AtomMut<number> { | ||
// interval in ms | ||
/** interval in ms */ | ||
intervalAtom: AtomMut<number> & { | ||
setSeconds: Action<[seconds: number], number> | ||
} | ||
// start timer by passed interval | ||
/** start timer by passed interval */ | ||
startTimer: Action<[delayInSeconds: number], Promise<void>> | ||
// stop timer manually | ||
/** stop timer manually */ | ||
stopTimer: Action<[], void> | ||
// track end of timer, do not call manually | ||
/** track end of timer, do not call manually */ | ||
endTimer: Action<[], void> | ||
/** track every interval tick, do not call manually */ | ||
tick: Action<[remains: number], number> | ||
} | ||
``` |
@@ -6,12 +6,14 @@ import { Action, action, atom, AtomMut, __count } from '@reatom/core' | ||
export interface TimerAtom extends AtomMut<number> { | ||
// interval in ms | ||
/** interval in ms */ | ||
intervalAtom: AtomMut<number> & { | ||
setSeconds: Action<[seconds: number], number> | ||
} | ||
// start timer by passed interval | ||
/** start timer by passed interval */ | ||
startTimer: Action<[delayInSeconds: number], Promise<void>> | ||
// stop timer manually | ||
/** stop timer manually */ | ||
stopTimer: Action<[], void> | ||
// track end of timer, do not call manually | ||
/** track end of timer, do not call manually */ | ||
endTimer: Action<[], void> | ||
/** track every interval tick, do not call manually */ | ||
tick: Action<[remains: number], number> | ||
} | ||
@@ -37,2 +39,7 @@ | ||
const tick: TimerAtom['tick'] = action( | ||
(ctx, remains) => remains, | ||
`${name}.tick`, | ||
) | ||
const startTimer: TimerAtom['startTimer'] = action( | ||
@@ -54,3 +61,4 @@ (ctx, delayInSeconds: number) => { | ||
timerAtom(ctx, (remains = target - Date.now())) | ||
remains = timerAtom(ctx, target - Date.now()) | ||
tick(ctx, remains) | ||
} | ||
@@ -78,3 +86,4 @@ | ||
stopTimer, | ||
tick, | ||
}) | ||
} |
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
45187
150
25