@webreflection/signals 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/branded.js +1 -1
- package/dist/disposable.js +1 -1
- package/dist/signals.js +1 -1
- package/package.json +1 -1
- package/src/effect.js +7 -8
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ You know, nowadays it's hard to find libraries that are still 100% under control
|
|
|
78
78
|
* [signal](https://github.com/WebReflection/signals/blob/main/src/signal.js) is 26 LOC.
|
|
79
79
|
* [computed](https://github.com/WebReflection/signals/blob/main/src/computed.js) is 33 LOC.
|
|
80
80
|
* the shared [stack](https://github.com/WebReflection/signals/blob/main/src/stack.js) is 18 LOC.
|
|
81
|
-
* [effect](https://github.com/WebReflection/signals/blob/main/src/effect.js) is where business happens,
|
|
81
|
+
* [effect](https://github.com/WebReflection/signals/blob/main/src/effect.js) is where business happens, 74 LOC.
|
|
82
82
|
* [disposable](https://github.com/WebReflection/signals/blob/main/src/disposable.js) is 10 LOC, based on the core library mentioned in the previous points.
|
|
83
83
|
* [branded](https://github.com/WebReflection/signals/blob/main/src/branded.js) is 25 LOC extra needed only for libraries building on top.
|
|
84
84
|
|
|
@@ -87,7 +87,7 @@ I mean ... that's coding, isn't it ... today I really needed something that woul
|
|
|
87
87
|
|
|
88
88
|
#### Benchmark
|
|
89
89
|
|
|
90
|
-

|
|
91
91
|
|
|
92
92
|
There is a *huge* difference between *NodeJS* and *Bun* but that's likely because *JSC* handles *Set* or *Map* in a better way, meaning all *WebKit* based browsers and mobile devices will have similar *Preact* performance, while *Chromium* based browsers will have half Preact size, but 1.5X slowdown.
|
|
93
93
|
|
package/dist/branded.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var c=!0,l=t=>{c=t},n,
|
|
1
|
+
var c=!0,l=t=>{c=t},n,i=t=>{c&&n&&t.add(n)},a=(t,e)=>{let r=n;n=t;try{return e()}finally{n=r}};var u=new WeakSet,p=new WeakMap,f,W=t=>{let e=f;e||(f=[]);try{return t()}finally{if(!e){[e,f]=[f,e];for(let[r,o]of e)u.has(r)||o()}}},b=t=>{let e=p.get(t);if(e.length)for(let o of e.splice(0))x(o)},x=t=>{u.add(t),b(t),p.delete(t)},g=t=>{let e=()=>{o||u.has(e)||(o=!0,n||(f?f.push([e,r]):r()))},r=()=>{for(;o;)if(o=!1,b(e),s?.(),s=a(e,t),u.has(e))return},o=!0,s;return n&&p.get(n).push(e),p.set(e,[]),r(),()=>{p.has(e)&&(s?.(),x(e))}};var h=t=>{let e=new Set,r=!0,o,s=()=>{if(r)return;r=!0;let w=e;e=new Set;for(let y of w)y()},d=()=>{for(;r;)r=!1,o=a(s,t);return o};return{get value(){return i(e),d()},peek(){return d()}}};var k=t=>{let e=new Set;return{get value(){return i(e),t},set value(r){if(t=r,c){let o=e;e=new Set;for(let s of o)s()}},peek(){return t}}};var z=t=>{let e=c;l(!1);try{return t()}finally{l(e)}};var H=t=>function(...r){let o,s=g(()=>{o??=t.apply(this,r)??this});return o[Symbol.dispose]=s,o};var m=new WeakSet,N=t=>{let e=h(t);return m.add(e),e},O=t=>m.has(t),P=t=>{let e=k(t);return m.add(e),e};export{W as batch,N as computed,H as disposable,g as effect,O as isSignal,P as signal,z as untracked};
|
package/dist/disposable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var c=!0,
|
|
1
|
+
var c=!0,a=t=>{c=t},n,i=t=>{c&&n&&t.add(n)},p=(t,e)=>{let r=n;n=t;try{return e()}finally{n=r}};var l=new WeakSet,u=new WeakMap,f,y=t=>{let e=f;e||(f=[]);try{return t()}finally{if(!e){[e,f]=[f,e];for(let[r,o]of e)l.has(r)||o()}}},h=t=>{let e=u.get(t);if(e.length)for(let o of e.splice(0))m(o)},m=t=>{l.add(t),h(t),u.delete(t)},d=t=>{let e=()=>{o||l.has(e)||(o=!0,n||(f?f.push([e,r]):r()))},r=()=>{for(;o;)if(o=!1,h(e),s?.(),s=p(e,t),l.has(e))return},o=!0,s;return n&&u.get(n).push(e),u.set(e,[]),r(),()=>{u.has(e)&&(s?.(),m(e))}};var T=t=>{let e=new Set,r=!0,o,s=()=>{if(r)return;r=!0;let x=e;e=new Set;for(let g of x)g()},b=()=>{for(;r;)r=!1,o=p(s,t);return o};return{get value(){return i(e),b()},peek(){return b()}}};var U=t=>{let e=new Set;return{get value(){return i(e),t},set value(r){if(t=r,c){let o=e;e=new Set;for(let s of o)s()}},peek(){return t}}};var z=t=>{let e=c;a(!1);try{return t()}finally{a(e)}};var H=t=>function(...r){let o,s=d(()=>{o??=t.apply(this,r)??this});return o[Symbol.dispose]=s,o};export{y as batch,T as computed,H as disposable,d as effect,U as signal,z as untracked};
|
package/dist/signals.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var c=!0,p=t=>{c=t},s,
|
|
1
|
+
var c=!0,p=t=>{c=t},s,i=t=>{c&&s&&t.add(s)},a=(t,e)=>{let r=s;s=t;try{return e()}finally{s=r}};var l=new WeakSet,u=new WeakMap,f,w=t=>{let e=f;e||(f=[]);try{return t()}finally{if(!e){[e,f]=[f,e];for(let[r,o]of e)l.has(r)||o()}}},h=t=>{let e=u.get(t);if(e.length)for(let o of e.splice(0))g(o)},g=t=>{l.add(t),h(t),u.delete(t)},v=t=>{let e=()=>{o||l.has(e)||(o=!0,s||(f?f.push([e,r]):r()))},r=()=>{for(;o;)if(o=!1,h(e),n?.(),n=a(e,t),l.has(e))return},o=!0,n;return s&&u.get(s).push(e),u.set(e,[]),r(),()=>{u.has(e)&&(n?.(),g(e))}};var T=t=>{let e=new Set,r=!0,o,n=()=>{if(r)return;r=!0;let x=e;e=new Set;for(let d of x)d()},b=()=>{for(;r;)r=!1,o=a(n,t);return o};return{get value(){return i(e),b()},peek(){return b()}}};var U=t=>{let e=new Set;return{get value(){return i(e),t},set value(r){if(t=r,c){let o=e;e=new Set;for(let n of o)n()}},peek(){return t}}};var z=t=>{let e=c;p(!1);try{return t()}finally{p(e)}};export{w as batch,T as computed,v as effect,U as signal,z as untracked};
|
package/package.json
CHANGED
package/src/effect.js
CHANGED
|
@@ -2,19 +2,18 @@ import { run, stack } from './stack.js';
|
|
|
2
2
|
|
|
3
3
|
const disposed = new WeakSet;
|
|
4
4
|
const effects = new WeakMap;
|
|
5
|
-
const batches = [];
|
|
6
5
|
|
|
7
|
-
let
|
|
6
|
+
let batches;
|
|
8
7
|
|
|
9
8
|
/** @type {<T>(fn: () => T) => T} */
|
|
10
9
|
export const batch = fn => {
|
|
11
|
-
|
|
12
|
-
if (
|
|
10
|
+
let updates = batches;
|
|
11
|
+
if (!updates) batches = [];
|
|
13
12
|
try { return fn() }
|
|
14
13
|
finally {
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
for (const [subscriber, run] of
|
|
14
|
+
if (!updates) {
|
|
15
|
+
[updates, batches] = [batches, updates];
|
|
16
|
+
for (const [subscriber, run] of updates) {
|
|
18
17
|
if (!disposed.has(subscriber)) run();
|
|
19
18
|
}
|
|
20
19
|
}
|
|
@@ -43,7 +42,7 @@ export const effect = fn => {
|
|
|
43
42
|
if (invalid || disposed.has(subscriber)) return;
|
|
44
43
|
invalid = true;
|
|
45
44
|
if (!stack) {
|
|
46
|
-
if (
|
|
45
|
+
if (batches) batches.push([subscriber, loop]);
|
|
47
46
|
else loop();
|
|
48
47
|
}
|
|
49
48
|
};
|