balises 0.2.1 → 0.3.0
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 +108 -3
- package/dist/balises.esm.js +45 -2
- package/dist/balises.esm.js.map +1 -1
- package/dist/balises.iife.js +45 -1
- package/dist/balises.iife.js.map +1 -1
- package/dist/balises.iife.min.js +2 -2
- package/dist/balises.iife.min.js.map +1 -1
- package/dist/esm/signals/computed.d.ts.map +1 -1
- package/dist/esm/signals/computed.js +3 -1
- package/dist/esm/signals/computed.js.map +1 -1
- package/dist/esm/signals/context.d.ts +23 -0
- package/dist/esm/signals/context.d.ts.map +1 -1
- package/dist/esm/signals/context.js +53 -0
- package/dist/esm/signals/context.js.map +1 -1
- package/dist/esm/signals/effect.d.ts.map +1 -1
- package/dist/esm/signals/effect.js +8 -1
- package/dist/esm/signals/effect.js.map +1 -1
- package/dist/esm/signals/index.d.ts +1 -1
- package/dist/esm/signals/index.d.ts.map +1 -1
- package/dist/esm/signals/index.js +1 -1
- package/dist/esm/signals/index.js.map +1 -1
- package/package.json +16 -5
|
@@ -44,4 +44,57 @@ export function enqueueBatchAll(subs) {
|
|
|
44
44
|
batchQueue.add(subs[i]);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
/** Scope disposal: collect all disposers in a scope */
|
|
48
|
+
let disposalStack = null;
|
|
49
|
+
/**
|
|
50
|
+
* Create a disposal scope that collects all subscriptions and computeds created within.
|
|
51
|
+
* Returns the result of the function and a dispose function that cleans up all resources.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const [result, dispose] = scope(() => {
|
|
56
|
+
* const count = signal(0);
|
|
57
|
+
* const doubled = computed(() => count.value * 2);
|
|
58
|
+
* effect(() => console.log(doubled.value));
|
|
59
|
+
* return { count, doubled };
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Later: clean up all subscriptions and computeds
|
|
63
|
+
* dispose();
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function scope(fn) {
|
|
67
|
+
const disposers = [];
|
|
68
|
+
// Push new disposal context
|
|
69
|
+
if (!disposalStack)
|
|
70
|
+
disposalStack = [];
|
|
71
|
+
disposalStack.push(disposers);
|
|
72
|
+
try {
|
|
73
|
+
const result = fn();
|
|
74
|
+
return [
|
|
75
|
+
result,
|
|
76
|
+
() => {
|
|
77
|
+
for (let i = disposers.length - 1; i >= 0; i--) {
|
|
78
|
+
disposers[i]();
|
|
79
|
+
}
|
|
80
|
+
disposers.length = 0;
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
// Pop disposal context
|
|
86
|
+
disposalStack.pop();
|
|
87
|
+
if (disposalStack.length === 0)
|
|
88
|
+
disposalStack = null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Register a disposer in the current scope (if any).
|
|
93
|
+
* This is called internally by computed/effect when they create cleanup functions.
|
|
94
|
+
*/
|
|
95
|
+
export function registerDisposer(dispose) {
|
|
96
|
+
if (disposalStack && disposalStack.length > 0) {
|
|
97
|
+
disposalStack[disposalStack.length - 1].push(dispose);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
47
100
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/signals/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,iEAAiE;AACjE,MAAM,CAAC,IAAI,OAAO,GAA6B,IAAI,CAAC;AAEpD,wCAAwC;AACxC,MAAM,UAAU,UAAU,CAAC,CAA2B;IACpD,OAAO,GAAG,CAAC,CAAC;AACd,CAAC;AAED,qEAAqE;AACrE,IAAI,UAAU,GAAG,CAAC,CAAC;AACnB,IAAI,UAAU,GAA2B,IAAI,CAAC;AAE9C;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAI,EAAW;IAClC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AAC,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC/C,SAAS,CAAC,CAAC,CAAE,EAAE,CAAC;gBAClB,CAAC;gBACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;YACvB,CAAC;SACF,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,uBAAuB;QACvB,aAAa,CAAC,GAAG,EAAE,CAAC;QACpB,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;YAAE,aAAa,GAAG,IAAI,CAAC;IACvD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAmB;IAClD,IAAI,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9C,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../../src/signals/effect.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../../src/signals/effect.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAqBjD"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Effect - Run side effects reactively.
|
|
3
3
|
*/
|
|
4
4
|
import { computed } from "./computed.js";
|
|
5
|
+
import { registerDisposer } from "./context.js";
|
|
5
6
|
/**
|
|
6
7
|
* Create a reactive effect that automatically tracks dependencies
|
|
7
8
|
* and re-runs when they change.
|
|
@@ -25,9 +26,15 @@ export function effect(fn) {
|
|
|
25
26
|
});
|
|
26
27
|
// Subscribe to make it reactive (rerun on dependency changes)
|
|
27
28
|
const unsub = c.subscribe(() => { });
|
|
28
|
-
|
|
29
|
+
const dispose = () => {
|
|
29
30
|
unsub();
|
|
30
31
|
c.dispose();
|
|
31
32
|
};
|
|
33
|
+
// Auto-register disposal in current root scope
|
|
34
|
+
// Note: This doesn't prevent returning the dispose function since the
|
|
35
|
+
// user might want to dispose early, while the root dispose cleans up any
|
|
36
|
+
// effects that weren't manually disposed.
|
|
37
|
+
registerDisposer(dispose);
|
|
38
|
+
return dispose;
|
|
32
39
|
}
|
|
33
40
|
//# sourceMappingURL=effect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect.js","sourceRoot":"","sources":["../../../src/signals/effect.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"effect.js","sourceRoot":"","sources":["../../../src/signals/effect.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,MAAM,CAAC,EAAc;IACnC,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE;QACtB,EAAE,EAAE,CAAC;QACL,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,8DAA8D;IAC9D,MAAM,KAAK,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAEpC,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,KAAK,EAAE,CAAC;QACR,CAAC,CAAC,OAAO,EAAE,CAAC;IACd,CAAC,CAAC;IAEF,+CAA+C;IAC/C,sEAAsE;IACtE,yEAAyE;IACzE,0CAA0C;IAC1C,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE1B,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -9,7 +9,7 @@ export { Signal, signal } from "./signal.js";
|
|
|
9
9
|
export { Computed, computed } from "./computed.js";
|
|
10
10
|
export { effect } from "./effect.js";
|
|
11
11
|
export { store } from "./store.js";
|
|
12
|
-
export { batch, type Subscriber } from "./context.js";
|
|
12
|
+
export { batch, scope, type Subscriber } from "./context.js";
|
|
13
13
|
/** Common interface for reactive values (Signal or Computed). */
|
|
14
14
|
export interface Reactive<T> {
|
|
15
15
|
readonly value: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signals/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signals/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAK7D,iEAAiE;AACjE,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CACvC;AAED,yDAAyD;AACzD,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,QAAQ,CAAC,OAAO,CACb,CAAC"}
|
|
@@ -9,7 +9,7 @@ export { Signal, signal } from "./signal.js";
|
|
|
9
9
|
export { Computed, computed } from "./computed.js";
|
|
10
10
|
export { effect } from "./effect.js";
|
|
11
11
|
export { store } from "./store.js";
|
|
12
|
-
export { batch } from "./context.js";
|
|
12
|
+
export { batch, scope } from "./context.js";
|
|
13
13
|
import { Signal } from "./signal.js";
|
|
14
14
|
import { Computed } from "./computed.js";
|
|
15
15
|
/** Check if a value is a reactive signal or computed. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/signals/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAmB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/signals/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAmB,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQzC,yDAAyD;AACzD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA8B,EAAE,CACrE,KAAK,YAAY,MAAM,IAAI,KAAK,YAAY,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "balises",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A very simple reactive html templating library",
|
|
5
5
|
"author": "Julien Elbaz <elbywan@hotmail.com>",
|
|
6
6
|
"type": "module",
|
|
@@ -56,13 +56,24 @@
|
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "rm -rf dist && tsc && rolldown -c",
|
|
59
|
-
"test": "node --
|
|
59
|
+
"test": "node --import tsx/esm --import ./tests/setup.ts --test tests/*.test.ts",
|
|
60
|
+
"typecheck": "tsc --project tsconfig.typecheck.json",
|
|
60
61
|
"lint": "eslint .",
|
|
62
|
+
"lint:fix": "eslint . --fix",
|
|
63
|
+
"format": "prettier --write .",
|
|
64
|
+
"check": "yarn format && yarn lint:fix && yarn typecheck",
|
|
61
65
|
"pretty": "prettier --write .",
|
|
62
66
|
"examples": "rolldown -c examples/rolldown.config.ts && yarn dlx serve examples",
|
|
63
67
|
"examples:build": "rolldown -c examples/rolldown.config.ts && cp docs/base.css examples/ && cp docs/example.css examples/",
|
|
64
|
-
"bench": "cd bench && yarn && yarn start",
|
|
65
|
-
"bench:
|
|
68
|
+
"bench": "cd bench && yarn && yarn start --isolate",
|
|
69
|
+
"bench:update-readme": "cd bench && yarn && node update-readme.mjs",
|
|
70
|
+
"bench:self": "cd bench && yarn && yarn start:self --isolate",
|
|
71
|
+
"bench:layers": "cd bench && yarn && yarn start:layers --isolate",
|
|
72
|
+
"bench:wide": "cd bench && yarn && yarn start:wide --isolate",
|
|
73
|
+
"bench:diamond": "cd bench && yarn && yarn start:diamond --isolate",
|
|
74
|
+
"bench:create": "cd bench && yarn && yarn start:create --isolate",
|
|
75
|
+
"bench:conditional": "cd bench && yarn && yarn start:conditional --isolate",
|
|
76
|
+
"bench:list": "cd bench && yarn && yarn start:list --isolate",
|
|
66
77
|
"docs": "yarn docs:build && yarn dlx serve _site",
|
|
67
78
|
"docs:build": "yarn build && yarn examples:build && rm -rf _site && mkdir -p _site/assets && cp docs/index.html _site/ && cp docs/*.css _site/ && cp docs/quickstart-demo.js _site/ && cp docs/counter-demo.js _site/ && cp assets/logo.svg _site/assets/ && cp assets/logo-icon.svg _site/assets/ && cp -r examples _site/examples && cp dist/balises.esm.js _site/examples/"
|
|
68
79
|
},
|
|
@@ -79,6 +90,6 @@
|
|
|
79
90
|
"typescript-eslint": "8.50.1"
|
|
80
91
|
},
|
|
81
92
|
"dependencies": {
|
|
82
|
-
"balises": "
|
|
93
|
+
"balises": "0.3.0"
|
|
83
94
|
}
|
|
84
95
|
}
|