@webreflection/signals 0.1.1 → 0.1.2

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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [![Coverage Status](https://coveralls.io/repos/github/WebReflection/signals/badge.svg?branch=main)](https://coveralls.io/github/WebReflection/signals?branch=main)
6
6
 
7
- A minimalistic [Preact-like signals](https://preactjs.com/guide/v10/signals/) (*minus options*) implementation.
7
+ A minimalistic [Preact-like signals](https://github.com/preactjs/signals/blob/main/packages/core/README.md) implementation.
8
8
 
9
9
  Once minified and compressed, this module is actually [0.5KB](https://cdn.jsdelivr.net/npm/@webreflection/signals/dist/signals.js).
10
10
 
@@ -13,9 +13,9 @@ Once minified and compressed, this module is actually [0.5KB](https://cdn.jsdeli
13
13
  // basic core features
14
14
  import {
15
15
  batch, // Preact-like API
16
- computed, // Preact-like API w/out options
17
- effect, // Preact-like API w/out options
18
- signal, // Preact-like API w/out options
16
+ computed, // Preact-like API
17
+ effect, // Preact-like API
18
+ signal, // Preact-like API
19
19
  untracked, // Preact-like API
20
20
  } from '@webreflection/signals';
21
21
  ```
@@ -72,6 +72,7 @@ import {
72
72
 
73
73
  You know, nowadays it's hard to find libraries that are still 100% under control, minimalistic, not bloated, yet correct, and this one would like to be one of those 😇
74
74
 
75
+
75
76
  #### The Beauty
76
77
 
77
78
  * [signal](https://github.com/WebReflection/signals/blob/main/src/signal.js) is 26 LOC.
@@ -82,3 +83,12 @@ You know, nowadays it's hard to find libraries that are still 100% under control
82
83
  * [branded](https://github.com/WebReflection/signals/blob/main/src/branded.js) is 21 LOC extra needed only for libraries building on top.
83
84
 
84
85
  I mean ... that's coding, isn't it ... today I really needed something that would remind me why I love what I do ❤️
86
+
87
+
88
+ #### Benchmark
89
+
90
+ ![benchmark](/WebReflection/usignal/raw/main/test/benchmark.png)
91
+
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
+
94
+ However, in common scenarios with no more than 10 to 100 signals per *effect*, the performance are consistently better or really close to Preact.
package/dist/branded.js CHANGED
@@ -1 +1 @@
1
- var l=!0,d=t=>{l=t},i=()=>l,n=null,f=t=>{l&&n&&t.add(n)},a=(t,e)=>{let r=n;n=t;try{return e()}finally{n=r}};var u=new WeakSet,c=new WeakMap,g=[],p=!1,M=t=>{let e=!p;e&&(p=!0);try{return t()}finally{if(e){p=!1;for(let[r,o]of g.splice(0))u.has(r)||o()}}},h=t=>{let e=c.get(t);if(e.length)for(let o of e.splice(0))x(o)},x=t=>{u.add(t),h(t),c.delete(t)},k=t=>{let e=()=>{o||u.has(e)||(o=!0,n||(p?g.push([e,r]):r()))},r=()=>{for(;o;)if(o=!1,h(e),s?.(),s=a(e,t),u.has(e))return},o=!0,s;return n&&c.get(n).push(e),c.set(e,[]),r(),()=>{c.has(e)&&(s?.(),x(e))}};var w=t=>{let e=new Set,r=!0,o,s=()=>{if(r)return;r=!0;let S=e;e=new Set;for(let v of S)v()},b=()=>{for(;r;)r=!1,o=a(s,t);return o};return{get value(){return f(e),b()},peek(){return b()}}};var y=t=>{let e=new Set;return{get value(){return f(e),t},set value(r){if(t=r,i()){let o=e;e=new Set;for(let s of o)s()}},peek(){return t}}};var B=t=>{let e=i();d(!1);try{return t()}finally{d(e)}};var{defineProperty:T}=Object,{dispose:W}=Symbol,J=t=>function(...r){let o,s=k(()=>{o??=t.apply(this,r)??this});return T(o,W,{value:s})};var m=new WeakSet,R=t=>{let e=w(t);return m.add(e),e},V=t=>m.has(t),X=t=>{let e=y(t);return m.add(e),e};export{M as batch,R as computed,J as disposable,k as effect,V as isSignal,X as signal,B as untracked};
1
+ var l=!0,m=t=>{l=t},f=()=>l,n=null,i=t=>{l&&n&&t.add(n)},a=(t,e)=>{let r=n;n=t;try{return e()}finally{n=r}};var u=new WeakSet,c=new WeakMap,x=[],p=!1,M=t=>{let e=!p;e&&(p=!0);try{return t()}finally{if(e){p=!1;for(let[r,o]of x.splice(0))u.has(r)||o()}}},g=t=>{let e=c.get(t);if(e.length)for(let o of e.splice(0))h(o)},h=t=>{u.add(t),g(t),c.delete(t)},k=t=>{let e=()=>{o||u.has(e)||(o=!0,n||(p?x.push([e,r]):r()))},r=()=>{for(;o;)if(o=!1,g(e),s?.(),s=a(e,t),u.has(e))return},o=!0,s;return n&&c.get(n).push(e),c.set(e,[]),r(),()=>{c.has(e)&&(s?.(),h(e))}};var w=t=>{let e=new Set,r=!0,o,s=()=>{if(r)return;r=!0;let S=e;e=new Set;for(let v of S)v()},b=()=>{for(;r;)r=!1,o=a(s,t);return o};return{get value(){return i(e),b()},peek(){return b()}}};var y=t=>{let e=new Set;return{get value(){return i(e),t},set value(r){if(t=r,f()){let o=e;e=new Set;for(let s of o)s()}},peek(){return t}}};var B=t=>{let e=f();m(!1);try{return t()}finally{m(e)}};var{defineProperty:T}=Object,{dispose:W}=Symbol,J=t=>function(...r){let o,s=k(()=>{o??=t.apply(this,r)??this});return T(o,W,{value:s})};var d=new WeakSet,R=t=>{let e=w(t);return d.add(e),e},V=t=>d.has(t),X=t=>{let e=y(t);return d.add(e),e};export{M as batch,R as computed,J as disposable,k as effect,V as isSignal,X as signal,B as untracked};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webreflection/signals",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "A minimalistic Preact-like signals implementation",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
package/src/branded.js CHANGED
@@ -1,5 +1,6 @@
1
- export * from './effect.js';
2
1
  export * from './disposable.js';
2
+ export * from './effect.js';
3
+ export * from './untracked.js';
3
4
 
4
5
  import { computed as $computed } from './computed.js';
5
6
  import { signal as $signal } from './signal.js';
@@ -1,5 +1,6 @@
1
- export * from "./effect.js";
2
1
  export * from "./disposable.js";
2
+ export * from "./effect.js";
3
+ export * from "./untracked.js";
3
4
  export function computed(callback: any): {
4
5
  readonly value: any;
5
6
  peek: () => any;