Comparing version
@@ -1,2 +0,2 @@ | ||
/* hydroxide v0.10.0 */ | ||
/* hydroxide v0.11.0 */ | ||
'use strict'; | ||
@@ -92,6 +92,7 @@ | ||
const LIST_PHASE = 0; | ||
const DATA_PHASE = 0; | ||
const CONNECTION_PHASE = 1; | ||
const RENDER_PHASE = 2; | ||
const USER_EFFECT_PHASE = 3; | ||
const LIST_PHASE = 2; | ||
const RENDER_PHASE = 3; | ||
const USER_EFFECT_PHASE = 4; | ||
/** information about batching */ | ||
@@ -157,7 +158,35 @@ | ||
function invalidate(reactive) { | ||
if (!batching.enabled) { | ||
// batching enabled or not | ||
// data effects are executed right away for consistency | ||
// list phase is executed right for performance | ||
// data phase | ||
if (reactive.subs[DATA_PHASE]) { | ||
reactive.subs[DATA_PHASE].forEach(cb => cb()); | ||
} // connection phase | ||
if (batching.enabled && !invalidatedReactives.has(reactive)) { | ||
if (reactive.subs[CONNECTION_PHASE]) { | ||
connectionQueue.push(reactive.subs[CONNECTION_PHASE]); | ||
} | ||
} else { | ||
if (reactive.subs[CONNECTION_PHASE]) { | ||
reactive.subs[CONNECTION_PHASE].forEach(cb => cb()); | ||
} | ||
} // list update phase | ||
if (reactive.subs[LIST_PHASE]) { | ||
const inv = reactive.listInvalidator; | ||
if (inv) { | ||
// @ts-expect-error - we only care about first argument | ||
reactive.subs[LIST_PHASE].forEach(inv); // @ts-expect-error | ||
reactive.listInvalidator = undefined; | ||
} | ||
} // render and user effect phase | ||
if (!batching.enabled) { | ||
if (reactive.subs[RENDER_PHASE]) { | ||
@@ -235,3 +264,3 @@ reactive.subs[RENDER_PHASE].forEach(cb => cb()); | ||
function effect(callback, phase = USER_EFFECT_PHASE, sync = false) { | ||
function effect(callback, phase = USER_EFFECT_PHASE) { | ||
let deps = new Set(); | ||
@@ -261,5 +290,8 @@ const effectContext = coreInfo.context; | ||
deps.forEach(dep => subscribe(dep, runEffect, phase, effectContext)); | ||
} | ||
} // initialize the effect right away | ||
// if the effect is effect is of type data or render | ||
// or if there's no context | ||
if (phase === RENDER_PHASE || sync || !effectContext) { | ||
if (phase === RENDER_PHASE || phase === DATA_PHASE || !effectContext) { | ||
createEffect(); | ||
@@ -285,6 +317,18 @@ } // other phase effects are initialized after the context is connected | ||
let value; | ||
let deps; | ||
effect(() => { | ||
value = fn(); | ||
}, USER_EFFECT_PHASE, true); | ||
return () => value; | ||
value = fn(); // update deps | ||
deps = coreInfo.detected; | ||
}, DATA_PHASE); | ||
return () => { | ||
// pass the deps of effect to detector | ||
if (deps && coreInfo.detectorEnabled) { | ||
deps.forEach(dep => { | ||
coreInfo.detected.add(dep); | ||
}); | ||
} | ||
return value; | ||
}; | ||
} | ||
@@ -405,5 +449,6 @@ | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
state.listInvalidator = cb => { | ||
cb('set', path, newValue); | ||
}); | ||
}; | ||
} | ||
@@ -532,5 +577,6 @@ | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
state.listInvalidator = cb => { | ||
cb('set', null, newValue); | ||
}); | ||
}; | ||
} | ||
@@ -556,5 +602,6 @@ | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
state.listInvalidator = cb => { | ||
cb('insert', i, values); | ||
}); | ||
}; | ||
} | ||
@@ -575,5 +622,6 @@ | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
state.listInvalidator = cb => { | ||
cb('remove', i, count); | ||
}); | ||
}; | ||
} | ||
@@ -600,7 +648,5 @@ | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
cb('clear'); | ||
}); | ||
} | ||
state.listInvalidator = cb => { | ||
cb('clear'); | ||
}; | ||
@@ -623,5 +669,6 @@ invalidate(state); | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
state.listInvalidator = cb => { | ||
cb('swap', i, j); | ||
}); | ||
}; | ||
} | ||
@@ -647,3 +694,3 @@ | ||
state.value = value; | ||
state.subs = new Array(4); | ||
state.subs = new Array(5); | ||
state.context = coreInfo.context; | ||
@@ -680,2 +727,3 @@ state.mutable = true; | ||
exports.CONNECTION_PHASE = CONNECTION_PHASE; | ||
exports.DATA_PHASE = DATA_PHASE; | ||
exports.LIST_PHASE = LIST_PHASE; | ||
@@ -682,0 +730,0 @@ exports.RENDER_PHASE = RENDER_PHASE; |
@@ -1,2 +0,2 @@ | ||
/* hydroxide v0.10.0 */ | ||
/* hydroxide v0.11.0 */ | ||
function targetKey(obj, path) { | ||
@@ -88,6 +88,7 @@ if (path.length === 1) return [obj, path[0]]; | ||
const LIST_PHASE = 0; | ||
const DATA_PHASE = 0; | ||
const CONNECTION_PHASE = 1; | ||
const RENDER_PHASE = 2; | ||
const USER_EFFECT_PHASE = 3; | ||
const LIST_PHASE = 2; | ||
const RENDER_PHASE = 3; | ||
const USER_EFFECT_PHASE = 4; | ||
/** information about batching */ | ||
@@ -153,7 +154,35 @@ | ||
function invalidate(reactive) { | ||
if (!batching.enabled) { | ||
// batching enabled or not | ||
// data effects are executed right away for consistency | ||
// list phase is executed right for performance | ||
// data phase | ||
if (reactive.subs[DATA_PHASE]) { | ||
reactive.subs[DATA_PHASE].forEach(cb => cb()); | ||
} // connection phase | ||
if (batching.enabled && !invalidatedReactives.has(reactive)) { | ||
if (reactive.subs[CONNECTION_PHASE]) { | ||
connectionQueue.push(reactive.subs[CONNECTION_PHASE]); | ||
} | ||
} else { | ||
if (reactive.subs[CONNECTION_PHASE]) { | ||
reactive.subs[CONNECTION_PHASE].forEach(cb => cb()); | ||
} | ||
} // list update phase | ||
if (reactive.subs[LIST_PHASE]) { | ||
const inv = reactive.listInvalidator; | ||
if (inv) { | ||
// @ts-expect-error - we only care about first argument | ||
reactive.subs[LIST_PHASE].forEach(inv); // @ts-expect-error | ||
reactive.listInvalidator = undefined; | ||
} | ||
} // render and user effect phase | ||
if (!batching.enabled) { | ||
if (reactive.subs[RENDER_PHASE]) { | ||
@@ -231,3 +260,3 @@ reactive.subs[RENDER_PHASE].forEach(cb => cb()); | ||
function effect(callback, phase = USER_EFFECT_PHASE, sync = false) { | ||
function effect(callback, phase = USER_EFFECT_PHASE) { | ||
let deps = new Set(); | ||
@@ -257,5 +286,8 @@ const effectContext = coreInfo.context; | ||
deps.forEach(dep => subscribe(dep, runEffect, phase, effectContext)); | ||
} | ||
} // initialize the effect right away | ||
// if the effect is effect is of type data or render | ||
// or if there's no context | ||
if (phase === RENDER_PHASE || sync || !effectContext) { | ||
if (phase === RENDER_PHASE || phase === DATA_PHASE || !effectContext) { | ||
createEffect(); | ||
@@ -281,6 +313,18 @@ } // other phase effects are initialized after the context is connected | ||
let value; | ||
let deps; | ||
effect(() => { | ||
value = fn(); | ||
}, USER_EFFECT_PHASE, true); | ||
return () => value; | ||
value = fn(); // update deps | ||
deps = coreInfo.detected; | ||
}, DATA_PHASE); | ||
return () => { | ||
// pass the deps of effect to detector | ||
if (deps && coreInfo.detectorEnabled) { | ||
deps.forEach(dep => { | ||
coreInfo.detected.add(dep); | ||
}); | ||
} | ||
return value; | ||
}; | ||
} | ||
@@ -401,5 +445,6 @@ | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
state.listInvalidator = cb => { | ||
cb('set', path, newValue); | ||
}); | ||
}; | ||
} | ||
@@ -528,5 +573,6 @@ | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
state.listInvalidator = cb => { | ||
cb('set', null, newValue); | ||
}); | ||
}; | ||
} | ||
@@ -552,5 +598,6 @@ | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
state.listInvalidator = cb => { | ||
cb('insert', i, values); | ||
}); | ||
}; | ||
} | ||
@@ -571,5 +618,6 @@ | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
state.listInvalidator = cb => { | ||
cb('remove', i, count); | ||
}); | ||
}; | ||
} | ||
@@ -596,7 +644,5 @@ | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
cb('clear'); | ||
}); | ||
} | ||
state.listInvalidator = cb => { | ||
cb('clear'); | ||
}; | ||
@@ -619,5 +665,6 @@ invalidate(state); | ||
if (state.subs[LIST_PHASE]) { | ||
state.subs[LIST_PHASE].forEach(cb => { | ||
state.listInvalidator = cb => { | ||
cb('swap', i, j); | ||
}); | ||
}; | ||
} | ||
@@ -643,3 +690,3 @@ | ||
state.value = value; | ||
state.subs = new Array(4); | ||
state.subs = new Array(5); | ||
state.context = coreInfo.context; | ||
@@ -675,2 +722,2 @@ state.mutable = true; | ||
export { CONNECTION_PHASE, LIST_PHASE, RENDER_PHASE, USER_EFFECT_PHASE, batch, batching, coreInfo, detect, effect, invalidate, memo, onConnect, onDisconnect, reactive, subscribe, targetKey, unsubscribe, valueAt }; | ||
export { CONNECTION_PHASE, DATA_PHASE, LIST_PHASE, RENDER_PHASE, USER_EFFECT_PHASE, batch, batching, coreInfo, detect, effect, invalidate, memo, onConnect, onDisconnect, reactive, subscribe, targetKey, unsubscribe, valueAt }; |
@@ -1,1 +0,1 @@ | ||
"use strict";function e(e,t){if(1===t.length)return[e,t[0]];const n=t.length-1;let s=e;for(let e=0;e<n;e++)s=s[t[e]];return[s,t[n]]}function t(e,t,n=0,s=t.length-1){let o=e;for(let e=n;e<=s;e++)o=o[t[e]];return o}function n(e){const t=N.detected,n=N.detectorEnabled;N.detectorEnabled=!0,N.detected=new Set;const s=e(),o=N.detected;return n&&o.forEach((e=>{t.add(e)})),N.detectorEnabled=n,N.detected=t,[o,s]}Object.defineProperty(exports,"__esModule",{value:!0});const s=new Set,o={enabled:!1,cloned:new Set},c=[],u=[],i=[];function a(e,t){for(let n=0;n<t;n++){const t=e[n];for(const e of t)e()}e.splice(0,t)}function l(){s.clear();const e=c.length,t=u.length,n=i.length;0!==e&&a(c,e),0!==t&&a(u,t),0!==n&&a(i,n),0!==s.size&&l()}function r(e){o.enabled?s.has(e)||(s.add(e),e.subs[1]&&c.push(e.subs[1]),e.subs[2]&&u.push(e.subs[2]),e.subs[3]&&i.push(e.subs[3])):(e.subs[1]&&e.subs[1].forEach((e=>e())),e.subs[2]&&e.subs[2].forEach((e=>e())),e.subs[3]&&e.subs[3].forEach((e=>e())))}function h(e,t,n,s=N.context){const o=e.subs[n]||(e.subs[n]=new Set);if(o.add(t),s!==e.context){const e=()=>{o.delete(t)},n=()=>{o.add(t)};s.onDisconnect?s.onDisconnect.push(e):s.onDisconnect=[e],s.onConnect?s.onConnect.push(n):s.onConnect=[n]}}function d(e,t,n){e.subs[n].delete(t)}function f(e,t=3,s=!1){let o=new Set;const c=N.context;function u(){const s=n(e)[0];o.forEach((e=>{s.has(e)||d(e,u,t)})),s.forEach((e=>{o.has(e)||h(e,u,t,c)})),o=s}function i(){o=n(e)[0],o.forEach((e=>h(e,u,t,c)))}2===t||s||!c?i():c.onConnect?c.onConnect.push(i):c.onConnect=[i]}function b(e,t,n){const s=e[t];e[t]=e[n],e[n]=s}function p(e,t,n){if(o.enabled&&o.cloned.has(e))return e.splice(t,n),e;const s=[...e.slice(0,t),...e.slice(t+n)];return o.enabled&&o.cloned.add(s),s}function v(e,t,n){const s=g(e),o=t.length-1;let c=s;for(let e=0;e<o;e++)c[t[e]]=g(c[t[e]]),c=c[t[e]];return c[t[o]]=n,s}function x(e,t,n){if(o.enabled&&o.cloned.has(e))return e.splice(t,0,...n),e;const s=[...e.slice(0,t),...n,...e.slice(t)];return o.enabled&&o.cloned.add(s),s}function E(e,t,n){if(o.enabled&&o.cloned.has(e))return b(e,t,n),e;const s=[...e];return b(s,t,n),o.enabled&&o.cloned.add(s),s}function g(e){if(o.enabled&&o.cloned.has(e))return e;const t=Array.isArray(e)?[...e]:{...e};return o.enabled&&o.cloned.add(t),t}class m{constructor(e,t){this.reactive=e,this.path=t}set(e){const t=this.reactive,n=this.path;if(t.mutable){const s=n.length-1;let o=t.value;for(let e=0;e<s;e++)o=o[n[e]];if(e===o[n[s]])return;o[n[s]]=e}else t.value=v(t.value,n,e);t.subs[0]&&t.subs[0].forEach((t=>{t("set",n,e)})),r(t)}do(e){const n=t(this.reactive.value,this.path),s=e(n);n!==s&&this.set(s)}insertList(e,n){const{reactive:s,path:o}=this,c=t(s.value,o),u=e<0?c.length+e+1:e;s.mutable?c.splice(u,0,...n):s.value=v(s.value,o,x(c,u,n)),r(s)}remove(e,n=1){const{reactive:s,path:o}=this,c=t(s.value,o),u=e<0?c.length+e:e;s.mutable?c.splice(u,n):s.value=v(s.value,o,p(c,u,n)),r(s)}insert(e,t){this.insertList(e,[t])}clear(){const t=this.reactive,n=this.path,[s,o]=e(t.value,n),c=s[o];0!==c.length&&(t.mutable?s[o]=[]:t.value=v(c,n,[]),r(t))}swap(e,n){const s=this.reactive,o=this.path,c=t(s.value,o);if(s.mutable)b(c,e,n);else{const c=t(s.value,o);s.value=v(s.value,o,E(c,e,n))}r(s)}push(e){this.insertList(-1,[e])}pushList(e){this.insertList(-1,e)}pop(e=1){this.remove(-1*e,e)}}function C(e){const t=this;e!==t.value&&(t.value=e,t.subs[0]&&t.subs[0].forEach((t=>{t("set",null,e)})),r(t))}function S(e){const t=e(this.value);this.value!==t&&this.set(t)}function w(e,t){const n=this,s=e<0?this.value.length+e+1:e;n.mutable?n.value.splice(s,0,...t):n.value=x(n.value,s,t),n.subs[0]&&n.subs[0].forEach((e=>{e("insert",s,t)})),r(n)}function L(e,t=1){const n=this,s=e<0?n.value.length+e:e;n.mutable?n.value.splice(s,t):n.value=p(n.value,s,t),n.subs[0]&&n.subs[0].forEach((e=>{e("remove",s,t)})),r(n)}function A(e,t){this.insertList(e,[t])}function D(e){this.insertList(-1,[e])}function y(e){this.insertList(-1,e)}function _(e=1){this.remove(-1*e,e)}function P(){const e=this;0!==e.value.length&&(e.value=[],e.subs[0]&&e.subs[0].forEach((e=>{e("clear")})),r(e))}function H(e,t){const n=this;n.mutable?b(n.value,e,t):n.value=E(n.value,e,t),n.subs[0]&&n.subs[0].forEach((n=>{n("swap",e,t)})),r(n)}const N={context:null,detectorEnabled:!1,detected:new Set};exports.CONNECTION_PHASE=1,exports.LIST_PHASE=0,exports.RENDER_PHASE=2,exports.USER_EFFECT_PHASE=3,exports.batch=function(e){o.enabled=!0,e(),o.enabled=!1,o.cloned.clear(),l()},exports.batching=o,exports.coreInfo=N,exports.detect=n,exports.effect=f,exports.invalidate=r,exports.memo=function(e){let t;return f((()=>{t=e()}),3,!0),()=>t},exports.onConnect=function(e){N.context.onConnect?N.context.onConnect.push(e):N.context.onConnect=[e]},exports.onDisconnect=function(e){N.context.onDisconnect?N.context.onDisconnect.push(e):N.context.onDisconnect=[e]},exports.reactive=function(e){const t=function(...e){return 0!==e.length?new m(t,e):(N.detectorEnabled&&N.detected.add(t),t.value)};return t.value=e,t.subs=new Array(4),t.context=N.context,t.mutable=!0,t.set=C,t.do=S,Array.isArray(e)&&(t.insert=A,t.insertList=w,t.remove=L,t.swap=H,t.clear=P,t.push=D,t.pushList=y,t.pop=_),t},exports.subscribe=h,exports.targetKey=e,exports.unsubscribe=d,exports.valueAt=t; | ||
"use strict";function t(t,e){if(1===e.length)return[t,e[0]];const n=e.length-1;let s=t;for(let t=0;t<n;t++)s=s[e[t]];return[s,e[n]]}function e(t,e,n=0,s=e.length-1){let o=t;for(let t=n;t<=s;t++)o=o[e[t]];return o}function n(t){const e=H.detected,n=H.detectorEnabled;H.detectorEnabled=!0,H.detected=new Set;const s=t(),o=H.detected;return n&&o.forEach((t=>{e.add(t)})),H.detectorEnabled=n,H.detected=e,[o,s]}Object.defineProperty(exports,"__esModule",{value:!0});const s=new Set,o={enabled:!1,cloned:new Set},c=[],i=[],l=[];function u(t,e){for(let n=0;n<e;n++){const e=t[n];for(const t of e)t()}t.splice(0,e)}function a(){s.clear();const t=c.length,e=i.length,n=l.length;0!==t&&u(c,t),0!==e&&u(i,e),0!==n&&u(l,n),0!==s.size&&a()}function r(t){if(t.subs[0]&&t.subs[0].forEach((t=>t())),o.enabled&&!s.has(t)?t.subs[1]&&c.push(t.subs[1]):t.subs[1]&&t.subs[1].forEach((t=>t())),t.subs[2]){const e=t.listInvalidator;e&&(t.subs[2].forEach(e),t.listInvalidator=void 0)}o.enabled?s.has(t)||(s.add(t),t.subs[1]&&c.push(t.subs[1]),t.subs[3]&&i.push(t.subs[3]),t.subs[4]&&l.push(t.subs[4])):(t.subs[3]&&t.subs[3].forEach((t=>t())),t.subs[4]&&t.subs[4].forEach((t=>t())))}function d(t,e,n,s=H.context){const o=t.subs[n]||(t.subs[n]=new Set);if(o.add(e),s!==t.context){const t=()=>{o.delete(e)},n=()=>{o.add(e)};s.onDisconnect?s.onDisconnect.push(t):s.onDisconnect=[t],s.onConnect?s.onConnect.push(n):s.onConnect=[n]}}function h(t,e,n){t.subs[n].delete(e)}function f(t,e=4){let s=new Set;const o=H.context;function c(){const i=n(t)[0];s.forEach((t=>{i.has(t)||h(t,c,e)})),i.forEach((t=>{s.has(t)||d(t,c,e,o)})),s=i}function i(){s=n(t)[0],s.forEach((t=>d(t,c,e,o)))}3!==e&&0!==e&&o?o.onConnect?o.onConnect.push(i):o.onConnect=[i]:i()}function b(t,e,n){const s=t[e];t[e]=t[n],t[n]=s}function v(t,e,n){if(o.enabled&&o.cloned.has(t))return t.splice(e,n),t;const s=[...t.slice(0,e),...t.slice(e+n)];return o.enabled&&o.cloned.add(s),s}function p(t,e,n){const s=g(t),o=e.length-1;let c=s;for(let t=0;t<o;t++)c[e[t]]=g(c[e[t]]),c=c[e[t]];return c[e[o]]=n,s}function x(t,e,n){if(o.enabled&&o.cloned.has(t))return t.splice(e,0,...n),t;const s=[...t.slice(0,e),...n,...t.slice(e)];return o.enabled&&o.cloned.add(s),s}function E(t,e,n){if(o.enabled&&o.cloned.has(t))return b(t,e,n),t;const s=[...t];return b(s,e,n),o.enabled&&o.cloned.add(s),s}function g(t){if(o.enabled&&o.cloned.has(t))return t;const e=Array.isArray(t)?[...t]:{...t};return o.enabled&&o.cloned.add(e),e}class m{constructor(t,e){this.reactive=t,this.path=e}set(t){const e=this.reactive,n=this.path;if(e.mutable){const s=n.length-1;let o=e.value;for(let t=0;t<s;t++)o=o[n[t]];if(t===o[n[s]])return;o[n[s]]=t}else e.value=p(e.value,n,t);e.subs[2]&&(e.listInvalidator=e=>{e("set",n,t)}),r(e)}do(t){const n=e(this.reactive.value,this.path),s=t(n);n!==s&&this.set(s)}insertList(t,n){const{reactive:s,path:o}=this,c=e(s.value,o),i=t<0?c.length+t+1:t;s.mutable?c.splice(i,0,...n):s.value=p(s.value,o,x(c,i,n)),r(s)}remove(t,n=1){const{reactive:s,path:o}=this,c=e(s.value,o),i=t<0?c.length+t:t;s.mutable?c.splice(i,n):s.value=p(s.value,o,v(c,i,n)),r(s)}insert(t,e){this.insertList(t,[e])}clear(){const e=this.reactive,n=this.path,[s,o]=t(e.value,n),c=s[o];0!==c.length&&(e.mutable?s[o]=[]:e.value=p(c,n,[]),r(e))}swap(t,n){const s=this.reactive,o=this.path,c=e(s.value,o);if(s.mutable)b(c,t,n);else{const c=e(s.value,o);s.value=p(s.value,o,E(c,t,n))}r(s)}push(t){this.insertList(-1,[t])}pushList(t){this.insertList(-1,t)}pop(t=1){this.remove(-1*t,t)}}function A(t){const e=this;t!==e.value&&(e.value=t,e.subs[2]&&(e.listInvalidator=e=>{e("set",null,t)}),r(e))}function C(t){const e=t(this.value);this.value!==e&&this.set(e)}function S(t,e){const n=this,s=t<0?this.value.length+t+1:t;n.mutable?n.value.splice(s,0,...e):n.value=x(n.value,s,e),n.subs[2]&&(n.listInvalidator=t=>{t("insert",s,e)}),r(n)}function w(t,e=1){const n=this,s=t<0?n.value.length+t:t;n.mutable?n.value.splice(s,e):n.value=v(n.value,s,e),n.subs[2]&&(n.listInvalidator=t=>{t("remove",s,e)}),r(n)}function I(t,e){this.insertList(t,[e])}function L(t){this.insertList(-1,[t])}function D(t){this.insertList(-1,t)}function _(t=1){this.remove(-1*t,t)}function y(){const t=this;0!==t.value.length&&(t.value=[],t.listInvalidator=t=>{t("clear")},r(t))}function P(t,e){const n=this;n.mutable?b(n.value,t,e):n.value=E(n.value,t,e),n.subs[2]&&(n.listInvalidator=n=>{n("swap",t,e)}),r(n)}const H={context:null,detectorEnabled:!1,detected:new Set};exports.CONNECTION_PHASE=1,exports.DATA_PHASE=0,exports.LIST_PHASE=2,exports.RENDER_PHASE=3,exports.USER_EFFECT_PHASE=4,exports.batch=function(t){o.enabled=!0,t(),o.enabled=!1,o.cloned.clear(),a()},exports.batching=o,exports.coreInfo=H,exports.detect=n,exports.effect=f,exports.invalidate=r,exports.memo=function(t){let e,n;return f((()=>{e=t(),n=H.detected}),0),()=>(n&&H.detectorEnabled&&n.forEach((t=>{H.detected.add(t)})),e)},exports.onConnect=function(t){H.context.onConnect?H.context.onConnect.push(t):H.context.onConnect=[t]},exports.onDisconnect=function(t){H.context.onDisconnect?H.context.onDisconnect.push(t):H.context.onDisconnect=[t]},exports.reactive=function(t){const e=function(...t){return 0!==t.length?new m(e,t):(H.detectorEnabled&&H.detected.add(e),e.value)};return e.value=t,e.subs=new Array(5),e.context=H.context,e.mutable=!0,e.set=A,e.do=C,Array.isArray(t)&&(e.insert=I,e.insertList=S,e.remove=w,e.swap=P,e.clear=y,e.push=L,e.pushList=D,e.pop=_),e},exports.subscribe=d,exports.targetKey=t,exports.unsubscribe=h,exports.valueAt=e; |
@@ -1,1 +0,1 @@ | ||
function e(e,t){if(1===t.length)return[e,t[0]];const n=t.length-1;let s=e;for(let e=0;e<n;e++)s=s[t[e]];return[s,t[n]]}function t(e,t,n=0,s=t.length-1){let c=e;for(let e=n;e<=s;e++)c=c[t[e]];return c}function n(e){N.context.onConnect?N.context.onConnect.push(e):N.context.onConnect=[e]}function s(e){N.context.onDisconnect?N.context.onDisconnect.push(e):N.context.onDisconnect=[e]}function c(e){const t=N.detected,n=N.detectorEnabled;N.detectorEnabled=!0,N.detected=new Set;const s=e(),c=N.detected;return n&&c.forEach((e=>{t.add(e)})),N.detectorEnabled=n,N.detected=t,[c,s]}const o=new Set,u=0,l=1,i=2,a=3,r={enabled:!1,cloned:new Set},h=[],d=[],f=[];function b(e,t){for(let n=0;n<t;n++){const t=e[n];for(const e of t)e()}e.splice(0,t)}function v(){o.clear();const e=h.length,t=d.length,n=f.length;0!==e&&b(h,e),0!==t&&b(d,t),0!==n&&b(f,n),0!==o.size&&v()}function p(e){r.enabled=!0,e(),r.enabled=!1,r.cloned.clear(),v()}function E(e){r.enabled?o.has(e)||(o.add(e),e.subs[1]&&h.push(e.subs[1]),e.subs[2]&&d.push(e.subs[2]),e.subs[3]&&f.push(e.subs[3])):(e.subs[1]&&e.subs[1].forEach((e=>e())),e.subs[2]&&e.subs[2].forEach((e=>e())),e.subs[3]&&e.subs[3].forEach((e=>e())))}function g(e,t,n,s=N.context){const c=e.subs[n]||(e.subs[n]=new Set);if(c.add(t),s!==e.context){const e=()=>{c.delete(t)},n=()=>{c.add(t)};s.onDisconnect?s.onDisconnect.push(e):s.onDisconnect=[e],s.onConnect?s.onConnect.push(n):s.onConnect=[n]}}function m(e,t,n){e.subs[n].delete(t)}function x(e,t=3,n=!1){let s=new Set;const o=N.context;function u(){const n=c(e)[0];s.forEach((e=>{n.has(e)||m(e,u,t)})),n.forEach((e=>{s.has(e)||g(e,u,t,o)})),s=n}function l(){s=c(e)[0],s.forEach((e=>g(e,u,t,o)))}2===t||n||!o?l():o.onConnect?o.onConnect.push(l):o.onConnect=[l]}function w(e){let t;return x((()=>{t=e()}),3,!0),()=>t}function L(e,t,n){const s=e[t];e[t]=e[n],e[n]=s}function C(e,t,n){if(r.enabled&&r.cloned.has(e))return e.splice(t,n),e;const s=[...e.slice(0,t),...e.slice(t+n)];return r.enabled&&r.cloned.add(s),s}function D(e,t,n){const s=A(e),c=t.length-1;let o=s;for(let e=0;e<c;e++)o[t[e]]=A(o[t[e]]),o=o[t[e]];return o[t[c]]=n,s}function S(e,t,n){if(r.enabled&&r.cloned.has(e))return e.splice(t,0,...n),e;const s=[...e.slice(0,t),...n,...e.slice(t)];return r.enabled&&r.cloned.add(s),s}function y(e,t,n){if(r.enabled&&r.cloned.has(e))return L(e,t,n),e;const s=[...e];return L(s,t,n),r.enabled&&r.cloned.add(s),s}function A(e){if(r.enabled&&r.cloned.has(e))return e;const t=Array.isArray(e)?[...e]:{...e};return r.enabled&&r.cloned.add(t),t}class z{constructor(e,t){this.reactive=e,this.path=t}set(e){const t=this.reactive,n=this.path;if(t.mutable){const s=n.length-1;let c=t.value;for(let e=0;e<s;e++)c=c[n[e]];if(e===c[n[s]])return;c[n[s]]=e}else t.value=D(t.value,n,e);t.subs[0]&&t.subs[0].forEach((t=>{t("set",n,e)})),E(t)}do(e){const n=t(this.reactive.value,this.path),s=e(n);n!==s&&this.set(s)}insertList(e,n){const{reactive:s,path:c}=this,o=t(s.value,c),u=e<0?o.length+e+1:e;s.mutable?o.splice(u,0,...n):s.value=D(s.value,c,S(o,u,n)),E(s)}remove(e,n=1){const{reactive:s,path:c}=this,o=t(s.value,c),u=e<0?o.length+e:e;s.mutable?o.splice(u,n):s.value=D(s.value,c,C(o,u,n)),E(s)}insert(e,t){this.insertList(e,[t])}clear(){const t=this.reactive,n=this.path,[s,c]=e(t.value,n),o=s[c];0!==o.length&&(t.mutable?s[c]=[]:t.value=D(o,n,[]),E(t))}swap(e,n){const s=this.reactive,c=this.path,o=t(s.value,c);if(s.mutable)L(o,e,n);else{const o=t(s.value,c);s.value=D(s.value,c,y(o,e,n))}E(s)}push(e){this.insertList(-1,[e])}pushList(e){this.insertList(-1,e)}pop(e=1){this.remove(-1*e,e)}}function j(e){const t=this;e!==t.value&&(t.value=e,t.subs[0]&&t.subs[0].forEach((t=>{t("set",null,e)})),E(t))}function k(e){const t=e(this.value);this.value!==t&&this.set(t)}function q(e,t){const n=this,s=e<0?this.value.length+e+1:e;n.mutable?n.value.splice(s,0,...t):n.value=S(n.value,s,t),n.subs[0]&&n.subs[0].forEach((e=>{e("insert",s,t)})),E(n)}function B(e,t=1){const n=this,s=e<0?n.value.length+e:e;n.mutable?n.value.splice(s,t):n.value=C(n.value,s,t),n.subs[0]&&n.subs[0].forEach((e=>{e("remove",s,t)})),E(n)}function F(e,t){this.insertList(e,[t])}function G(e){this.insertList(-1,[e])}function H(e){this.insertList(-1,e)}function I(e=1){this.remove(-1*e,e)}function J(){const e=this;0!==e.value.length&&(e.value=[],e.subs[0]&&e.subs[0].forEach((e=>{e("clear")})),E(e))}function K(e,t){const n=this;n.mutable?L(n.value,e,t):n.value=y(n.value,e,t),n.subs[0]&&n.subs[0].forEach((n=>{n("swap",e,t)})),E(n)}function M(e){const t=function(...e){return 0!==e.length?new z(t,e):(N.detectorEnabled&&N.detected.add(t),t.value)};return t.value=e,t.subs=new Array(4),t.context=N.context,t.mutable=!0,t.set=j,t.do=k,Array.isArray(e)&&(t.insert=F,t.insertList=q,t.remove=B,t.swap=K,t.clear=J,t.push=G,t.pushList=H,t.pop=I),t}const N={context:null,detectorEnabled:!1,detected:new Set};export{l as CONNECTION_PHASE,u as LIST_PHASE,i as RENDER_PHASE,a as USER_EFFECT_PHASE,p as batch,r as batching,N as coreInfo,c as detect,x as effect,E as invalidate,w as memo,n as onConnect,s as onDisconnect,M as reactive,g as subscribe,e as targetKey,m as unsubscribe,t as valueAt}; | ||
function t(t,e){if(1===e.length)return[t,e[0]];const n=e.length-1;let s=t;for(let t=0;t<n;t++)s=s[e[t]];return[s,e[n]]}function e(t,e,n=0,s=e.length-1){let o=t;for(let t=n;t<=s;t++)o=o[e[t]];return o}function n(t){O.context.onConnect?O.context.onConnect.push(t):O.context.onConnect=[t]}function s(t){O.context.onDisconnect?O.context.onDisconnect.push(t):O.context.onDisconnect=[t]}function o(t){const e=O.detected,n=O.detectorEnabled;O.detectorEnabled=!0,O.detected=new Set;const s=t(),o=O.detected;return n&&o.forEach((t=>{e.add(t)})),O.detectorEnabled=n,O.detected=e,[o,s]}const c=new Set,l=0,i=1,u=2,a=3,r=4,d={enabled:!1,cloned:new Set},h=[],f=[],v=[];function b(t,e){for(let n=0;n<e;n++){const e=t[n];for(const t of e)t()}t.splice(0,e)}function p(){c.clear();const t=h.length,e=f.length,n=v.length;0!==t&&b(h,t),0!==e&&b(f,e),0!==n&&b(v,n),0!==c.size&&p()}function E(t){d.enabled=!0,t(),d.enabled=!1,d.cloned.clear(),p()}function g(t){if(t.subs[0]&&t.subs[0].forEach((t=>t())),d.enabled&&!c.has(t)?t.subs[1]&&h.push(t.subs[1]):t.subs[1]&&t.subs[1].forEach((t=>t())),t.subs[2]){const e=t.listInvalidator;e&&(t.subs[2].forEach(e),t.listInvalidator=void 0)}d.enabled?c.has(t)||(c.add(t),t.subs[1]&&h.push(t.subs[1]),t.subs[3]&&f.push(t.subs[3]),t.subs[4]&&v.push(t.subs[4])):(t.subs[3]&&t.subs[3].forEach((t=>t())),t.subs[4]&&t.subs[4].forEach((t=>t())))}function m(t,e,n,s=O.context){const o=t.subs[n]||(t.subs[n]=new Set);if(o.add(e),s!==t.context){const t=()=>{o.delete(e)},n=()=>{o.add(e)};s.onDisconnect?s.onDisconnect.push(t):s.onDisconnect=[t],s.onConnect?s.onConnect.push(n):s.onConnect=[n]}}function x(t,e,n){t.subs[n].delete(e)}function w(t,e=4){let n=new Set;const s=O.context;function c(){const l=o(t)[0];n.forEach((t=>{l.has(t)||x(t,c,e)})),l.forEach((t=>{n.has(t)||m(t,c,e,s)})),n=l}function l(){n=o(t)[0],n.forEach((t=>m(t,c,e,s)))}3!==e&&0!==e&&s?s.onConnect?s.onConnect.push(l):s.onConnect=[l]:l()}function L(t){let e,n;return w((()=>{e=t(),n=O.detected}),0),()=>(n&&O.detectorEnabled&&n.forEach((t=>{O.detected.add(t)})),e)}function C(t,e,n){const s=t[e];t[e]=t[n],t[n]=s}function I(t,e,n){if(d.enabled&&d.cloned.has(t))return t.splice(e,n),t;const s=[...t.slice(0,e),...t.slice(e+n)];return d.enabled&&d.cloned.add(s),s}function D(t,e,n){const s=A(t),o=e.length-1;let c=s;for(let t=0;t<o;t++)c[e[t]]=A(c[e[t]]),c=c[e[t]];return c[e[o]]=n,s}function S(t,e,n){if(d.enabled&&d.cloned.has(t))return t.splice(e,0,...n),t;const s=[...t.slice(0,e),...n,...t.slice(e)];return d.enabled&&d.cloned.add(s),s}function y(t,e,n){if(d.enabled&&d.cloned.has(t))return C(t,e,n),t;const s=[...t];return C(s,e,n),d.enabled&&d.cloned.add(s),s}function A(t){if(d.enabled&&d.cloned.has(t))return t;const e=Array.isArray(t)?[...t]:{...t};return d.enabled&&d.cloned.add(e),e}class z{constructor(t,e){this.reactive=t,this.path=e}set(t){const e=this.reactive,n=this.path;if(e.mutable){const s=n.length-1;let o=e.value;for(let t=0;t<s;t++)o=o[n[t]];if(t===o[n[s]])return;o[n[s]]=t}else e.value=D(e.value,n,t);e.subs[2]&&(e.listInvalidator=e=>{e("set",n,t)}),g(e)}do(t){const n=e(this.reactive.value,this.path),s=t(n);n!==s&&this.set(s)}insertList(t,n){const{reactive:s,path:o}=this,c=e(s.value,o),l=t<0?c.length+t+1:t;s.mutable?c.splice(l,0,...n):s.value=D(s.value,o,S(c,l,n)),g(s)}remove(t,n=1){const{reactive:s,path:o}=this,c=e(s.value,o),l=t<0?c.length+t:t;s.mutable?c.splice(l,n):s.value=D(s.value,o,I(c,l,n)),g(s)}insert(t,e){this.insertList(t,[e])}clear(){const e=this.reactive,n=this.path,[s,o]=t(e.value,n),c=s[o];0!==c.length&&(e.mutable?s[o]=[]:e.value=D(c,n,[]),g(e))}swap(t,n){const s=this.reactive,o=this.path,c=e(s.value,o);if(s.mutable)C(c,t,n);else{const c=e(s.value,o);s.value=D(s.value,o,y(c,t,n))}g(s)}push(t){this.insertList(-1,[t])}pushList(t){this.insertList(-1,t)}pop(t=1){this.remove(-1*t,t)}}function j(t){const e=this;t!==e.value&&(e.value=t,e.subs[2]&&(e.listInvalidator=e=>{e("set",null,t)}),g(e))}function k(t){const e=t(this.value);this.value!==e&&this.set(e)}function q(t,e){const n=this,s=t<0?this.value.length+t+1:t;n.mutable?n.value.splice(s,0,...e):n.value=S(n.value,s,e),n.subs[2]&&(n.listInvalidator=t=>{t("insert",s,e)}),g(n)}function B(t,e=1){const n=this,s=t<0?n.value.length+t:t;n.mutable?n.value.splice(s,e):n.value=I(n.value,s,e),n.subs[2]&&(n.listInvalidator=t=>{t("remove",s,e)}),g(n)}function F(t,e){this.insertList(t,[e])}function G(t){this.insertList(-1,[t])}function H(t){this.insertList(-1,t)}function J(t=1){this.remove(-1*t,t)}function K(){const t=this;0!==t.value.length&&(t.value=[],t.listInvalidator=t=>{t("clear")},g(t))}function M(t,e){const n=this;n.mutable?C(n.value,t,e):n.value=y(n.value,t,e),n.subs[2]&&(n.listInvalidator=n=>{n("swap",t,e)}),g(n)}function N(t){const e=function(...t){return 0!==t.length?new z(e,t):(O.detectorEnabled&&O.detected.add(e),e.value)};return e.value=t,e.subs=new Array(5),e.context=O.context,e.mutable=!0,e.set=j,e.do=k,Array.isArray(t)&&(e.insert=F,e.insertList=q,e.remove=B,e.swap=M,e.clear=K,e.push=G,e.pushList=H,e.pop=J),e}const O={context:null,detectorEnabled:!1,detected:new Set};export{i as CONNECTION_PHASE,l as DATA_PHASE,u as LIST_PHASE,a as RENDER_PHASE,r as USER_EFFECT_PHASE,E as batch,d as batching,O as coreInfo,o as detect,w as effect,g as invalidate,L as memo,n as onConnect,s as onDisconnect,N as reactive,m as subscribe,t as targetKey,x as unsubscribe,e as valueAt}; |
@@ -9,3 +9,3 @@ import { GlobalInfo } from './types/others'; | ||
export { reactive } from './reactive/$'; | ||
export { batch, batching, invalidate, CONNECTION_PHASE, LIST_PHASE, RENDER_PHASE, USER_EFFECT_PHASE } from './reactive/scheduler'; | ||
export { batch, batching, invalidate, DATA_PHASE, CONNECTION_PHASE, LIST_PHASE, RENDER_PHASE, USER_EFFECT_PHASE } from './reactive/scheduler'; | ||
export { subscribe, unsubscribe } from './reactive/subscribe'; | ||
@@ -12,0 +12,0 @@ export type { Context, GlobalInfo, Phase, GenericPath, AnyArrayOp } from './types/others'; |
@@ -9,2 +9,2 @@ import { Phase } from '../types/others'; | ||
*/ | ||
export declare function effect(callback: () => void, phase?: Phase, sync?: boolean): void; | ||
export declare function effect(callback: () => void, phase?: Phase): void; |
import { Reactive } from '../types/reactive'; | ||
export declare const LIST_PHASE = 0; | ||
export declare const DATA_PHASE = 0; | ||
export declare const CONNECTION_PHASE = 1; | ||
export declare const RENDER_PHASE = 2; | ||
export declare const USER_EFFECT_PHASE = 3; | ||
export declare const LIST_PHASE = 2; | ||
export declare const RENDER_PHASE = 3; | ||
export declare const USER_EFFECT_PHASE = 4; | ||
/** information about batching */ | ||
@@ -7,0 +8,0 @@ export declare const batching: { |
@@ -15,4 +15,5 @@ import { Reactive } from './reactive'; | ||
}; | ||
export declare type Phase = 0 | 1 | 2 | 3; | ||
export declare type Phase = 0 | 1 | 2 | 3 | 4; | ||
export declare type Subs = [ | ||
dataUpdate?: Set<Function>, | ||
listUpdate?: Set<Function>, | ||
@@ -19,0 +20,0 @@ connection?: Set<Function>, |
@@ -1,2 +0,2 @@ | ||
import { Subs, Context, GenericPath } from './others'; | ||
import { Subs, Context, GenericPath, AnyArrayOp } from './others'; | ||
import { Paths, PathTarget } from './path'; | ||
@@ -28,2 +28,4 @@ export declare namespace Methods { | ||
pop: Methods.Pop; | ||
/** @internal */ | ||
listInvalidator?: (cb: AnyArrayOp) => void; | ||
}; | ||
@@ -30,0 +32,0 @@ declare type Methods<V> = { |
{ | ||
"name": "hydroxide", | ||
"description": "Next Generation Reactive Framework", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"author": "Manan Tank", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
54991
5.48%1379
5.43%