Comparing version 0.1.3 to 0.1.4
@@ -11,15 +11,15 @@ 'use strict'; | ||
let fx = null; | ||
let h = null, c = null, a = null; | ||
const effects = new WeakMap; | ||
const fx = new WeakMap; | ||
const wrap = (fx, reduced) => ( | ||
fx ? [ | ||
const wrap = (h, c, a, reduced) => ( | ||
h ? [ | ||
reduced[0], | ||
value => { | ||
if (!effects.has(fx)) { | ||
effects.set(fx, 0); | ||
if (!fx.has(h)) { | ||
fx.set(h, 0); | ||
wait.then(() => { | ||
effects.delete(fx); | ||
fx(); | ||
fx.delete(h); | ||
h.apply(c, a); | ||
}); | ||
@@ -36,9 +36,9 @@ } | ||
function hook() { | ||
const prev = fx; | ||
fx = hook; | ||
const [ph, pc, pa] = [h, c, a]; | ||
[h, c, a] = [hook, this, arguments]; | ||
try { | ||
return callback.apply(this, arguments); | ||
return callback.apply(c, a); | ||
} | ||
finally { | ||
fx = prev; | ||
[h, c, a] = [ph, pc, pa]; | ||
} | ||
@@ -51,6 +51,6 @@ } : | ||
const useReducer = (reducer, value, init) => | ||
wrap(fx, $useReducer(reducer, value, init)); | ||
wrap(h, c, a, $useReducer(reducer, value, init)); | ||
exports.useReducer = useReducer; | ||
const useState = value => wrap(fx, $useState(value)); | ||
const useState = value => wrap(h, c, a, $useState(value)); | ||
exports.useState = useState; | ||
@@ -57,0 +57,0 @@ |
@@ -1,3 +0,3 @@ | ||
self.uhooksFX=function(e){"use strict";var t=Promise;let n=null,s=new Set;const o=new WeakMap,c=e=>{const{$:t,r:n,h:s}=e;f(n)&&(a.get(s).delete(e),n()),f(e.r=t())&&a.get(s).add(e)},u=()=>{const e=s;s=new Set,e.forEach(d)},a=new WeakMap,r=[],l=[];function h(e,t){return e!==this[t]}const i=()=>o.get(n),f=e=>"function"==typeof e,p=e=>{const t={h:s,c:null,a:null,e:0,i:0,s:[]};return o.set(s,t),s;function s(){const o=n;n=s,t.e=t.i=0;try{return e.apply(t.c=this,t.a=arguments)}finally{n=o,r.length&&g.then(r.forEach.bind(r.splice(0),c)),l.length&&l.splice(0).forEach(c)}}},d=({h:e,c:t,a:n,e:s})=>{s&&e.apply(t,n)},g=new t((e=>e()));function w(e){const{_:t,value:n}=this;n!==e&&(this._=new Set,this.value=e,t.forEach(d))}const y=(e,t)=>{const n=i(),{i:s,s:o}=n;return s!==o.length&&t&&!t.some(h,o[s]._)||(o[s]={$:e(),_:t}),o[n.i++].$},_=e=>(t,n)=>{const s=i(),{i:o,s:c,h:u}=s,r=o===c.length;r&&(a.has(u)||a.set(u,new Set),c.push({$:t,_:n,r:null,h:u}));const l=c[s.i++];(r||!n||n.some(h,l._))&&e.push(l)},v=_(r),E=_(l),$=(e,t)=>f(t)?t(e):t,k=(e,t,n)=>{const o=i(),{i:c,s:a}=o;c===a.length&&a.push({$:f(n)?n(t):$(void 0,t),set:t=>{a[c].$=e(a[c].$,t),(e=>{s.has(e)||(e.e=1,s.add(e),g.then(u))})(o)}});const{$:r,set:l}=a[o.i++];return[r,l]}; | ||
self.uhooksFX=function(e){"use strict";var t=Promise;let n=null,s=new Set;const l=new WeakMap,o=e=>{const{$:t,r:n,h:s}=e;f(n)&&(c.get(s).delete(e),n()),f(e.r=t())&&c.get(s).add(e)},u=()=>{const e=s;s=new Set,e.forEach(d)},c=new WeakMap,a=[],r=[];function h(e,t){return e!==this[t]}const i=()=>l.get(n),f=e=>"function"==typeof e,p=e=>{const t={h:s,c:null,a:null,e:0,i:0,s:[]};return l.set(s,t),s;function s(){const l=n;n=s,t.e=t.i=0;try{return e.apply(t.c=this,t.a=arguments)}finally{n=l,a.length&&y.then(a.forEach.bind(a.splice(0),o)),r.length&&r.splice(0).forEach(o)}}},d=({h:e,c:t,a:n,e:s})=>{s&&e.apply(t,n)},y=new t((e=>e()));function g(e){const{_:t,value:n}=this;n!==e&&(this._=new Set,this.value=e,t.forEach(d))}const w=(e,t)=>{const n=i(),{i:s,s:l}=n;return s!==l.length&&t&&!t.some(h,l[s]._)||(l[s]={$:e(),_:t}),l[n.i++].$},_=e=>(t,n)=>{const s=i(),{i:l,s:o,h:u}=s,a=l===o.length;a&&(c.has(u)||c.set(u,new Set),o.push({$:t,_:n,r:null,h:u}));const r=o[s.i++];(a||!n||n.some(h,r._))&&e.push(r)},v=_(a),E=_(r),$=(e,t)=>f(t)?t(e):t,k=(e,t,n)=>{const l=i(),{i:o,s:c}=l;o===c.length&&c.push({$:f(n)?n(t):$(void 0,t),set:t=>{c[o].$=e(c[o].$,t),(e=>{s.has(e)||(e.e=1,s.add(e),y.then(u))})(l)}});const{$:a,set:r}=c[l.i++];return[a,r]}; | ||
/*! (c) Andrea Giammarchi - ISC */ | ||
let S=null;const M=new WeakMap,m=(e,t)=>e?[t[0],n=>{M.has(e)||(M.set(e,0),g.then((()=>{M.delete(e),e()}))),t[1](n)}]:t;return e.createContext=e=>({_:new Set,provide:w,value:e}),e.dropEffect=e=>{const t=a.get(e);t&&g.then((()=>{t.forEach((e=>{e.r(),e.r=null})),t.clear()}))},e.hasEffect=e=>a.has(e),e.hooked=(e,t)=>p(t?function t(){const n=S;S=t;try{return e.apply(this,arguments)}finally{S=n}}:e),e.useCallback=(e,t)=>y((()=>e),t),e.useContext=({_:e,value:t})=>(e.add(i()),t),e.useEffect=v,e.useLayoutEffect=E,e.useMemo=y,e.useReducer=(e,t,n)=>m(S,k(e,t,n)),e.useRef=e=>{const t=i(),{i:n,s:s}=t;return n===s.length&&s.push({current:e}),s[t.i++]},e.useState=e=>m(S,(e=>k($,e))(e)),e.wait=g,e}({}); | ||
let S=null,M=null,m=null;const b=new WeakMap,C=(e,t,n,s)=>e?[s[0],l=>{b.has(e)||(b.set(e,0),y.then((()=>{b.delete(e),e.apply(t,n)}))),s[1](l)}]:s;return e.createContext=e=>({_:new Set,provide:g,value:e}),e.dropEffect=e=>{const t=c.get(e);t&&y.then((()=>{t.forEach((e=>{e.r(),e.r=null})),t.clear()}))},e.hasEffect=e=>c.has(e),e.hooked=(e,t)=>p(t?function t(){const[n,s,l]=[S,M,m];[S,M,m]=[t,this,arguments];try{return e.apply(M,m)}finally{[S,M,m]=[n,s,l]}}:e),e.useCallback=(e,t)=>w((()=>e),t),e.useContext=({_:e,value:t})=>(e.add(i()),t),e.useEffect=v,e.useLayoutEffect=E,e.useMemo=w,e.useReducer=(e,t,n)=>C(S,M,m,k(e,t,n)),e.useRef=e=>{const t=i(),{i:n,s:s}=t;return n===s.length&&s.push({current:e}),s[t.i++]},e.useState=e=>C(S,M,m,(e=>k($,e))(e)),e.wait=y,e}({}); |
@@ -10,15 +10,15 @@ /*! (c) Andrea Giammarchi - ISC */ | ||
let fx = null; | ||
let h = null, c = null, a = null; | ||
const effects = new WeakMap; | ||
const fx = new WeakMap; | ||
const wrap = (fx, reduced) => ( | ||
fx ? [ | ||
const wrap = (h, c, a, reduced) => ( | ||
h ? [ | ||
reduced[0], | ||
value => { | ||
if (!effects.has(fx)) { | ||
effects.set(fx, 0); | ||
if (!fx.has(h)) { | ||
fx.set(h, 0); | ||
wait.then(() => { | ||
effects.delete(fx); | ||
fx(); | ||
fx.delete(h); | ||
h.apply(c, a); | ||
}); | ||
@@ -35,9 +35,9 @@ } | ||
function hook() { | ||
const prev = fx; | ||
fx = hook; | ||
const [ph, pc, pa] = [h, c, a]; | ||
[h, c, a] = [hook, this, arguments]; | ||
try { | ||
return callback.apply(this, arguments); | ||
return callback.apply(c, a); | ||
} | ||
finally { | ||
fx = prev; | ||
[h, c, a] = [ph, pc, pa]; | ||
} | ||
@@ -49,5 +49,5 @@ } : | ||
export const useReducer = (reducer, value, init) => | ||
wrap(fx, $useReducer(reducer, value, init)); | ||
wrap(h, c, a, $useReducer(reducer, value, init)); | ||
export const useState = value => wrap(fx, $useState(value)); | ||
export const useState = value => wrap(h, c, a, $useState(value)); | ||
@@ -54,0 +54,0 @@ export { |
36
index.js
@@ -221,12 +221,14 @@ self.uhooksFX = (function (exports) { | ||
/*! (c) Andrea Giammarchi - ISC */ | ||
var fx$1 = null; | ||
var effects$1 = new WeakMap(); | ||
var h$1 = null, | ||
c = null, | ||
a = null; | ||
var fx$1 = new WeakMap(); | ||
var wrap = function wrap(fx, reduced) { | ||
return fx ? [reduced[0], function (value) { | ||
if (!effects$1.has(fx)) { | ||
effects$1.set(fx, 0); | ||
var wrap = function wrap(h, c, a, reduced) { | ||
return h ? [reduced[0], function (value) { | ||
if (!fx$1.has(h)) { | ||
fx$1.set(h, 0); | ||
wait.then(function () { | ||
effects$1["delete"](fx); | ||
fx(); | ||
fx$1["delete"](h); | ||
h.apply(c, a); | ||
}); | ||
@@ -241,9 +243,15 @@ } | ||
return hooked(outer ? function hook() { | ||
var prev = fx$1; | ||
fx$1 = hook; | ||
var ph = h$1, | ||
pc = c, | ||
pa = a; | ||
h$1 = hook; | ||
c = this; | ||
a = arguments; | ||
try { | ||
return callback.apply(this, arguments); | ||
return callback.apply(c, a); | ||
} finally { | ||
fx$1 = prev; | ||
h$1 = ph; | ||
c = pc; | ||
a = pa; | ||
} | ||
@@ -253,6 +261,6 @@ } : callback); | ||
var useReducer$1 = function useReducer$1(reducer, value, init) { | ||
return wrap(fx$1, useReducer(reducer, value, init)); | ||
return wrap(h$1, c, a, useReducer(reducer, value, init)); | ||
}; | ||
var useState$1 = function useState$1(value) { | ||
return wrap(fx$1, useState(value)); | ||
return wrap(h$1, c, a, useState(value)); | ||
}; | ||
@@ -259,0 +267,0 @@ |
@@ -1,1 +0,1 @@ | ||
self.uhooksFX=function(n){"use strict";var t="function"==typeof Promise?Promise:function(n){var t,e=[],u=0;return n((function(n){t=n,u=1,e.splice(0).forEach(r)})),{then:r};function r(n){return u?setTimeout(n,0,t):e.push(n),this}},e=null,u=new Set,r=new WeakMap,i=function(n){var t=n.$,e=n.r,u=n.h;l(e)&&(c.get(u).delete(n),e()),l(n.r=t())&&c.get(u).add(n)},o=function(){var n=u;u=new Set,n.forEach(v)},c=new WeakMap,f=[],a=[];function s(n,t){return n!==this[t]}var h=function(){return r.get(e)},l=function(n){return"function"==typeof n},v=function(n){var t=n.h,e=n.c,u=n.a;n.e&&t.apply(e,u)},p=new t((function(n){return n()}));function d(n){var t=this._;this.value!==n&&(this._=new Set,this.value=n,t.forEach(v))}var g=function(n,t){var e=h(),u=e.i,r=e.s;return u!==r.length&&t&&!t.some(s,r[u]._)||(r[u]={$:n(),_:t}),r[e.i++].$},w=function(n){return function(t,e){var u=h(),r=u.i,i=u.s,o=u.h,f=r===i.length;f&&(c.has(o)||c.set(o,new Set),i.push({$:t,_:e,r:null,h:o}));var a=i[u.i++];(f||!e||e.some(s,a._))&&n.push(a)}},y=w(f),E=w(a),$=function(n,t){return l(t)?t(n):t},_=function(n,t,e){var r=h(),i=r.i,c=r.s;i===c.length&&c.push({$:l(e)?e(t):$(void 0,t),set:function(t){c[i].$=n(c[i].$,t),function(n){u.has(n)||(n.e=1,u.add(n),p.then(o))}(r)}});var f=c[r.i++];return[f.$,f.set]},k=null,m=new WeakMap,S=function(n,t){return n?[t[0],function(e){m.has(n)||(m.set(n,0),p.then((function(){m.delete(n),n()}))),t[1](e)}]:t};return n.createContext=function(n){return{_:new Set,provide:d,value:n}},n.dropEffect=function(n){var t=c.get(n);t&&p.then((function(){t.forEach((function(n){n.r(),n.r=null})),t.clear()}))},n.hasEffect=function(n){return c.has(n)},n.hooked=function(n,t){return function(n){var t={h:u,c:null,a:null,e:0,i:0,s:[]};return r.set(u,t),u;function u(){var r=e;e=u,t.e=t.i=0;try{return n.apply(t.c=this,t.a=arguments)}finally{e=r,f.length&&p.then(f.forEach.bind(f.splice(0),i)),a.length&&a.splice(0).forEach(i)}}}(t?function t(){var e=k;k=t;try{return n.apply(this,arguments)}finally{k=e}}:n)},n.useCallback=function(n,t){return g((function(){return n}),t)},n.useContext=function(n){var t=n._,e=n.value;return t.add(h()),e},n.useEffect=y,n.useLayoutEffect=E,n.useMemo=g,n.useReducer=function(n,t,e){return S(k,_(n,t,e))},n.useRef=function(n){var t=h(),e=t.i,u=t.s;return e===u.length&&u.push({current:n}),u[t.i++]},n.useState=function(n){return S(k,function(n){return _($,n)}(n))},n.wait=p,n}({}); | ||
self.uhooksFX=function(n){"use strict";var t="function"==typeof Promise?Promise:function(n){var t,e=[],u=0;return n((function(n){t=n,u=1,e.splice(0).forEach(r)})),{then:r};function r(n){return u?setTimeout(n,0,t):e.push(n),this}},e=null,u=new Set,r=new WeakMap,i=function(n){var t=n.$,e=n.r,u=n.h;h(e)&&(c.get(u).delete(n),e()),h(n.r=t())&&c.get(u).add(n)},o=function(){var n=u;u=new Set,n.forEach(v)},c=new WeakMap,f=[],a=[];function s(n,t){return n!==this[t]}var l=function(){return r.get(e)},h=function(n){return"function"==typeof n},v=function(n){var t=n.h,e=n.c,u=n.a;n.e&&t.apply(e,u)},p=new t((function(n){return n()}));function d(n){var t=this._;this.value!==n&&(this._=new Set,this.value=n,t.forEach(v))}var y=function(n,t){var e=l(),u=e.i,r=e.s;return u!==r.length&&t&&!t.some(s,r[u]._)||(r[u]={$:n(),_:t}),r[e.i++].$},g=function(n){return function(t,e){var u=l(),r=u.i,i=u.s,o=u.h,f=r===i.length;f&&(c.has(o)||c.set(o,new Set),i.push({$:t,_:e,r:null,h:o}));var a=i[u.i++];(f||!e||e.some(s,a._))&&n.push(a)}},w=g(f),E=g(a),$=function(n,t){return h(t)?t(n):t},_=function(n,t,e){var r=l(),i=r.i,c=r.s;i===c.length&&c.push({$:h(e)?e(t):$(void 0,t),set:function(t){c[i].$=n(c[i].$,t),function(n){u.has(n)||(n.e=1,u.add(n),p.then(o))}(r)}});var f=c[r.i++];return[f.$,f.set]},k=null,m=null,S=null,M=new WeakMap,C=function(n,t,e,u){return n?[u[0],function(r){M.has(n)||(M.set(n,0),p.then((function(){M.delete(n),n.apply(t,e)}))),u[1](r)}]:u};return n.createContext=function(n){return{_:new Set,provide:d,value:n}},n.dropEffect=function(n){var t=c.get(n);t&&p.then((function(){t.forEach((function(n){n.r(),n.r=null})),t.clear()}))},n.hasEffect=function(n){return c.has(n)},n.hooked=function(n,t){return function(n){var t={h:u,c:null,a:null,e:0,i:0,s:[]};return r.set(u,t),u;function u(){var r=e;e=u,t.e=t.i=0;try{return n.apply(t.c=this,t.a=arguments)}finally{e=r,f.length&&p.then(f.forEach.bind(f.splice(0),i)),a.length&&a.splice(0).forEach(i)}}}(t?function t(){var e=k,u=m,r=S;k=t,m=this,S=arguments;try{return n.apply(m,S)}finally{k=e,m=u,S=r}}:n)},n.useCallback=function(n,t){return y((function(){return n}),t)},n.useContext=function(n){var t=n._,e=n.value;return t.add(l()),e},n.useEffect=w,n.useLayoutEffect=E,n.useMemo=y,n.useReducer=function(n,t,e){return C(k,m,S,_(n,t,e))},n.useRef=function(n){var t=l(),e=t.i,u=t.s;return e===u.length&&u.push({current:n}),u[t.i++]},n.useState=function(n){return C(k,m,S,function(n){return _($,n)}(n))},n.wait=p,n}({}); |
{ | ||
"name": "uhooks-fx", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "uhooks with propagated states", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
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
17560
365