@opentf/web 0.4.0 → 0.5.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/components/Link.jsx +29 -0
- package/core/errors.js +48 -0
- package/core/signals.js +188 -0
- package/index.js +12 -0
- package/package.json +27 -18
- package/runtime/context.js +89 -0
- package/runtime/dom.js +280 -0
- package/runtime/error-boundary.js +109 -0
- package/runtime/events.js +17 -0
- package/runtime/index.js +16 -0
- package/runtime/lifecycle.js +9 -0
- package/runtime/mount.js +49 -0
- package/runtime/portal.js +59 -0
- package/runtime/router.js +246 -0
- package/server/builtins.js +11 -0
- package/server/index.js +7 -0
- package/server/render.js +76 -0
- package/server/ssg-runtime.js +109 -0
- package/README.md +0 -41
- package/dist/CHANGELOG.md +0 -49
- package/dist/README.md +0 -41
- package/dist/babel.config.cjs +0 -6
- package/dist/compiler/babel-plugin.cjs +0 -798
- package/dist/core/mount.js +0 -32
- package/dist/index.js +0 -7
- package/dist/node_modules/@babel/core/LICENSE +0 -22
- package/dist/node_modules/@babel/core/README.md +0 -19
- package/dist/node_modules/@babel/core/lib/config/cache-contexts.js +0 -5
- package/dist/node_modules/@babel/core/lib/config/cache-contexts.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/caching.js +0 -261
- package/dist/node_modules/@babel/core/lib/config/caching.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/config-chain.js +0 -469
- package/dist/node_modules/@babel/core/lib/config/config-chain.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/config-descriptors.js +0 -190
- package/dist/node_modules/@babel/core/lib/config/config-descriptors.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/files/configuration.js +0 -290
- package/dist/node_modules/@babel/core/lib/config/files/configuration.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/files/import.cjs +0 -6
- package/dist/node_modules/@babel/core/lib/config/files/import.cjs.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/files/index-browser.js +0 -58
- package/dist/node_modules/@babel/core/lib/config/files/index-browser.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/files/index.js +0 -78
- package/dist/node_modules/@babel/core/lib/config/files/index.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/files/module-types.js +0 -203
- package/dist/node_modules/@babel/core/lib/config/files/module-types.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/files/package.js +0 -61
- package/dist/node_modules/@babel/core/lib/config/files/package.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/files/plugins.js +0 -220
- package/dist/node_modules/@babel/core/lib/config/files/plugins.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/files/types.js +0 -5
- package/dist/node_modules/@babel/core/lib/config/files/types.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/files/utils.js +0 -36
- package/dist/node_modules/@babel/core/lib/config/files/utils.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/full.js +0 -312
- package/dist/node_modules/@babel/core/lib/config/full.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/helpers/config-api.js +0 -85
- package/dist/node_modules/@babel/core/lib/config/helpers/config-api.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/helpers/deep-array.js +0 -23
- package/dist/node_modules/@babel/core/lib/config/helpers/deep-array.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/helpers/environment.js +0 -12
- package/dist/node_modules/@babel/core/lib/config/helpers/environment.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/index.js +0 -87
- package/dist/node_modules/@babel/core/lib/config/index.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/item.js +0 -67
- package/dist/node_modules/@babel/core/lib/config/item.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/partial.js +0 -158
- package/dist/node_modules/@babel/core/lib/config/partial.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/pattern-to-regex.js +0 -38
- package/dist/node_modules/@babel/core/lib/config/pattern-to-regex.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/plugin.js +0 -33
- package/dist/node_modules/@babel/core/lib/config/plugin.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/printer.js +0 -113
- package/dist/node_modules/@babel/core/lib/config/printer.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/resolve-targets-browser.js +0 -41
- package/dist/node_modules/@babel/core/lib/config/resolve-targets-browser.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/resolve-targets.js +0 -61
- package/dist/node_modules/@babel/core/lib/config/resolve-targets.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/util.js +0 -31
- package/dist/node_modules/@babel/core/lib/config/util.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/validation/option-assertions.js +0 -277
- package/dist/node_modules/@babel/core/lib/config/validation/option-assertions.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/validation/options.js +0 -187
- package/dist/node_modules/@babel/core/lib/config/validation/options.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/validation/plugins.js +0 -67
- package/dist/node_modules/@babel/core/lib/config/validation/plugins.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/config/validation/removed.js +0 -68
- package/dist/node_modules/@babel/core/lib/config/validation/removed.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/errors/config-error.js +0 -18
- package/dist/node_modules/@babel/core/lib/errors/config-error.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js +0 -98
- package/dist/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/gensync-utils/async.js +0 -90
- package/dist/node_modules/@babel/core/lib/gensync-utils/async.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/gensync-utils/fs.js +0 -31
- package/dist/node_modules/@babel/core/lib/gensync-utils/fs.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/gensync-utils/functional.js +0 -58
- package/dist/node_modules/@babel/core/lib/gensync-utils/functional.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/index.js +0 -230
- package/dist/node_modules/@babel/core/lib/index.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/parse.js +0 -45
- package/dist/node_modules/@babel/core/lib/parse.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/parser/index.js +0 -85
- package/dist/node_modules/@babel/core/lib/parser/index.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/parser/util/missing-plugin-helper.js +0 -337
- package/dist/node_modules/@babel/core/lib/parser/util/missing-plugin-helper.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/tools/build-external-helpers.js +0 -144
- package/dist/node_modules/@babel/core/lib/tools/build-external-helpers.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transform-ast.js +0 -48
- package/dist/node_modules/@babel/core/lib/transform-ast.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transform-file-browser.js +0 -23
- package/dist/node_modules/@babel/core/lib/transform-file-browser.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transform-file.js +0 -40
- package/dist/node_modules/@babel/core/lib/transform-file.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transform.js +0 -47
- package/dist/node_modules/@babel/core/lib/transform.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js +0 -84
- package/dist/node_modules/@babel/core/lib/transformation/block-hoist-plugin.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transformation/file/babel-7-helpers.cjs +0 -4
- package/dist/node_modules/@babel/core/lib/transformation/file/babel-7-helpers.cjs.map +0 -1
- package/dist/node_modules/@babel/core/lib/transformation/file/file.js +0 -204
- package/dist/node_modules/@babel/core/lib/transformation/file/file.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transformation/file/generate.js +0 -84
- package/dist/node_modules/@babel/core/lib/transformation/file/generate.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transformation/file/merge-map.js +0 -37
- package/dist/node_modules/@babel/core/lib/transformation/file/merge-map.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transformation/index.js +0 -90
- package/dist/node_modules/@babel/core/lib/transformation/index.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transformation/normalize-file.js +0 -127
- package/dist/node_modules/@babel/core/lib/transformation/normalize-file.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transformation/normalize-opts.js +0 -59
- package/dist/node_modules/@babel/core/lib/transformation/normalize-opts.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transformation/plugin-pass.js +0 -48
- package/dist/node_modules/@babel/core/lib/transformation/plugin-pass.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/transformation/util/clone-deep.js +0 -54
- package/dist/node_modules/@babel/core/lib/transformation/util/clone-deep.js.map +0 -1
- package/dist/node_modules/@babel/core/lib/vendor/import-meta-resolve.js +0 -1042
- package/dist/node_modules/@babel/core/lib/vendor/import-meta-resolve.js.map +0 -1
- package/dist/node_modules/@babel/core/package.json +0 -82
- package/dist/node_modules/@babel/core/src/config/files/index-browser.ts +0 -115
- package/dist/node_modules/@babel/core/src/config/files/index.ts +0 -30
- package/dist/node_modules/@babel/core/src/config/resolve-targets-browser.ts +0 -42
- package/dist/node_modules/@babel/core/src/config/resolve-targets.ts +0 -54
- package/dist/node_modules/@babel/core/src/transform-file-browser.ts +0 -33
- package/dist/node_modules/@babel/core/src/transform-file.ts +0 -56
- package/dist/node_modules/@babel/helper-module-imports/LICENSE +0 -22
- package/dist/node_modules/@babel/helper-module-imports/README.md +0 -19
- package/dist/node_modules/@babel/helper-module-imports/lib/import-builder.js +0 -122
- package/dist/node_modules/@babel/helper-module-imports/lib/import-builder.js.map +0 -1
- package/dist/node_modules/@babel/helper-module-imports/lib/import-injector.js +0 -304
- package/dist/node_modules/@babel/helper-module-imports/lib/import-injector.js.map +0 -1
- package/dist/node_modules/@babel/helper-module-imports/lib/index.js +0 -37
- package/dist/node_modules/@babel/helper-module-imports/lib/index.js.map +0 -1
- package/dist/node_modules/@babel/helper-module-imports/lib/is-module.js +0 -11
- package/dist/node_modules/@babel/helper-module-imports/lib/is-module.js.map +0 -1
- package/dist/node_modules/@babel/helper-module-imports/package.json +0 -28
- package/dist/node_modules/@babel/plugin-syntax-jsx/LICENSE +0 -22
- package/dist/node_modules/@babel/plugin-syntax-jsx/README.md +0 -19
- package/dist/node_modules/@babel/plugin-syntax-jsx/lib/index.js +0 -21
- package/dist/node_modules/@babel/plugin-syntax-jsx/lib/index.js.map +0 -1
- package/dist/node_modules/@babel/plugin-syntax-jsx/package.json +0 -33
- package/dist/node_modules/@preact/signals-core/CHANGELOG.md +0 -331
- package/dist/node_modules/@preact/signals-core/LICENSE +0 -21
- package/dist/node_modules/@preact/signals-core/README.md +0 -258
- package/dist/node_modules/@preact/signals-core/dist/signals-core.d.ts +0 -149
- package/dist/node_modules/@preact/signals-core/dist/signals-core.js +0 -1
- package/dist/node_modules/@preact/signals-core/dist/signals-core.js.map +0 -1
- package/dist/node_modules/@preact/signals-core/dist/signals-core.min.js +0 -1
- package/dist/node_modules/@preact/signals-core/dist/signals-core.min.js.map +0 -1
- package/dist/node_modules/@preact/signals-core/dist/signals-core.mjs +0 -1
- package/dist/node_modules/@preact/signals-core/dist/signals-core.mjs.map +0 -1
- package/dist/node_modules/@preact/signals-core/dist/signals-core.module.js +0 -1
- package/dist/node_modules/@preact/signals-core/dist/signals-core.module.js.map +0 -1
- package/dist/node_modules/@preact/signals-core/package.json +0 -48
- package/dist/node_modules/@preact/signals-core/src/index.ts +0 -1121
- package/dist/package.json +0 -30
- package/dist/router/Link.js +0 -73
- package/dist/router/index.js +0 -216
- package/dist/runtime/For.js +0 -16
- package/dist/runtime/dom.js +0 -73
- package/dist/runtime/lifecycle.js +0 -25
- package/dist/runtime/props.js +0 -103
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
# Signals
|
|
2
|
-
|
|
3
|
-
Signals is a performant state management library with two primary goals:
|
|
4
|
-
|
|
5
|
-
1. Make it as easy as possible to write business logic for small up to complex apps. No matter how complex your logic is, your app updates should stay fast without you needing to think about it. Signals automatically optimize state updates behind the scenes to trigger the fewest updates necessary. They are lazy by default and automatically skip signals that no one listens to.
|
|
6
|
-
2. Integrate into frameworks as if they were native built-in primitives. You don't need any selectors, wrapper functions, or anything else. Signals can be accessed directly and your component will automatically re-render when the signal's value changes.
|
|
7
|
-
|
|
8
|
-
Read the [announcement post](https://preactjs.com/blog/introducing-signals/) to learn more about which problems signals solves and how it came to be.
|
|
9
|
-
|
|
10
|
-
- [Installation](#installation)
|
|
11
|
-
- [Guide / API](#guide--api)
|
|
12
|
-
- [`signal(initialValue)`](#signalinitialvalue)
|
|
13
|
-
- [`signal.peek()`](#signalpeek)
|
|
14
|
-
- [`computed(fn)`](#computedfn)
|
|
15
|
-
- [`effect(fn)`](#effectfn)
|
|
16
|
-
- [`batch(fn)`](#batchfn)
|
|
17
|
-
- [`untracked(fn)`](#untrackedfn)
|
|
18
|
-
- [License](#license)
|
|
19
|
-
|
|
20
|
-
## Installation:
|
|
21
|
-
|
|
22
|
-
```sh
|
|
23
|
-
npm install @preact/signals-core
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Guide / API
|
|
27
|
-
|
|
28
|
-
The signals library exposes five functions which are the building blocks to model any business logic you can think of.
|
|
29
|
-
|
|
30
|
-
### `signal(initialValue)`
|
|
31
|
-
|
|
32
|
-
The `signal` function creates a new signal. A signal is a container for a value that can change over time. You can read a signal's value or subscribe to value updates by accessing its `.value` property.
|
|
33
|
-
|
|
34
|
-
```js
|
|
35
|
-
import { signal } from "@preact/signals-core";
|
|
36
|
-
|
|
37
|
-
const counter = signal(0);
|
|
38
|
-
|
|
39
|
-
// Read value from signal, logs: 0
|
|
40
|
-
console.log(counter.value);
|
|
41
|
-
|
|
42
|
-
// Write to a signal
|
|
43
|
-
counter.value = 1;
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Writing to a signal is done by setting its `.value` property. Changing a signal's value synchronously updates every [computed](#computedfn) and [effect](#effectfn) that depends on that signal, ensuring your app state is always consistent.
|
|
47
|
-
|
|
48
|
-
You can also pass options to `signal()` and `computed()` to be notified when the signal gains its first subscriber and loses its last subscriber:
|
|
49
|
-
|
|
50
|
-
```js
|
|
51
|
-
const counter = signal(0, {
|
|
52
|
-
name: "counter",
|
|
53
|
-
watched: function () {
|
|
54
|
-
console.log("Signal has its first subscriber");
|
|
55
|
-
},
|
|
56
|
-
unwatched: function () {
|
|
57
|
-
console.log("Signal lost its last subscriber");
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
These callbacks are useful for managing resources or side effects that should only be active when the signal has subscribers. For example, you might use them to start/stop expensive background operations or subscribe/unsubscribe from external event sources.
|
|
63
|
-
|
|
64
|
-
The `name` option will be used in the `@preact/signals-debug` package to provide meaningful names for the log output.
|
|
65
|
-
|
|
66
|
-
#### `signal.peek()`
|
|
67
|
-
|
|
68
|
-
In the rare instance that you have an effect that should write to another signal based on the previous value, but you _don't_ want the effect to be subscribed to that signal, you can read a signals's previous value via `signal.peek()`.
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
const counter = signal(0);
|
|
72
|
-
const effectCount = signal(0);
|
|
73
|
-
|
|
74
|
-
effect(() => {
|
|
75
|
-
console.log(counter.value);
|
|
76
|
-
|
|
77
|
-
// Whenever this effect is triggered, increase `effectCount`.
|
|
78
|
-
// But we don't want this signal to react to `effectCount`
|
|
79
|
-
effectCount.value = effectCount.peek() + 1;
|
|
80
|
-
});
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
Note that you should only use `signal.peek()` if you really need it. Reading a signal's value via `signal.value` is the preferred way in most scenarios.
|
|
84
|
-
|
|
85
|
-
### `computed(fn)`
|
|
86
|
-
|
|
87
|
-
Data is often derived from other pieces of existing data. The `computed` function lets you combine the values of multiple signals into a new signal that can be reacted to, or even used by additional computeds. When the signals accessed from within a computed callback change, the computed callback is re-executed and its new return value becomes the computed signal's value.
|
|
88
|
-
|
|
89
|
-
```js
|
|
90
|
-
import { signal, computed } from "@preact/signals-core";
|
|
91
|
-
|
|
92
|
-
const name = signal("Jane");
|
|
93
|
-
const surname = signal("Doe");
|
|
94
|
-
|
|
95
|
-
const fullName = computed(() => name.value + " " + surname.value);
|
|
96
|
-
|
|
97
|
-
// Logs: "Jane Doe"
|
|
98
|
-
console.log(fullName.value);
|
|
99
|
-
|
|
100
|
-
// Updates flow through computed, but only if someone
|
|
101
|
-
// subscribes to it. More on that later.
|
|
102
|
-
name.value = "John";
|
|
103
|
-
// Logs: "John Doe"
|
|
104
|
-
console.log(fullName.value);
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Any signal that is accessed inside the `computed`'s callback function will be automatically subscribed to and tracked as a dependency of the computed signal.
|
|
108
|
-
|
|
109
|
-
### `effect(fn)`
|
|
110
|
-
|
|
111
|
-
The `effect` function is the last piece that makes everything reactive. When you access a signal inside its callback function, that signal and every dependency of said signal will be activated and subscribed to. In that regard it is very similar to [`computed(fn)`](#computedfn). By default all updates are lazy, so nothing will update until you access a signal inside `effect`.
|
|
112
|
-
|
|
113
|
-
```js
|
|
114
|
-
import { signal, computed, effect } from "@preact/signals-core";
|
|
115
|
-
|
|
116
|
-
const name = signal("Jane");
|
|
117
|
-
const surname = signal("Doe");
|
|
118
|
-
const fullName = computed(() => name.value + " " + surname.value);
|
|
119
|
-
|
|
120
|
-
// Logs: "Jane Doe"
|
|
121
|
-
effect(() => console.log(fullName.value));
|
|
122
|
-
|
|
123
|
-
// Updating one of its dependencies will automatically trigger
|
|
124
|
-
// the effect above, and will print "John Doe" to the console.
|
|
125
|
-
name.value = "John";
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
You can destroy an effect and unsubscribe from all signals it was subscribed to, by calling the returned function.
|
|
129
|
-
|
|
130
|
-
```js
|
|
131
|
-
import { signal, computed, effect } from "@preact/signals-core";
|
|
132
|
-
|
|
133
|
-
const name = signal("Jane");
|
|
134
|
-
const surname = signal("Doe");
|
|
135
|
-
const fullName = computed(() => name.value + " " + surname.value);
|
|
136
|
-
|
|
137
|
-
// Logs: "Jane Doe"
|
|
138
|
-
const dispose = effect(() => console.log(fullName.value));
|
|
139
|
-
|
|
140
|
-
// Destroy effect and subscriptions
|
|
141
|
-
dispose();
|
|
142
|
-
|
|
143
|
-
// Update does nothing, because no one is subscribed anymore.
|
|
144
|
-
// Even the computed `fullName` signal won't change, because it knows
|
|
145
|
-
// that no one listens to it.
|
|
146
|
-
surname.value = "Doe 2";
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
Alternatively, you can also declare your effect as a non-arrow function and call `dispose`
|
|
150
|
-
on the `this`.
|
|
151
|
-
|
|
152
|
-
```js
|
|
153
|
-
effect(function () {
|
|
154
|
-
this.dispose();
|
|
155
|
-
});
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
The effect callback may return a cleanup function. The cleanup function gets run once, either when the effect callback is next called _or_ when the effect gets disposed, whichever happens first.
|
|
159
|
-
|
|
160
|
-
```js
|
|
161
|
-
import { signal, effect } from "@preact/signals-core";
|
|
162
|
-
|
|
163
|
-
const count = signal(0);
|
|
164
|
-
|
|
165
|
-
const dispose = effect(() => {
|
|
166
|
-
const c = count.value;
|
|
167
|
-
return () => console.log(`cleanup ${c}`);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// Logs: cleanup 0
|
|
171
|
-
count.value = 1;
|
|
172
|
-
|
|
173
|
-
// Logs: cleanup 1
|
|
174
|
-
dispose();
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### `batch(fn)`
|
|
178
|
-
|
|
179
|
-
The `batch` function allows you to combine multiple signal writes into one single update that is triggered at the end when the callback completes.
|
|
180
|
-
|
|
181
|
-
```js
|
|
182
|
-
import { signal, computed, effect, batch } from "@preact/signals-core";
|
|
183
|
-
|
|
184
|
-
const name = signal("Jane");
|
|
185
|
-
const surname = signal("Doe");
|
|
186
|
-
const fullName = computed(() => name.value + " " + surname.value);
|
|
187
|
-
|
|
188
|
-
// Logs: "Jane Doe"
|
|
189
|
-
effect(() => console.log(fullName.value));
|
|
190
|
-
|
|
191
|
-
// Combines both signal writes into one update. Once the callback
|
|
192
|
-
// returns the `effect` will trigger and we'll log "Foo Bar"
|
|
193
|
-
batch(() => {
|
|
194
|
-
name.value = "Foo";
|
|
195
|
-
surname.value = "Bar";
|
|
196
|
-
});
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
When you access a signal that you wrote to earlier inside the callback, or access a computed signal that was invalidated by another signal, we'll only update the necessary dependencies to get the current value for the signal you read from. All other invalidated signals will update at the end of the callback function.
|
|
200
|
-
|
|
201
|
-
```js
|
|
202
|
-
import { signal, computed, effect, batch } from "@preact/signals-core";
|
|
203
|
-
|
|
204
|
-
const counter = signal(0);
|
|
205
|
-
const double = computed(() => counter.value * 2);
|
|
206
|
-
const triple = computed(() => counter.value * 3);
|
|
207
|
-
|
|
208
|
-
effect(() => console.log(double.value, triple.value));
|
|
209
|
-
|
|
210
|
-
batch(() => {
|
|
211
|
-
counter.value = 1;
|
|
212
|
-
// Logs: 2, despite being inside batch, but `triple`
|
|
213
|
-
// will only update once the callback is complete
|
|
214
|
-
console.log(double.value);
|
|
215
|
-
});
|
|
216
|
-
// Now we reached the end of the batch and call the effect
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
Batches can be nested and updates will be flushed when the outermost batch call completes.
|
|
220
|
-
|
|
221
|
-
```js
|
|
222
|
-
import { signal, computed, effect, batch } from "@preact/signals-core";
|
|
223
|
-
|
|
224
|
-
const counter = signal(0);
|
|
225
|
-
effect(() => console.log(counter.value));
|
|
226
|
-
|
|
227
|
-
batch(() => {
|
|
228
|
-
batch(() => {
|
|
229
|
-
// Signal is invalidated, but update is not flushed because
|
|
230
|
-
// we're still inside another batch
|
|
231
|
-
counter.value = 1;
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
// Still not updated...
|
|
235
|
-
});
|
|
236
|
-
// Now the callback completed and we'll trigger the effect.
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
### `untracked(fn)`
|
|
240
|
-
|
|
241
|
-
In case when you're receiving a callback that can read some signals, but you don't want to subscribe to them, you can use `untracked` to prevent any subscriptions from happening.
|
|
242
|
-
|
|
243
|
-
```js
|
|
244
|
-
const counter = signal(0);
|
|
245
|
-
const effectCount = signal(0);
|
|
246
|
-
const fn = () => effectCount.value + 1;
|
|
247
|
-
|
|
248
|
-
effect(() => {
|
|
249
|
-
console.log(counter.value);
|
|
250
|
-
|
|
251
|
-
// Whenever this effect is triggered, run `fn` that gives new value
|
|
252
|
-
effectCount.value = untracked(fn);
|
|
253
|
-
});
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
## License
|
|
257
|
-
|
|
258
|
-
`MIT`, see the [LICENSE](../../LICENSE) file.
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
declare const BRAND_SYMBOL: unique symbol;
|
|
2
|
-
type Node = {
|
|
3
|
-
_source: Signal;
|
|
4
|
-
_prevSource?: Node;
|
|
5
|
-
_nextSource?: Node;
|
|
6
|
-
_target: Computed | Effect;
|
|
7
|
-
_prevTarget?: Node;
|
|
8
|
-
_nextTarget?: Node;
|
|
9
|
-
_version: number;
|
|
10
|
-
_rollbackNode?: Node;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Combine multiple value updates into one "commit" at the end of the provided callback.
|
|
14
|
-
*
|
|
15
|
-
* Batches can be nested and changes are only flushed once the outermost batch callback
|
|
16
|
-
* completes.
|
|
17
|
-
*
|
|
18
|
-
* Accessing a signal that has been modified within a batch will reflect its updated
|
|
19
|
-
* value.
|
|
20
|
-
*
|
|
21
|
-
* @param fn The callback function.
|
|
22
|
-
* @returns The value returned by the callback.
|
|
23
|
-
*/
|
|
24
|
-
declare function batch<T>(fn: () => T): T;
|
|
25
|
-
/**
|
|
26
|
-
* Run a callback function that can access signal values without
|
|
27
|
-
* subscribing to the signal updates.
|
|
28
|
-
*
|
|
29
|
-
* @param fn The callback function.
|
|
30
|
-
* @returns The value returned by the callback.
|
|
31
|
-
*/
|
|
32
|
-
declare function untracked<T>(fn: () => T): T;
|
|
33
|
-
/**
|
|
34
|
-
* The base class for plain and computed signals.
|
|
35
|
-
*/
|
|
36
|
-
declare class Signal<T = any> {
|
|
37
|
-
constructor(value?: T, options?: SignalOptions<T>);
|
|
38
|
-
subscribe(fn: (value: T) => void): () => void;
|
|
39
|
-
name?: string;
|
|
40
|
-
valueOf(): T;
|
|
41
|
-
toString(): string;
|
|
42
|
-
toJSON(): T;
|
|
43
|
-
peek(): T;
|
|
44
|
-
brand: typeof BRAND_SYMBOL;
|
|
45
|
-
get value(): T;
|
|
46
|
-
set value(value: T);
|
|
47
|
-
}
|
|
48
|
-
export interface SignalOptions<T = any> {
|
|
49
|
-
watched?: (this: Signal<T>) => void;
|
|
50
|
-
unwatched?: (this: Signal<T>) => void;
|
|
51
|
-
name?: string;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Create a new plain signal.
|
|
55
|
-
*
|
|
56
|
-
* @param value The initial value for the signal.
|
|
57
|
-
* @returns A new signal.
|
|
58
|
-
*/
|
|
59
|
-
export declare function signal<T>(value: T, options?: SignalOptions<T>): Signal<T>;
|
|
60
|
-
export declare function signal<T = undefined>(): Signal<T | undefined>;
|
|
61
|
-
/**
|
|
62
|
-
* The base class for computed signals.
|
|
63
|
-
*/
|
|
64
|
-
declare class Computed<T = any> extends Signal<T> {
|
|
65
|
-
_fn: () => T;
|
|
66
|
-
_sources?: Node;
|
|
67
|
-
_globalVersion: number;
|
|
68
|
-
_flags: number;
|
|
69
|
-
constructor(fn: () => T, options?: SignalOptions<T>);
|
|
70
|
-
_notify(): void;
|
|
71
|
-
get value(): T;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* An interface for read-only signals.
|
|
75
|
-
*/
|
|
76
|
-
interface ReadonlySignal<T = any> {
|
|
77
|
-
readonly value: T;
|
|
78
|
-
peek(): T;
|
|
79
|
-
subscribe(fn: (value: T) => void): () => void;
|
|
80
|
-
valueOf(): T;
|
|
81
|
-
toString(): string;
|
|
82
|
-
toJSON(): T;
|
|
83
|
-
brand: typeof BRAND_SYMBOL;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Create a new signal that is computed based on the values of other signals.
|
|
87
|
-
*
|
|
88
|
-
* The returned computed signal is read-only, and its value is automatically
|
|
89
|
-
* updated when any signals accessed from within the callback function change.
|
|
90
|
-
*
|
|
91
|
-
* @param fn The effect callback.
|
|
92
|
-
* @returns A new read-only signal.
|
|
93
|
-
*/
|
|
94
|
-
declare function computed<T>(fn: () => T, options?: SignalOptions<T>): ReadonlySignal<T>;
|
|
95
|
-
type EffectFn = ((this: {
|
|
96
|
-
dispose: () => void;
|
|
97
|
-
}) => void | (() => void)) | (() => void | (() => void));
|
|
98
|
-
type DisposeSymbol = typeof Symbol extends {
|
|
99
|
-
readonly dispose: infer TDispose;
|
|
100
|
-
} ? TDispose : never;
|
|
101
|
-
type DisposableLike = {
|
|
102
|
-
[K in DisposeSymbol & PropertyKey]: () => void;
|
|
103
|
-
};
|
|
104
|
-
type DisposeFn = (() => void) & DisposableLike;
|
|
105
|
-
/**
|
|
106
|
-
* The base class for reactive effects.
|
|
107
|
-
*/
|
|
108
|
-
declare class Effect {
|
|
109
|
-
_fn?: EffectFn;
|
|
110
|
-
_cleanup?: () => void;
|
|
111
|
-
_sources?: Node;
|
|
112
|
-
_nextBatchedEffect?: Effect;
|
|
113
|
-
_flags: number;
|
|
114
|
-
_debugCallback?: () => void;
|
|
115
|
-
name?: string;
|
|
116
|
-
constructor(fn: EffectFn, options?: EffectOptions);
|
|
117
|
-
_callback(): void;
|
|
118
|
-
_start(): () => void;
|
|
119
|
-
_notify(): void;
|
|
120
|
-
_dispose(): void;
|
|
121
|
-
dispose(): void;
|
|
122
|
-
}
|
|
123
|
-
export interface EffectOptions {
|
|
124
|
-
name?: string;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Create an effect to run arbitrary code in response to signal changes.
|
|
128
|
-
*
|
|
129
|
-
* An effect tracks which signals are accessed within the given callback
|
|
130
|
-
* function `fn`, and re-runs the callback when those signals change.
|
|
131
|
-
*
|
|
132
|
-
* The callback may return a cleanup function. The cleanup function gets
|
|
133
|
-
* run once, either when the callback is next called or when the effect
|
|
134
|
-
* gets disposed, whichever happens first.
|
|
135
|
-
*
|
|
136
|
-
* @param fn The effect callback.
|
|
137
|
-
* @returns A function for disposing the effect.
|
|
138
|
-
*/
|
|
139
|
-
declare function effect(fn: EffectFn, options?: EffectOptions): DisposeFn;
|
|
140
|
-
declare function action<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
|
|
141
|
-
/** Models should only contain signals, actions, and nested objects containing only signals and actions. */
|
|
142
|
-
type ValidateModel<TModel> = {
|
|
143
|
-
[Key in keyof TModel]: TModel[Key] extends ReadonlySignal<unknown> ? TModel[Key] : TModel[Key] extends (...args: any[]) => any ? TModel[Key] : TModel[Key] extends object ? ValidateModel<TModel[Key]> : `Property ${Key extends string ? `'${Key}' ` : ""}is not a Signal, Action, or an object that contains only Signals and Actions.`;
|
|
144
|
-
};
|
|
145
|
-
export type Model<TModel> = ValidateModel<TModel> & DisposableLike;
|
|
146
|
-
export type ModelFactory<TModel, TFactoryArgs extends any[] = []> = (...args: TFactoryArgs) => ValidateModel<TModel>;
|
|
147
|
-
export type ModelConstructor<TModel, TFactoryArgs extends any[] = []> = new (...args: TFactoryArgs) => Model<TModel>;
|
|
148
|
-
declare function createModel<TModel, TFactoryArgs extends any[] = []>(modelFactory: ModelFactory<TModel, TFactoryArgs>): ModelConstructor<TModel, TFactoryArgs>;
|
|
149
|
-
export { computed, effect, batch, untracked, action, createModel, Signal, ReadonlySignal, Effect, Computed, };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var i=Symbol.for("preact-signals");function t(){if(!(h>1)){var i,t=!1;!function(){var i=c;c=void 0;while(void 0!==i){if(i.S.v===i.v)i.S.i=i.i;i=i.o}}();while(void 0!==s){var r=s;s=void 0;v++;while(void 0!==r){var n=r.u;r.u=void 0;r.f&=-3;if(!(8&r.f)&&y(r))try{r.c()}catch(r){if(!t){i=r;t=!0}}r=n}}v=0;h--;if(t)throw i}else h--}function r(i){if(h>0)return i();u=++e;h++;try{return i()}finally{t()}}var n=void 0;function o(i){var t=n;n=void 0;try{return i()}finally{n=t}}var f,s=void 0,h=0,v=0,e=0,u=0,c=void 0,d=0;function a(i){if(void 0!==n){var t=i.n;if(void 0===t||t.t!==n){t={i:0,S:i,p:n.s,n:void 0,t:n,e:void 0,x:void 0,r:t};if(void 0!==n.s)n.s.n=t;n.s=t;i.n=t;if(32&n.f)i.S(t);return t}else if(-1===t.i){t.i=0;if(void 0!==t.n){t.n.p=t.p;if(void 0!==t.p)t.p.n=t.n;t.p=n.s;t.n=void 0;n.s.n=t;n.s=t}return t}}}function l(i,t){this.v=i;this.i=0;this.n=void 0;this.t=void 0;this.l=0;this.W=null==t?void 0:t.watched;this.Z=null==t?void 0:t.unwatched;this.name=null==t?void 0:t.name}l.prototype.brand=i;l.prototype.h=function(){return!0};l.prototype.S=function(i){var t=this,r=this.t;if(r!==i&&void 0===i.e){i.x=r;this.t=i;if(void 0!==r)r.e=i;else o(function(){var i;null==(i=t.W)||i.call(t)})}};l.prototype.U=function(i){var t=this;if(void 0!==this.t){var r=i.e,n=i.x;if(void 0!==r){r.x=n;i.e=void 0}if(void 0!==n){n.e=r;i.x=void 0}if(i===this.t){this.t=n;if(void 0===n)o(function(){var i;null==(i=t.Z)||i.call(t)})}}};l.prototype.subscribe=function(i){var t=this;return m(function(){var r=t.value,o=n;n=void 0;try{i(r)}finally{n=o}},{name:"sub"})};l.prototype.valueOf=function(){return this.value};l.prototype.toString=function(){return this.value+""};l.prototype.toJSON=function(){return this.value};l.prototype.peek=function(){var i=n;n=void 0;try{return this.value}finally{n=i}};Object.defineProperty(l.prototype,"value",{get:function(){var i=a(this);if(void 0!==i)i.i=this.i;return this.v},set:function(i){if(i!==this.v){if(v>100)throw new Error("Cycle detected");!function(i){if(0!==h&&0===v)if(i.l!==u){i.l=u;c={S:i,v:i.v,i:i.i,o:c}}}(this);this.v=i;this.i++;d++;h++;try{for(var r=this.t;void 0!==r;r=r.x)r.t.N()}finally{t()}}}});function y(i){for(var t=i.s;void 0!==t;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function w(i){for(var t=i.s;void 0!==t;t=t.n){var r=t.S.n;if(void 0!==r)t.r=r;t.S.n=t;t.i=-1;if(void 0===t.n){i.s=t;break}}}function p(i){var t=i.s,r=void 0;while(void 0!==t){var n=t.p;if(-1===t.i){t.S.U(t);if(void 0!==n)n.n=t.n;if(void 0!==t.n)t.n.p=n}else r=t;t.S.n=t.r;if(void 0!==t.r)t.r=void 0;t=n}i.s=r}function x(i,t){l.call(this,void 0);this.x=i;this.s=void 0;this.g=d-1;this.f=4;this.W=null==t?void 0:t.watched;this.Z=null==t?void 0:t.unwatched;this.name=null==t?void 0:t.name}x.prototype=new l;x.prototype.h=function(){this.f&=-3;if(1&this.f)return!1;if(32==(36&this.f))return!0;this.f&=-5;if(this.g===d)return!0;this.g=d;this.f|=1;if(this.i>0&&!y(this)){this.f&=-2;return!0}var i=n;try{w(this);n=this;var t=this.x();if(16&this.f||this.v!==t||0===this.i){this.v=t;this.f&=-17;this.i++}}catch(i){this.v=i;this.f|=16;this.i++}n=i;p(this);this.f&=-2;return!0};x.prototype.S=function(i){if(void 0===this.t){this.f|=36;for(var t=this.s;void 0!==t;t=t.n)t.S.S(t)}l.prototype.S.call(this,i)};x.prototype.U=function(i){if(void 0!==this.t){l.prototype.U.call(this,i);if(void 0===this.t){this.f&=-33;for(var t=this.s;void 0!==t;t=t.n)t.S.U(t)}}};x.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var i=this.t;void 0!==i;i=i.x)i.t.N()}};Object.defineProperty(x.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var i=a(this);this.h();if(void 0!==i)i.i=this.i;if(16&this.f)throw this.v;return this.v}});function _(i){var r=i.m;i.m=void 0;if("function"==typeof r){h++;var o=n;n=void 0;try{r()}catch(t){i.f&=-2;i.f|=8;b(i);throw t}finally{n=o;t()}}}function b(i){for(var t=i.s;void 0!==t;t=t.n)t.S.U(t);i.x=void 0;i.s=void 0;_(i)}function g(i){if(n!==this)throw new Error("Out-of-order effect");p(this);n=i;this.f&=-2;if(8&this.f)b(this);t()}function S(i,t){this.x=i;this.m=void 0;this.s=void 0;this.u=void 0;this.f=32;this.name=null==t?void 0:t.name;if(f)f.push(this)}S.prototype.c=function(){var i=this.S();try{if(8&this.f)return;if(void 0===this.x)return;var t=this.x();if("function"==typeof t)this.m=t}finally{i()}};S.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1;this.f&=-9;_(this);w(this);h++;var i=n;n=this;return g.bind(this,i)};S.prototype.N=function(){if(!(2&this.f)){this.f|=2;this.u=s;s=this}};S.prototype.d=function(){this.f|=8;if(!(1&this.f))b(this)};S.prototype.dispose=function(){this.d()};function m(i,t){var r=new S(i,t);try{r.c()}catch(i){r.d();throw i}var n=r.d.bind(r);n[Symbol.dispose]=n;return n}function E(i){return function(){var t=arguments,n=this;return r(function(){return o(function(){return i.apply(n,[].slice.call(t))})})}}function j(){var i=f;f=[];return function(){var t=f;if(f&&i)i=i.concat(f);f=i;return t}}var C=function(i){for(var t in i){var r=i[t];if("function"==typeof r)i[t]=E(r);else if("object"==typeof r&&null!==r&&!("brand"in r))C(r)}};exports.Computed=x;exports.Effect=S;exports.Signal=l;exports.action=E;exports.batch=r;exports.computed=function(i,t){return new x(i,t)};exports.createModel=function(i){return function(){var t,r,n=j();try{r=i.apply(void 0,[].slice.call(arguments))}catch(i){f=void 0;throw i}finally{t=n()}C(r);r[Symbol.dispose]=E(function(){if(t)for(var i=0;i<t.length;i++)t[i].dispose();t=void 0});return r}};exports.effect=m;exports.signal=function(i,t){return new l(i,t)};exports.untracked=o;//# sourceMappingURL=signals-core.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signals-core.js","sources":["../src/index.ts"],"sourcesContent":["// An named symbol/brand for detecting Signal instances even when they weren't\n// created using the same signals library version.\nconst BRAND_SYMBOL = Symbol.for(\"preact-signals\");\n\n// Flags for Computed and Effect.\nconst RUNNING = 1 << 0;\nconst NOTIFIED = 1 << 1;\nconst OUTDATED = 1 << 2;\nconst DISPOSED = 1 << 3;\nconst HAS_ERROR = 1 << 4;\nconst TRACKING = 1 << 5;\n\n// A linked list node used to track dependencies (sources) and dependents (targets).\n// Also used to remember the source's last version number that the target saw.\ntype Node = {\n\t// A source whose value the target depends on.\n\t_source: Signal;\n\t_prevSource?: Node;\n\t_nextSource?: Node;\n\n\t// A target that depends on the source and should be notified when the source changes.\n\t_target: Computed | Effect;\n\t_prevTarget?: Node;\n\t_nextTarget?: Node;\n\n\t// The version number of the source that target has last seen. We use version numbers\n\t// instead of storing the source value, because source values can take arbitrary amount\n\t// of memory, and computeds could hang on to them forever because they're lazily evaluated.\n\t// Use the special value -1 to mark potentially unused but recyclable nodes.\n\t_version: number;\n\n\t// Used to remember & roll back the source's previous `._node` value when entering &\n\t// exiting a new evaluation context.\n\t_rollbackNode?: Node;\n};\n\nfunction startBatch() {\n\tbatchDepth++;\n}\n\nfunction endBatch() {\n\tif (batchDepth > 1) {\n\t\tbatchDepth--;\n\t\treturn;\n\t}\n\n\tlet error: unknown;\n\tlet hasError = false;\n\treconcileBatchSnapshots();\n\n\twhile (batchedEffect !== undefined) {\n\t\tlet effect: Effect | undefined = batchedEffect;\n\t\tbatchedEffect = undefined;\n\n\t\tbatchIteration++;\n\n\t\twhile (effect !== undefined) {\n\t\t\tconst next: Effect | undefined = effect._nextBatchedEffect;\n\t\t\teffect._nextBatchedEffect = undefined;\n\t\t\teffect._flags &= ~NOTIFIED;\n\n\t\t\tif (!(effect._flags & DISPOSED) && needsToRecompute(effect)) {\n\t\t\t\ttry {\n\t\t\t\t\teffect._callback();\n\t\t\t\t} catch (err) {\n\t\t\t\t\tif (!hasError) {\n\t\t\t\t\t\terror = err;\n\t\t\t\t\t\thasError = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\teffect = next;\n\t\t}\n\t}\n\tbatchIteration = 0;\n\tbatchDepth--;\n\n\tif (hasError) {\n\t\tthrow error;\n\t}\n}\n\n/**\n * Combine multiple value updates into one \"commit\" at the end of the provided callback.\n *\n * Batches can be nested and changes are only flushed once the outermost batch callback\n * completes.\n *\n * Accessing a signal that has been modified within a batch will reflect its updated\n * value.\n *\n * @param fn The callback function.\n * @returns The value returned by the callback.\n */\nfunction batch<T>(fn: () => T): T {\n\tif (batchDepth > 0) {\n\t\treturn fn();\n\t}\n\tcurrentBatchSnapshotVersion = ++batchSnapshotVersion;\n\t/*@__INLINE__**/ startBatch();\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tendBatch();\n\t}\n}\n\n// Currently evaluated computed or effect.\nlet evalContext: Computed | Effect | undefined = undefined;\n\n/**\n * Run a callback function that can access signal values without\n * subscribing to the signal updates.\n *\n * @param fn The callback function.\n * @returns The value returned by the callback.\n */\nfunction untracked<T>(fn: () => T): T {\n\tconst prevContext = evalContext;\n\tevalContext = undefined;\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tevalContext = prevContext;\n\t}\n}\n\n// Effects collected into a batch.\nlet batchedEffect: Effect | undefined = undefined;\nlet batchDepth = 0;\nlet batchIteration = 0;\n\ntype BatchSnapshot = {\n\t_source: Signal;\n\t_value: unknown;\n\t_version: number;\n\t_next?: BatchSnapshot;\n};\n\nlet batchSnapshotVersion = 0;\nlet currentBatchSnapshotVersion = 0;\nlet batchSnapshots: BatchSnapshot | undefined = undefined;\n\n// A global version number for signals, used for fast-pathing repeated\n// computed.peek()/computed.value calls when nothing has changed globally.\nlet globalVersion = 0;\n\nfunction recordBatchSnapshot(source: Signal) {\n\t// Only capture writes during the user-visible batch callback, not during effect flush.\n\tif (batchDepth === 0 || batchIteration !== 0) {\n\t\treturn;\n\t}\n\n\tif (source._batchSnapshotVersion !== currentBatchSnapshotVersion) {\n\t\tsource._batchSnapshotVersion = currentBatchSnapshotVersion;\n\t\tbatchSnapshots = {\n\t\t\t_source: source,\n\t\t\t_value: source._value,\n\t\t\t_version: source._version,\n\t\t\t_next: batchSnapshots,\n\t\t};\n\t}\n}\n\nfunction reconcileBatchSnapshots() {\n\tlet snapshots = batchSnapshots;\n\tbatchSnapshots = undefined;\n\n\twhile (snapshots !== undefined) {\n\t\tif (snapshots._source._value === snapshots._value) {\n\t\t\tsnapshots._source._version = snapshots._version;\n\t\t}\n\t\tsnapshots = snapshots._next;\n\t}\n}\n\nfunction addDependency(signal: Signal): Node | undefined {\n\tif (evalContext === undefined) {\n\t\treturn undefined;\n\t}\n\n\tlet node = signal._node;\n\tif (node === undefined || node._target !== evalContext) {\n\t\t/**\n\t\t * `signal` is a new dependency. Create a new dependency node, and set it\n\t\t * as the tail of the current context's dependency list. e.g:\n\t\t *\n\t\t * { A <-> B }\n\t\t * ↑ ↑\n\t\t * tail node (new)\n\t\t * ↓\n\t\t * { A <-> B <-> C }\n\t\t * ↑\n\t\t * tail (evalContext._sources)\n\t\t */\n\t\tnode = {\n\t\t\t_version: 0,\n\t\t\t_source: signal,\n\t\t\t_prevSource: evalContext._sources,\n\t\t\t_nextSource: undefined,\n\t\t\t_target: evalContext,\n\t\t\t_prevTarget: undefined,\n\t\t\t_nextTarget: undefined,\n\t\t\t_rollbackNode: node,\n\t\t};\n\n\t\tif (evalContext._sources !== undefined) {\n\t\t\tevalContext._sources._nextSource = node;\n\t\t}\n\t\tevalContext._sources = node;\n\t\tsignal._node = node;\n\n\t\t// Subscribe to change notifications from this dependency if we're in an effect\n\t\t// OR evaluating a computed signal that in turn has subscribers.\n\t\tif (evalContext._flags & TRACKING) {\n\t\t\tsignal._subscribe(node);\n\t\t}\n\t\treturn node;\n\t} else if (node._version === -1) {\n\t\t// `signal` is an existing dependency from a previous evaluation. Reuse it.\n\t\tnode._version = 0;\n\n\t\t/**\n\t\t * If `node` is not already the current tail of the dependency list (i.e.\n\t\t * there is a next node in the list), then make the `node` the new tail. e.g:\n\t\t *\n\t\t * { A <-> B <-> C <-> D }\n\t\t * ↑ ↑\n\t\t * node ┌─── tail (evalContext._sources)\n\t\t * └─────│─────┐\n\t\t * ↓ ↓\n\t\t * { A <-> C <-> D <-> B }\n\t\t * ↑\n\t\t * tail (evalContext._sources)\n\t\t */\n\t\tif (node._nextSource !== undefined) {\n\t\t\tnode._nextSource._prevSource = node._prevSource;\n\n\t\t\tif (node._prevSource !== undefined) {\n\t\t\t\tnode._prevSource._nextSource = node._nextSource;\n\t\t\t}\n\n\t\t\tnode._prevSource = evalContext._sources;\n\t\t\tnode._nextSource = undefined;\n\n\t\t\tevalContext._sources!._nextSource = node;\n\t\t\tevalContext._sources = node;\n\t\t}\n\n\t\t// We can assume that the currently evaluated effect / computed signal is already\n\t\t// subscribed to change notifications from `signal` if needed.\n\t\treturn node;\n\t}\n\treturn undefined;\n}\n\n//#region Signal\n\n/**\n * The base class for plain and computed signals.\n */\n//\n// A function with the same name is defined later, so we need to ignore TypeScript's\n// warning about a redeclared variable.\n//\n// The class is declared here, but later implemented with ES5-style prototypes.\n// This enables better control of the transpiled output size.\n// @ts-ignore: \"Cannot redeclare exported variable 'Signal'.\"\ndeclare class Signal<T = any> {\n\t/** @internal */\n\t_value: unknown;\n\n\t/**\n\t * @internal\n\t * Version numbers should always be >= 0, because the special value -1 is used\n\t * by Nodes to signify potentially unused but recyclable nodes.\n\t */\n\t_version: number;\n\n\t/** @internal */\n\t_node?: Node;\n\n\t/** @internal */\n\t_targets?: Node;\n\n\t/** @internal */\n\t_batchSnapshotVersion: number;\n\n\tconstructor(value?: T, options?: SignalOptions<T>);\n\n\t/** @internal */\n\t_refresh(): boolean;\n\n\t/** @internal */\n\t_subscribe(node: Node): void;\n\n\t/** @internal */\n\t_unsubscribe(node: Node): void;\n\n\t/** @internal */\n\t_watched?(this: Signal<T>): void;\n\n\t/** @internal */\n\t_unwatched?(this: Signal<T>): void;\n\n\tsubscribe(fn: (value: T) => void): () => void;\n\n\tname?: string;\n\n\tvalueOf(): T;\n\n\ttoString(): string;\n\n\ttoJSON(): T;\n\n\tpeek(): T;\n\n\tbrand: typeof BRAND_SYMBOL;\n\n\tget value(): T;\n\tset value(value: T);\n}\n\nexport interface SignalOptions<T = any> {\n\twatched?: (this: Signal<T>) => void;\n\tunwatched?: (this: Signal<T>) => void;\n\tname?: string;\n}\n\n/** @internal */\n// A class with the same name has already been declared, so we need to ignore\n// TypeScript's warning about a redeclared variable.\n//\n// The previously declared class is implemented here with ES5-style prototypes.\n// This enables better control of the transpiled output size.\n// @ts-ignore: \"Cannot redeclare exported variable 'Signal'.\"\nfunction Signal(this: Signal, value?: unknown, options?: SignalOptions) {\n\tthis._value = value;\n\tthis._version = 0;\n\tthis._node = undefined;\n\tthis._targets = undefined;\n\tthis._batchSnapshotVersion = 0;\n\tthis._watched = options?.watched;\n\tthis._unwatched = options?.unwatched;\n\tthis.name = options?.name;\n}\n\nSignal.prototype.brand = BRAND_SYMBOL;\n\nSignal.prototype._refresh = function () {\n\treturn true;\n};\n\nSignal.prototype._subscribe = function (node) {\n\tconst targets = this._targets;\n\tif (targets !== node && node._prevTarget === undefined) {\n\t\tnode._nextTarget = targets;\n\t\tthis._targets = node;\n\n\t\tif (targets !== undefined) {\n\t\t\ttargets._prevTarget = node;\n\t\t} else {\n\t\t\tuntracked(() => {\n\t\t\t\tthis._watched?.call(this);\n\t\t\t});\n\t\t}\n\t}\n};\n\nSignal.prototype._unsubscribe = function (node) {\n\t// Only run the unsubscribe step if the signal has any subscribers to begin with.\n\tif (this._targets !== undefined) {\n\t\tconst prev = node._prevTarget;\n\t\tconst next = node._nextTarget;\n\t\tif (prev !== undefined) {\n\t\t\tprev._nextTarget = next;\n\t\t\tnode._prevTarget = undefined;\n\t\t}\n\n\t\tif (next !== undefined) {\n\t\t\tnext._prevTarget = prev;\n\t\t\tnode._nextTarget = undefined;\n\t\t}\n\n\t\tif (node === this._targets) {\n\t\t\tthis._targets = next;\n\t\t\tif (next === undefined) {\n\t\t\t\tuntracked(() => {\n\t\t\t\t\tthis._unwatched?.call(this);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n};\n\nSignal.prototype.subscribe = function (fn) {\n\treturn effect(\n\t\t() => {\n\t\t\tconst value = this.value;\n\t\t\tconst prevContext = evalContext;\n\t\t\tevalContext = undefined;\n\t\t\ttry {\n\t\t\t\tfn(value);\n\t\t\t} finally {\n\t\t\t\tevalContext = prevContext;\n\t\t\t}\n\t\t},\n\t\t{ name: \"sub\" }\n\t);\n};\n\nSignal.prototype.valueOf = function () {\n\treturn this.value;\n};\n\nSignal.prototype.toString = function () {\n\treturn this.value + \"\";\n};\n\nSignal.prototype.toJSON = function () {\n\treturn this.value;\n};\n\nSignal.prototype.peek = function () {\n\tconst prevContext = evalContext;\n\tevalContext = undefined;\n\ttry {\n\t\treturn this.value;\n\t} finally {\n\t\tevalContext = prevContext;\n\t}\n};\n\nObject.defineProperty(Signal.prototype, \"value\", {\n\tget(this: Signal) {\n\t\tconst node = addDependency(this);\n\t\tif (node !== undefined) {\n\t\t\tnode._version = this._version;\n\t\t}\n\t\treturn this._value;\n\t},\n\tset(this: Signal, value) {\n\t\tif (value !== this._value) {\n\t\t\tif (batchIteration > 100) {\n\t\t\t\tthrow new Error(\"Cycle detected\");\n\t\t\t}\n\n\t\t\trecordBatchSnapshot(this);\n\t\t\tthis._value = value;\n\t\t\tthis._version++;\n\t\t\tglobalVersion++;\n\n\t\t\t/**@__INLINE__*/ startBatch();\n\t\t\ttry {\n\t\t\t\tfor (\n\t\t\t\t\tlet node = this._targets;\n\t\t\t\t\tnode !== undefined;\n\t\t\t\t\tnode = node._nextTarget\n\t\t\t\t) {\n\t\t\t\t\tnode._target._notify();\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tendBatch();\n\t\t\t}\n\t\t}\n\t},\n});\n\n/**\n * Create a new plain signal.\n *\n * @param value The initial value for the signal.\n * @returns A new signal.\n */\nexport function signal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function signal<T = undefined>(): Signal<T | undefined>;\nexport function signal<T>(value?: T, options?: SignalOptions<T>): Signal<T> {\n\treturn new Signal(value, options);\n}\n\n//#endregion Signal\n\n//#region Computed\n\nfunction needsToRecompute(target: Computed | Effect): boolean {\n\t// Check the dependencies for changed values. The dependency list is already\n\t// in order of use. Therefore if multiple dependencies have changed values, only\n\t// the first used dependency is re-evaluated at this point.\n\tfor (\n\t\tlet node = target._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tif (\n\t\t\t// If the dependency has definitely been updated since its version number\n\t\t\t// was observed, then we need to recompute. This first check is not strictly\n\t\t\t// necessary for correctness, but allows us to skip the refresh call if the\n\t\t\t// dependency has already been updated.\n\t\t\tnode._source._version !== node._version ||\n\t\t\t// Refresh the dependency. If there's something blocking the refresh (e.g. a\n\t\t\t// dependency cycle), then we need to recompute.\n\t\t\t!node._source._refresh() ||\n\t\t\t// If the dependency got a new version after the refresh, then we need to recompute.\n\t\t\tnode._source._version !== node._version\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\t// If none of the dependencies have changed values since last recompute then\n\t// there's no need to recompute.\n\treturn false;\n}\n\nfunction prepareSources(target: Computed | Effect) {\n\t/**\n\t * 1. Mark all current sources as re-usable nodes (version: -1)\n\t * 2. Set a rollback node if the current node is being used in a different context\n\t * 3. Point 'target._sources' to the tail of the doubly-linked list, e.g:\n\t *\n\t * { undefined <- A <-> B <-> C -> undefined }\n\t * ↑ ↑\n\t * │ └──────┐\n\t * target._sources = A; (node is head) │\n\t * ↓ │\n\t * target._sources = C; (node is tail) ─┘\n\t */\n\tfor (\n\t\tlet node = target._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tconst rollbackNode = node._source._node;\n\t\tif (rollbackNode !== undefined) {\n\t\t\tnode._rollbackNode = rollbackNode;\n\t\t}\n\t\tnode._source._node = node;\n\t\tnode._version = -1;\n\n\t\tif (node._nextSource === undefined) {\n\t\t\ttarget._sources = node;\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction cleanupSources(target: Computed | Effect) {\n\tlet node = target._sources;\n\tlet head: Node | undefined = undefined;\n\n\t/**\n\t * At this point 'target._sources' points to the tail of the doubly-linked list.\n\t * It contains all existing sources + new sources in order of use.\n\t * Iterate backwards until we find the head node while dropping old dependencies.\n\t */\n\twhile (node !== undefined) {\n\t\tconst prev = node._prevSource;\n\n\t\t/**\n\t\t * The node was not re-used, unsubscribe from its change notifications and remove itself\n\t\t * from the doubly-linked list. e.g:\n\t\t *\n\t\t * { A <-> B <-> C }\n\t\t * ↓\n\t\t * { A <-> C }\n\t\t */\n\t\tif (node._version === -1) {\n\t\t\tnode._source._unsubscribe(node);\n\n\t\t\tif (prev !== undefined) {\n\t\t\t\tprev._nextSource = node._nextSource;\n\t\t\t}\n\t\t\tif (node._nextSource !== undefined) {\n\t\t\t\tnode._nextSource._prevSource = prev;\n\t\t\t}\n\t\t} else {\n\t\t\t/**\n\t\t\t * The new head is the last node seen which wasn't removed/unsubscribed\n\t\t\t * from the doubly-linked list. e.g:\n\t\t\t *\n\t\t\t * { A <-> B <-> C }\n\t\t\t * ↑ ↑ ↑\n\t\t\t * │ │ └ head = node\n\t\t\t * │ └ head = node\n\t\t\t * └ head = node\n\t\t\t */\n\t\t\thead = node;\n\t\t}\n\n\t\tnode._source._node = node._rollbackNode;\n\t\tif (node._rollbackNode !== undefined) {\n\t\t\tnode._rollbackNode = undefined;\n\t\t}\n\n\t\tnode = prev;\n\t}\n\n\ttarget._sources = head;\n}\n\n/**\n * The base class for computed signals.\n */\ndeclare class Computed<T = any> extends Signal<T> {\n\t_fn: () => T;\n\t_sources?: Node;\n\t_globalVersion: number;\n\t_flags: number;\n\n\tconstructor(fn: () => T, options?: SignalOptions<T>);\n\n\t_notify(): void;\n\tget value(): T;\n}\n\n/** @internal */\nfunction Computed(this: Computed, fn: () => unknown, options?: SignalOptions) {\n\tSignal.call(this, undefined);\n\n\tthis._fn = fn;\n\tthis._sources = undefined;\n\tthis._globalVersion = globalVersion - 1;\n\tthis._flags = OUTDATED;\n\tthis._watched = options?.watched;\n\tthis._unwatched = options?.unwatched;\n\tthis.name = options?.name;\n}\n\nComputed.prototype = new Signal() as Computed;\n\nComputed.prototype._refresh = function () {\n\tthis._flags &= ~NOTIFIED;\n\n\tif (this._flags & RUNNING) {\n\t\treturn false;\n\t}\n\n\t// If this computed signal has subscribed to updates from its dependencies\n\t// (TRACKING flag set) and none of them have notified about changes (OUTDATED\n\t// flag not set), then the computed value can't have changed.\n\tif ((this._flags & (OUTDATED | TRACKING)) === TRACKING) {\n\t\treturn true;\n\t}\n\tthis._flags &= ~OUTDATED;\n\n\tif (this._globalVersion === globalVersion) {\n\t\treturn true;\n\t}\n\tthis._globalVersion = globalVersion;\n\n\t// Mark this computed signal running before checking the dependencies for value\n\t// changes, so that the RUNNING flag can be used to notice cyclical dependencies.\n\tthis._flags |= RUNNING;\n\tif (this._version > 0 && !needsToRecompute(this)) {\n\t\tthis._flags &= ~RUNNING;\n\t\treturn true;\n\t}\n\n\tconst prevContext = evalContext;\n\ttry {\n\t\tprepareSources(this);\n\t\tevalContext = this;\n\t\tconst value = this._fn();\n\t\tif (\n\t\t\tthis._flags & HAS_ERROR ||\n\t\t\tthis._value !== value ||\n\t\t\tthis._version === 0\n\t\t) {\n\t\t\tthis._value = value;\n\t\t\tthis._flags &= ~HAS_ERROR;\n\t\t\tthis._version++;\n\t\t}\n\t} catch (err) {\n\t\tthis._value = err;\n\t\tthis._flags |= HAS_ERROR;\n\t\tthis._version++;\n\t}\n\tevalContext = prevContext;\n\tcleanupSources(this);\n\tthis._flags &= ~RUNNING;\n\treturn true;\n};\n\nComputed.prototype._subscribe = function (node) {\n\tif (this._targets === undefined) {\n\t\tthis._flags |= OUTDATED | TRACKING;\n\n\t\t// A computed signal subscribes lazily to its dependencies when it\n\t\t// gets its first subscriber.\n\t\tfor (\n\t\t\tlet node = this._sources;\n\t\t\tnode !== undefined;\n\t\t\tnode = node._nextSource\n\t\t) {\n\t\t\tnode._source._subscribe(node);\n\t\t}\n\t}\n\tSignal.prototype._subscribe.call(this, node);\n};\n\nComputed.prototype._unsubscribe = function (node) {\n\t// Only run the unsubscribe step if the computed signal has any subscribers.\n\tif (this._targets !== undefined) {\n\t\tSignal.prototype._unsubscribe.call(this, node);\n\n\t\t// Computed signal unsubscribes from its dependencies when it loses its last subscriber.\n\t\t// This makes it possible for unreferences subgraphs of computed signals to get garbage collected.\n\t\tif (this._targets === undefined) {\n\t\t\tthis._flags &= ~TRACKING;\n\n\t\t\tfor (\n\t\t\t\tlet node = this._sources;\n\t\t\t\tnode !== undefined;\n\t\t\t\tnode = node._nextSource\n\t\t\t) {\n\t\t\t\tnode._source._unsubscribe(node);\n\t\t\t}\n\t\t}\n\t}\n};\n\nComputed.prototype._notify = function () {\n\tif (!(this._flags & NOTIFIED)) {\n\t\tthis._flags |= OUTDATED | NOTIFIED;\n\n\t\tfor (\n\t\t\tlet node = this._targets;\n\t\t\tnode !== undefined;\n\t\t\tnode = node._nextTarget\n\t\t) {\n\t\t\tnode._target._notify();\n\t\t}\n\t}\n};\n\nObject.defineProperty(Computed.prototype, \"value\", {\n\tget(this: Computed) {\n\t\tif (this._flags & RUNNING) {\n\t\t\tthrow new Error(\"Cycle detected\");\n\t\t}\n\t\tconst node = addDependency(this);\n\t\tthis._refresh();\n\t\tif (node !== undefined) {\n\t\t\tnode._version = this._version;\n\t\t}\n\t\tif (this._flags & HAS_ERROR) {\n\t\t\tthrow this._value;\n\t\t}\n\t\treturn this._value;\n\t},\n});\n\n/**\n * An interface for read-only signals.\n */\ninterface ReadonlySignal<T = any> {\n\treadonly value: T;\n\tpeek(): T;\n\n\tsubscribe(fn: (value: T) => void): () => void;\n\tvalueOf(): T;\n\ttoString(): string;\n\ttoJSON(): T;\n\tbrand: typeof BRAND_SYMBOL;\n}\n\n/**\n * Create a new signal that is computed based on the values of other signals.\n *\n * The returned computed signal is read-only, and its value is automatically\n * updated when any signals accessed from within the callback function change.\n *\n * @param fn The effect callback.\n * @returns A new read-only signal.\n */\nfunction computed<T>(\n\tfn: () => T,\n\toptions?: SignalOptions<T>\n): ReadonlySignal<T> {\n\treturn new Computed(fn, options);\n}\n\n//#endregion Computed\n\n//#region Effect\n\nfunction cleanupEffect(effect: Effect) {\n\tconst cleanup = effect._cleanup;\n\teffect._cleanup = undefined;\n\n\tif (typeof cleanup === \"function\") {\n\t\t/*@__INLINE__**/ startBatch();\n\n\t\t// Run cleanup functions always outside of any context.\n\t\tconst prevContext = evalContext;\n\t\tevalContext = undefined;\n\t\ttry {\n\t\t\tcleanup();\n\t\t} catch (err) {\n\t\t\teffect._flags &= ~RUNNING;\n\t\t\teffect._flags |= DISPOSED;\n\t\t\tdisposeEffect(effect);\n\t\t\tthrow err;\n\t\t} finally {\n\t\t\tevalContext = prevContext;\n\t\t\tendBatch();\n\t\t}\n\t}\n}\n\nfunction disposeEffect(effect: Effect) {\n\tfor (\n\t\tlet node = effect._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tnode._source._unsubscribe(node);\n\t}\n\teffect._fn = undefined;\n\teffect._sources = undefined;\n\n\tcleanupEffect(effect);\n}\n\nfunction endEffect(this: Effect, prevContext?: Computed | Effect) {\n\tif (evalContext !== this) {\n\t\tthrow new Error(\"Out-of-order effect\");\n\t}\n\tcleanupSources(this);\n\tevalContext = prevContext;\n\n\tthis._flags &= ~RUNNING;\n\tif (this._flags & DISPOSED) {\n\t\tdisposeEffect(this);\n\t}\n\tendBatch();\n}\n\ntype EffectFn =\n\t| ((this: { dispose: () => void }) => void | (() => void))\n\t| (() => void | (() => void));\n\n// Avoid hard-requiring the ESNext.Disposable lib in consuming tsconfigs.\n// When `Symbol.dispose` is available, this becomes a symbol-keyed disposer type.\ntype DisposeSymbol = typeof Symbol extends { readonly dispose: infer TDispose }\n\t? TDispose\n\t: never;\ntype DisposableLike = {\n\t[K in DisposeSymbol & PropertyKey]: () => void;\n};\ntype DisposeFn = (() => void) & DisposableLike;\n\n/**\n * The base class for reactive effects.\n */\ndeclare class Effect {\n\t_fn?: EffectFn;\n\t_cleanup?: () => void;\n\t_sources?: Node;\n\t_nextBatchedEffect?: Effect;\n\t_flags: number;\n\t_debugCallback?: () => void;\n\tname?: string;\n\n\tconstructor(fn: EffectFn, options?: EffectOptions);\n\n\t_callback(): void;\n\t_start(): () => void;\n\t_notify(): void;\n\t_dispose(): void;\n\tdispose(): void;\n}\n\nexport interface EffectOptions {\n\tname?: string;\n}\n\nlet capturedEffects: Effect[] | undefined;\n\n/** @internal */\nfunction Effect(this: Effect, fn: EffectFn, options?: EffectOptions) {\n\tthis._fn = fn;\n\tthis._cleanup = undefined;\n\tthis._sources = undefined;\n\tthis._nextBatchedEffect = undefined;\n\tthis._flags = TRACKING;\n\tthis.name = options?.name;\n\n\tif (capturedEffects) {\n\t\tcapturedEffects.push(this);\n\t}\n}\n\nEffect.prototype._callback = function () {\n\tconst finish = this._start();\n\ttry {\n\t\tif (this._flags & DISPOSED) return;\n\t\tif (this._fn === undefined) return;\n\n\t\tconst cleanup = this._fn();\n\t\tif (typeof cleanup === \"function\") {\n\t\t\tthis._cleanup = cleanup;\n\t\t}\n\t} finally {\n\t\tfinish();\n\t}\n};\n\nEffect.prototype._start = function () {\n\tif (this._flags & RUNNING) {\n\t\tthrow new Error(\"Cycle detected\");\n\t}\n\tthis._flags |= RUNNING;\n\tthis._flags &= ~DISPOSED;\n\tcleanupEffect(this);\n\tprepareSources(this);\n\n\t/*@__INLINE__**/ startBatch();\n\tconst prevContext = evalContext;\n\tevalContext = this;\n\treturn endEffect.bind(this, prevContext);\n};\n\nEffect.prototype._notify = function () {\n\tif (!(this._flags & NOTIFIED)) {\n\t\tthis._flags |= NOTIFIED;\n\t\tthis._nextBatchedEffect = batchedEffect;\n\t\tbatchedEffect = this;\n\t}\n};\n\nEffect.prototype._dispose = function () {\n\tthis._flags |= DISPOSED;\n\n\tif (!(this._flags & RUNNING)) {\n\t\tdisposeEffect(this);\n\t}\n};\n\nEffect.prototype.dispose = function () {\n\tthis._dispose();\n};\n/**\n * Create an effect to run arbitrary code in response to signal changes.\n *\n * An effect tracks which signals are accessed within the given callback\n * function `fn`, and re-runs the callback when those signals change.\n *\n * The callback may return a cleanup function. The cleanup function gets\n * run once, either when the callback is next called or when the effect\n * gets disposed, whichever happens first.\n *\n * @param fn The effect callback.\n * @returns A function for disposing the effect.\n */\nfunction effect(fn: EffectFn, options?: EffectOptions): DisposeFn {\n\tconst effect = new Effect(fn, options);\n\ttry {\n\t\teffect._callback();\n\t} catch (err) {\n\t\teffect._dispose();\n\t\tthrow err;\n\t}\n\t// Return a bound function instead of a wrapper like `() => effect._dispose()`,\n\t// because bound functions seem to be just as fast and take up a lot less memory.\n\tconst dispose = effect._dispose.bind(effect);\n\t(dispose as any)[Symbol.dispose] = dispose;\n\treturn dispose as DisposeFn;\n}\n\n//#endregion Effect\n\n//#region Action\n\nfunction action<TArgs extends unknown[], TReturn>(\n\tfn: (...args: TArgs) => TReturn\n): (...args: TArgs) => TReturn {\n\treturn function actionWrapper(this: unknown, ...args: TArgs) {\n\t\treturn batch(() => untracked(() => fn.apply(this, args)));\n\t};\n}\n\n//#endregion Action\n\n//#region createModel\n\n/** Models should only contain signals, actions, and nested objects containing only signals and actions. */\ntype ValidateModel<TModel> = {\n\t[Key in keyof TModel]: TModel[Key] extends ReadonlySignal<unknown>\n\t\t? TModel[Key]\n\t\t: TModel[Key] extends (...args: any[]) => any\n\t\t\t? TModel[Key]\n\t\t\t: TModel[Key] extends object\n\t\t\t\t? ValidateModel<TModel[Key]>\n\t\t\t\t: `Property ${Key extends string ? `'${Key}' ` : \"\"}is not a Signal, Action, or an object that contains only Signals and Actions.`;\n};\n\nexport type Model<TModel> = ValidateModel<TModel> & DisposableLike;\n\nexport type ModelFactory<TModel, TFactoryArgs extends any[] = []> = (\n\t...args: TFactoryArgs\n) => ValidateModel<TModel>;\nexport type ModelConstructor<TModel, TFactoryArgs extends any[] = []> = new (\n\t...args: TFactoryArgs\n) => Model<TModel>;\n\n/**\n * The public types for ModelConstructor require using `new` to help\n * disambiguate the function passed into `createModel` and the returned\n * constructor function. It is easier to say that `createModel` accepts\n * a factory and returns a class, then to say it accepts a factory and\n * returns a factory. In other words, this example:\n *\n * ```ts\n * const PersonModel = createModel((name: string) => ({ ... }));\n * const person = new PersonModel(\"John\");\n * ```\n *\n * is easier to understand than this example:\n *\n * ```ts\n * const createPerson = createModel((name: string) => ({ ... }));\n * const person = createPerson(\"John\");\n * ```\n *\n * However, internally we implement `createModel` to return a function\n * that can be called without `new` for simplicity. To bridge the gap\n * between the public types and the internal implementation, we define\n * this internal interface that extends the public interface but also\n * allows calling without `new`.\n *\n * This pattern is used by the Preact & React adapters to make instantiating\n * a model or a function that returns a model easier.\n *\n * @internal\n */\ninterface InternalModelConstructor<\n\tTModel,\n\tTFactoryArgs extends any[],\n> extends ModelConstructor<TModel, TFactoryArgs> {\n\t(...args: TFactoryArgs): Model<TModel>;\n}\n\nfunction startCapturingEffects(): () => Effect[] | undefined {\n\tlet prevCapturedEffects = capturedEffects;\n\tcapturedEffects = [];\n\n\treturn function stopCapturingEffects() {\n\t\tlet modelEffects = capturedEffects;\n\t\tif (capturedEffects && prevCapturedEffects) {\n\t\t\tprevCapturedEffects = prevCapturedEffects.concat(capturedEffects);\n\t\t}\n\n\t\tcapturedEffects = prevCapturedEffects;\n\n\t\treturn modelEffects;\n\t};\n}\n\nconst wrapInAction = (value: Record<string, unknown>) => {\n\tfor (const key in value) {\n\t\tconst val = value[key];\n\t\tif (typeof val === \"function\") {\n\t\t\tvalue[key] = action(val as (...args: unknown[]) => unknown);\n\t\t} else if (typeof val === \"object\" && val !== null && !(\"brand\" in val)) {\n\t\t\t// Recursively wrap nested object properties in actions. This allows users to write\n\t\t\t// nested models without worrying about wrapping their functions in `action`.\n\t\t\twrapInAction(val as Record<string, unknown>);\n\t\t}\n\t}\n};\n\nfunction createModel<TModel, TFactoryArgs extends any[] = []>(\n\tmodelFactory: ModelFactory<TModel, TFactoryArgs>\n): ModelConstructor<TModel, TFactoryArgs> {\n\treturn function SignalModel(...args: TFactoryArgs): Model<TModel> {\n\t\tlet modelEffects: Effect[] | undefined;\n\t\tlet model: Model<TModel>;\n\n\t\tconst stopCapturingEffects = startCapturingEffects();\n\t\ttry {\n\t\t\tmodel = modelFactory(...args) as Model<TModel>;\n\t\t} catch (err) {\n\t\t\t// Drop any captured effects on error. Errors from nested models will bubble\n\t\t\t// up here and recursively reset `capturedEffects` to `undefined` preventing\n\t\t\t// any captured effects from leaking\n\t\t\tcapturedEffects = undefined;\n\t\t\tthrow err;\n\t\t} finally {\n\t\t\tmodelEffects = stopCapturingEffects();\n\t\t}\n\n\t\twrapInAction(model);\n\n\t\tmodel[Symbol.dispose] = action(function disposeModel() {\n\t\t\tif (modelEffects) {\n\t\t\t\tfor (let i = 0; i < modelEffects.length; i++) {\n\t\t\t\t\tmodelEffects[i].dispose();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tmodelEffects = undefined;\n\t\t});\n\n\t\treturn model;\n\t} as InternalModelConstructor<TModel, TFactoryArgs>;\n}\n\n//#endregion createModel\n\nexport {\n\tcomputed,\n\teffect,\n\tbatch,\n\tuntracked,\n\taction,\n\tcreateModel,\n\tSignal,\n\tReadonlySignal,\n\tEffect,\n\tComputed,\n};\n"],"names":["BRAND_SYMBOL","Symbol","endBatch","batchDepth","error","hasError","snapshots","batchSnapshots","undefined","_source","_value","_version","_next","reconcileBatchSnapshots","batchedEffect","effect","batchIteration","next","_nextBatchedEffect","_flags","needsToRecompute","_callback","err","batch","fn","currentBatchSnapshotVersion","batchSnapshotVersion","evalContext","untracked","prevContext","capturedEffects","globalVersion","addDependency","signal","node","_node","_target","_prevSource","_sources","_nextSource","_prevTarget","_nextTarget","_rollbackNode","_subscribe","Signal","value","options","this","_targets","_batchSnapshotVersion","_watched","watched","_unwatched","unwatched","name","prototype","brand","_refresh","_this","targets","_this$_watched","call","_unsubscribe","_this2","prev","_this2$_unwatched","subscribe","_this3","valueOf","toString","toJSON","peek","Object","defineProperty","get","set","Error","source","recordBatchSnapshot","_notify","target","prepareSources","rollbackNode","cleanupSources","head","Computed","_fn","_globalVersion","OUTDATED","cleanupEffect","cleanup","_cleanup","disposeEffect","endEffect","Effect","push","finish","_start","bind","_dispose","dispose","action","_arguments","arguments","_this4","apply","slice","startCapturingEffects","prevCapturedEffects","modelEffects","concat","wrapInAction","key","val","exports","computed","createModel","modelFactory","model","stopCapturingEffects","i","length"],"mappings":"AAEA,IAAMA,EAAeC,OAAU,IAAC,kBAsChC,SAASC,IACR,KAAIC,EAAa,GAAjB,CAKA,IAAIC,EACAC,GAAW,GAqHhB,WACC,IAAIC,EAAYC,EAChBA,OAAiBC,EAEjB,WAAqBA,IAAdF,EAAyB,CAC/B,GAAIA,EAAUG,EAAQC,IAAWJ,EAAUI,EAC1CJ,EAAUG,EAAQE,EAAWL,EAAUK,EAExCL,EAAYA,EAAUM,CACvB,CACD,CA9HCC,GAEA,WAAyBL,IAAlBM,EAA6B,CACnC,IAAIC,EAA6BD,EACjCA,OAAgBN,EAEhBQ,IAEA,WAAkBR,IAAXO,EAAsB,CAC5B,IAAME,EAA2BF,EAAOG,EACxCH,EAAOG,OAAqBV,EAC5BO,EAAOI,IAAU,EAEjB,KArDc,EAqDRJ,EAAOI,IAAsBC,EAAiBL,GACnD,IACCA,EAAOM,GAMR,CALE,MAAOC,GACR,IAAKjB,EAAU,CACdD,EAAQkB,EACRjB,GAAW,CACZ,CACD,CAEDU,EAASE,CACV,CACD,CACAD,EAAiB,EACjBb,IAEA,GAAIE,EACH,MAAMD,CAlCP,MAFCD,GAsCF,CAcA,SAASoB,EAASC,GACjB,GAAIrB,EAAa,EAChB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AIX,EAAaY,OAAQD,IACxCX,EAAaW,GAAGpB,UAIlBS,OAAerG,CAChB,GAEA,OAAO8G,CACR,CACD,EAAAJ,QAAAnG,OAAAA,EAAAmG,QAAAjF,OArnBgB,SAAUY,EAAWC,GACpC,WAAWF,EAAOC,EAAOC,EAC1B,EAmnBAoE,QAAAtF,UAAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((i||self).preactSignalsCore={})}(this,function(i){var t=Symbol.for("preact-signals");function n(){if(!(v>1)){var i,t=!1;!function(){var i=c;c=void 0;while(void 0!==i){if(i.S.v===i.v)i.S.i=i.i;i=i.o}}();while(void 0!==s){var n=s;s=void 0;e++;while(void 0!==n){var o=n.u;n.u=void 0;n.f&=-3;if(!(8&n.f)&&w(n))try{n.c()}catch(n){if(!t){i=n;t=!0}}n=o}}e=0;v--;if(t)throw i}else v--}function o(i){if(v>0)return i();d=++u;v++;try{return i()}finally{n()}}var r=void 0;function f(i){var t=r;r=void 0;try{return i()}finally{r=t}}var h,s=void 0,v=0,e=0,u=0,d=0,c=void 0,a=0;function l(i){if(void 0!==r){var t=i.n;if(void 0===t||t.t!==r){t={i:0,S:i,p:r.s,n:void 0,t:r,e:void 0,x:void 0,r:t};if(void 0!==r.s)r.s.n=t;r.s=t;i.n=t;if(32&r.f)i.S(t);return t}else if(-1===t.i){t.i=0;if(void 0!==t.n){t.n.p=t.p;if(void 0!==t.p)t.p.n=t.n;t.p=r.s;t.n=void 0;r.s.n=t;r.s=t}return t}}}function y(i,t){this.v=i;this.i=0;this.n=void 0;this.t=void 0;this.l=0;this.W=null==t?void 0:t.watched;this.Z=null==t?void 0:t.unwatched;this.name=null==t?void 0:t.name}y.prototype.brand=t;y.prototype.h=function(){return!0};y.prototype.S=function(i){var t=this,n=this.t;if(n!==i&&void 0===i.e){i.x=n;this.t=i;if(void 0!==n)n.e=i;else f(function(){var i;null==(i=t.W)||i.call(t)})}};y.prototype.U=function(i){var t=this;if(void 0!==this.t){var n=i.e,o=i.x;if(void 0!==n){n.x=o;i.e=void 0}if(void 0!==o){o.e=n;i.x=void 0}if(i===this.t){this.t=o;if(void 0===o)f(function(){var i;null==(i=t.Z)||i.call(t)})}}};y.prototype.subscribe=function(i){var t=this;return j(function(){var n=t.value,o=r;r=void 0;try{i(n)}finally{r=o}},{name:"sub"})};y.prototype.valueOf=function(){return this.value};y.prototype.toString=function(){return this.value+""};y.prototype.toJSON=function(){return this.value};y.prototype.peek=function(){var i=r;r=void 0;try{return this.value}finally{r=i}};Object.defineProperty(y.prototype,"value",{get:function(){var i=l(this);if(void 0!==i)i.i=this.i;return this.v},set:function(i){if(i!==this.v){if(e>100)throw new Error("Cycle detected");!function(i){if(0!==v&&0===e)if(i.l!==d){i.l=d;c={S:i,v:i.v,i:i.i,o:c}}}(this);this.v=i;this.i++;a++;v++;try{for(var t=this.t;void 0!==t;t=t.x)t.t.N()}finally{n()}}}});function w(i){for(var t=i.s;void 0!==t;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function p(i){for(var t=i.s;void 0!==t;t=t.n){var n=t.S.n;if(void 0!==n)t.r=n;t.S.n=t;t.i=-1;if(void 0===t.n){i.s=t;break}}}function b(i){var t=i.s,n=void 0;while(void 0!==t){var o=t.p;if(-1===t.i){t.S.U(t);if(void 0!==o)o.n=t.n;if(void 0!==t.n)t.n.p=o}else n=t;t.S.n=t.r;if(void 0!==t.r)t.r=void 0;t=o}i.s=n}function _(i,t){y.call(this,void 0);this.x=i;this.s=void 0;this.g=a-1;this.f=4;this.W=null==t?void 0:t.watched;this.Z=null==t?void 0:t.unwatched;this.name=null==t?void 0:t.name}_.prototype=new y;_.prototype.h=function(){this.f&=-3;if(1&this.f)return!1;if(32==(36&this.f))return!0;this.f&=-5;if(this.g===a)return!0;this.g=a;this.f|=1;if(this.i>0&&!w(this)){this.f&=-2;return!0}var i=r;try{p(this);r=this;var t=this.x();if(16&this.f||this.v!==t||0===this.i){this.v=t;this.f&=-17;this.i++}}catch(i){this.v=i;this.f|=16;this.i++}r=i;b(this);this.f&=-2;return!0};_.prototype.S=function(i){if(void 0===this.t){this.f|=36;for(var t=this.s;void 0!==t;t=t.n)t.S.S(t)}y.prototype.S.call(this,i)};_.prototype.U=function(i){if(void 0!==this.t){y.prototype.U.call(this,i);if(void 0===this.t){this.f&=-33;for(var t=this.s;void 0!==t;t=t.n)t.S.U(t)}}};_.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var i=this.t;void 0!==i;i=i.x)i.t.N()}};Object.defineProperty(_.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var i=l(this);this.h();if(void 0!==i)i.i=this.i;if(16&this.f)throw this.v;return this.v}});function g(i){var t=i.m;i.m=void 0;if("function"==typeof t){v++;var o=r;r=void 0;try{t()}catch(t){i.f&=-2;i.f|=8;x(i);throw t}finally{r=o;n()}}}function x(i){for(var t=i.s;void 0!==t;t=t.n)t.S.U(t);i.x=void 0;i.s=void 0;g(i)}function m(i){if(r!==this)throw new Error("Out-of-order effect");b(this);r=i;this.f&=-2;if(8&this.f)x(this);n()}function S(i,t){this.x=i;this.m=void 0;this.s=void 0;this.u=void 0;this.f=32;this.name=null==t?void 0:t.name;if(h)h.push(this)}S.prototype.c=function(){var i=this.S();try{if(8&this.f)return;if(void 0===this.x)return;var t=this.x();if("function"==typeof t)this.m=t}finally{i()}};S.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1;this.f&=-9;g(this);p(this);v++;var i=r;r=this;return m.bind(this,i)};S.prototype.N=function(){if(!(2&this.f)){this.f|=2;this.u=s;s=this}};S.prototype.d=function(){this.f|=8;if(!(1&this.f))x(this)};S.prototype.dispose=function(){this.d()};function j(i,t){var n=new S(i,t);try{n.c()}catch(i){n.d();throw i}var o=n.d.bind(n);o[Symbol.dispose]=o;return o}function E(i){return function(){var t=arguments,n=this;return o(function(){return f(function(){return i.apply(n,[].slice.call(t))})})}}function T(){var i=h;h=[];return function(){var t=h;if(h&&i)i=i.concat(h);h=i;return t}}var C=function(i){for(var t in i){var n=i[t];if("function"==typeof n)i[t]=E(n);else if("object"==typeof n&&null!==n&&!("brand"in n))C(n)}};i.Computed=_;i.Effect=S;i.Signal=y;i.action=E;i.batch=o;i.computed=function(i,t){return new _(i,t)};i.createModel=function(i){return function(){var t,n,o=T();try{n=i.apply(void 0,[].slice.call(arguments))}catch(i){h=void 0;throw i}finally{t=o()}C(n);n[Symbol.dispose]=E(function(){if(t)for(var i=0;i<t.length;i++)t[i].dispose();t=void 0});return n}};i.effect=j;i.signal=function(i,t){return new y(i,t)};i.untracked=f});//# sourceMappingURL=signals-core.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signals-core.min.js","sources":["../src/index.ts"],"sourcesContent":["// An named symbol/brand for detecting Signal instances even when they weren't\n// created using the same signals library version.\nconst BRAND_SYMBOL = Symbol.for(\"preact-signals\");\n\n// Flags for Computed and Effect.\nconst RUNNING = 1 << 0;\nconst NOTIFIED = 1 << 1;\nconst OUTDATED = 1 << 2;\nconst DISPOSED = 1 << 3;\nconst HAS_ERROR = 1 << 4;\nconst TRACKING = 1 << 5;\n\n// A linked list node used to track dependencies (sources) and dependents (targets).\n// Also used to remember the source's last version number that the target saw.\ntype Node = {\n\t// A source whose value the target depends on.\n\t_source: Signal;\n\t_prevSource?: Node;\n\t_nextSource?: Node;\n\n\t// A target that depends on the source and should be notified when the source changes.\n\t_target: Computed | Effect;\n\t_prevTarget?: Node;\n\t_nextTarget?: Node;\n\n\t// The version number of the source that target has last seen. We use version numbers\n\t// instead of storing the source value, because source values can take arbitrary amount\n\t// of memory, and computeds could hang on to them forever because they're lazily evaluated.\n\t// Use the special value -1 to mark potentially unused but recyclable nodes.\n\t_version: number;\n\n\t// Used to remember & roll back the source's previous `._node` value when entering &\n\t// exiting a new evaluation context.\n\t_rollbackNode?: Node;\n};\n\nfunction startBatch() {\n\tbatchDepth++;\n}\n\nfunction endBatch() {\n\tif (batchDepth > 1) {\n\t\tbatchDepth--;\n\t\treturn;\n\t}\n\n\tlet error: unknown;\n\tlet hasError = false;\n\treconcileBatchSnapshots();\n\n\twhile (batchedEffect !== undefined) {\n\t\tlet effect: Effect | undefined = batchedEffect;\n\t\tbatchedEffect = undefined;\n\n\t\tbatchIteration++;\n\n\t\twhile (effect !== undefined) {\n\t\t\tconst next: Effect | undefined = effect._nextBatchedEffect;\n\t\t\teffect._nextBatchedEffect = undefined;\n\t\t\teffect._flags &= ~NOTIFIED;\n\n\t\t\tif (!(effect._flags & DISPOSED) && needsToRecompute(effect)) {\n\t\t\t\ttry {\n\t\t\t\t\teffect._callback();\n\t\t\t\t} catch (err) {\n\t\t\t\t\tif (!hasError) {\n\t\t\t\t\t\terror = err;\n\t\t\t\t\t\thasError = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\teffect = next;\n\t\t}\n\t}\n\tbatchIteration = 0;\n\tbatchDepth--;\n\n\tif (hasError) {\n\t\tthrow error;\n\t}\n}\n\n/**\n * Combine multiple value updates into one \"commit\" at the end of the provided callback.\n *\n * Batches can be nested and changes are only flushed once the outermost batch callback\n * completes.\n *\n * Accessing a signal that has been modified within a batch will reflect its updated\n * value.\n *\n * @param fn The callback function.\n * @returns The value returned by the callback.\n */\nfunction batch<T>(fn: () => T): T {\n\tif (batchDepth > 0) {\n\t\treturn fn();\n\t}\n\tcurrentBatchSnapshotVersion = ++batchSnapshotVersion;\n\t/*@__INLINE__**/ startBatch();\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tendBatch();\n\t}\n}\n\n// Currently evaluated computed or effect.\nlet evalContext: Computed | Effect | undefined = undefined;\n\n/**\n * Run a callback function that can access signal values without\n * subscribing to the signal updates.\n *\n * @param fn The callback function.\n * @returns The value returned by the callback.\n */\nfunction untracked<T>(fn: () => T): T {\n\tconst prevContext = evalContext;\n\tevalContext = undefined;\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tevalContext = prevContext;\n\t}\n}\n\n// Effects collected into a batch.\nlet batchedEffect: Effect | undefined = undefined;\nlet batchDepth = 0;\nlet batchIteration = 0;\n\ntype BatchSnapshot = {\n\t_source: Signal;\n\t_value: unknown;\n\t_version: number;\n\t_next?: BatchSnapshot;\n};\n\nlet batchSnapshotVersion = 0;\nlet currentBatchSnapshotVersion = 0;\nlet batchSnapshots: BatchSnapshot | undefined = undefined;\n\n// A global version number for signals, used for fast-pathing repeated\n// computed.peek()/computed.value calls when nothing has changed globally.\nlet globalVersion = 0;\n\nfunction recordBatchSnapshot(source: Signal) {\n\t// Only capture writes during the user-visible batch callback, not during effect flush.\n\tif (batchDepth === 0 || batchIteration !== 0) {\n\t\treturn;\n\t}\n\n\tif (source._batchSnapshotVersion !== currentBatchSnapshotVersion) {\n\t\tsource._batchSnapshotVersion = currentBatchSnapshotVersion;\n\t\tbatchSnapshots = {\n\t\t\t_source: source,\n\t\t\t_value: source._value,\n\t\t\t_version: source._version,\n\t\t\t_next: batchSnapshots,\n\t\t};\n\t}\n}\n\nfunction reconcileBatchSnapshots() {\n\tlet snapshots = batchSnapshots;\n\tbatchSnapshots = undefined;\n\n\twhile (snapshots !== undefined) {\n\t\tif (snapshots._source._value === snapshots._value) {\n\t\t\tsnapshots._source._version = snapshots._version;\n\t\t}\n\t\tsnapshots = snapshots._next;\n\t}\n}\n\nfunction addDependency(signal: Signal): Node | undefined {\n\tif (evalContext === undefined) {\n\t\treturn undefined;\n\t}\n\n\tlet node = signal._node;\n\tif (node === undefined || node._target !== evalContext) {\n\t\t/**\n\t\t * `signal` is a new dependency. Create a new dependency node, and set it\n\t\t * as the tail of the current context's dependency list. e.g:\n\t\t *\n\t\t * { A <-> B }\n\t\t * ↑ ↑\n\t\t * tail node (new)\n\t\t * ↓\n\t\t * { A <-> B <-> C }\n\t\t * ↑\n\t\t * tail (evalContext._sources)\n\t\t */\n\t\tnode = {\n\t\t\t_version: 0,\n\t\t\t_source: signal,\n\t\t\t_prevSource: evalContext._sources,\n\t\t\t_nextSource: undefined,\n\t\t\t_target: evalContext,\n\t\t\t_prevTarget: undefined,\n\t\t\t_nextTarget: undefined,\n\t\t\t_rollbackNode: node,\n\t\t};\n\n\t\tif (evalContext._sources !== undefined) {\n\t\t\tevalContext._sources._nextSource = node;\n\t\t}\n\t\tevalContext._sources = node;\n\t\tsignal._node = node;\n\n\t\t// Subscribe to change notifications from this dependency if we're in an effect\n\t\t// OR evaluating a computed signal that in turn has subscribers.\n\t\tif (evalContext._flags & TRACKING) {\n\t\t\tsignal._subscribe(node);\n\t\t}\n\t\treturn node;\n\t} else if (node._version === -1) {\n\t\t// `signal` is an existing dependency from a previous evaluation. Reuse it.\n\t\tnode._version = 0;\n\n\t\t/**\n\t\t * If `node` is not already the current tail of the dependency list (i.e.\n\t\t * there is a next node in the list), then make the `node` the new tail. e.g:\n\t\t *\n\t\t * { A <-> B <-> C <-> D }\n\t\t * ↑ ↑\n\t\t * node ┌─── tail (evalContext._sources)\n\t\t * └─────│─────┐\n\t\t * ↓ ↓\n\t\t * { A <-> C <-> D <-> B }\n\t\t * ↑\n\t\t * tail (evalContext._sources)\n\t\t */\n\t\tif (node._nextSource !== undefined) {\n\t\t\tnode._nextSource._prevSource = node._prevSource;\n\n\t\t\tif (node._prevSource !== undefined) {\n\t\t\t\tnode._prevSource._nextSource = node._nextSource;\n\t\t\t}\n\n\t\t\tnode._prevSource = evalContext._sources;\n\t\t\tnode._nextSource = undefined;\n\n\t\t\tevalContext._sources!._nextSource = node;\n\t\t\tevalContext._sources = node;\n\t\t}\n\n\t\t// We can assume that the currently evaluated effect / computed signal is already\n\t\t// subscribed to change notifications from `signal` if needed.\n\t\treturn node;\n\t}\n\treturn undefined;\n}\n\n//#region Signal\n\n/**\n * The base class for plain and computed signals.\n */\n//\n// A function with the same name is defined later, so we need to ignore TypeScript's\n// warning about a redeclared variable.\n//\n// The class is declared here, but later implemented with ES5-style prototypes.\n// This enables better control of the transpiled output size.\n// @ts-ignore: \"Cannot redeclare exported variable 'Signal'.\"\ndeclare class Signal<T = any> {\n\t/** @internal */\n\t_value: unknown;\n\n\t/**\n\t * @internal\n\t * Version numbers should always be >= 0, because the special value -1 is used\n\t * by Nodes to signify potentially unused but recyclable nodes.\n\t */\n\t_version: number;\n\n\t/** @internal */\n\t_node?: Node;\n\n\t/** @internal */\n\t_targets?: Node;\n\n\t/** @internal */\n\t_batchSnapshotVersion: number;\n\n\tconstructor(value?: T, options?: SignalOptions<T>);\n\n\t/** @internal */\n\t_refresh(): boolean;\n\n\t/** @internal */\n\t_subscribe(node: Node): void;\n\n\t/** @internal */\n\t_unsubscribe(node: Node): void;\n\n\t/** @internal */\n\t_watched?(this: Signal<T>): void;\n\n\t/** @internal */\n\t_unwatched?(this: Signal<T>): void;\n\n\tsubscribe(fn: (value: T) => void): () => void;\n\n\tname?: string;\n\n\tvalueOf(): T;\n\n\ttoString(): string;\n\n\ttoJSON(): T;\n\n\tpeek(): T;\n\n\tbrand: typeof BRAND_SYMBOL;\n\n\tget value(): T;\n\tset value(value: T);\n}\n\nexport interface SignalOptions<T = any> {\n\twatched?: (this: Signal<T>) => void;\n\tunwatched?: (this: Signal<T>) => void;\n\tname?: string;\n}\n\n/** @internal */\n// A class with the same name has already been declared, so we need to ignore\n// TypeScript's warning about a redeclared variable.\n//\n// The previously declared class is implemented here with ES5-style prototypes.\n// This enables better control of the transpiled output size.\n// @ts-ignore: \"Cannot redeclare exported variable 'Signal'.\"\nfunction Signal(this: Signal, value?: unknown, options?: SignalOptions) {\n\tthis._value = value;\n\tthis._version = 0;\n\tthis._node = undefined;\n\tthis._targets = undefined;\n\tthis._batchSnapshotVersion = 0;\n\tthis._watched = options?.watched;\n\tthis._unwatched = options?.unwatched;\n\tthis.name = options?.name;\n}\n\nSignal.prototype.brand = BRAND_SYMBOL;\n\nSignal.prototype._refresh = function () {\n\treturn true;\n};\n\nSignal.prototype._subscribe = function (node) {\n\tconst targets = this._targets;\n\tif (targets !== node && node._prevTarget === undefined) {\n\t\tnode._nextTarget = targets;\n\t\tthis._targets = node;\n\n\t\tif (targets !== undefined) {\n\t\t\ttargets._prevTarget = node;\n\t\t} else {\n\t\t\tuntracked(() => {\n\t\t\t\tthis._watched?.call(this);\n\t\t\t});\n\t\t}\n\t}\n};\n\nSignal.prototype._unsubscribe = function (node) {\n\t// Only run the unsubscribe step if the signal has any subscribers to begin with.\n\tif (this._targets !== undefined) {\n\t\tconst prev = node._prevTarget;\n\t\tconst next = node._nextTarget;\n\t\tif (prev !== undefined) {\n\t\t\tprev._nextTarget = next;\n\t\t\tnode._prevTarget = undefined;\n\t\t}\n\n\t\tif (next !== undefined) {\n\t\t\tnext._prevTarget = prev;\n\t\t\tnode._nextTarget = undefined;\n\t\t}\n\n\t\tif (node === this._targets) {\n\t\t\tthis._targets = next;\n\t\t\tif (next === undefined) {\n\t\t\t\tuntracked(() => {\n\t\t\t\t\tthis._unwatched?.call(this);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n};\n\nSignal.prototype.subscribe = function (fn) {\n\treturn effect(\n\t\t() => {\n\t\t\tconst value = this.value;\n\t\t\tconst prevContext = evalContext;\n\t\t\tevalContext = undefined;\n\t\t\ttry {\n\t\t\t\tfn(value);\n\t\t\t} finally {\n\t\t\t\tevalContext = prevContext;\n\t\t\t}\n\t\t},\n\t\t{ name: \"sub\" }\n\t);\n};\n\nSignal.prototype.valueOf = function () {\n\treturn this.value;\n};\n\nSignal.prototype.toString = function () {\n\treturn this.value + \"\";\n};\n\nSignal.prototype.toJSON = function () {\n\treturn this.value;\n};\n\nSignal.prototype.peek = function () {\n\tconst prevContext = evalContext;\n\tevalContext = undefined;\n\ttry {\n\t\treturn this.value;\n\t} finally {\n\t\tevalContext = prevContext;\n\t}\n};\n\nObject.defineProperty(Signal.prototype, \"value\", {\n\tget(this: Signal) {\n\t\tconst node = addDependency(this);\n\t\tif (node !== undefined) {\n\t\t\tnode._version = this._version;\n\t\t}\n\t\treturn this._value;\n\t},\n\tset(this: Signal, value) {\n\t\tif (value !== this._value) {\n\t\t\tif (batchIteration > 100) {\n\t\t\t\tthrow new Error(\"Cycle detected\");\n\t\t\t}\n\n\t\t\trecordBatchSnapshot(this);\n\t\t\tthis._value = value;\n\t\t\tthis._version++;\n\t\t\tglobalVersion++;\n\n\t\t\t/**@__INLINE__*/ startBatch();\n\t\t\ttry {\n\t\t\t\tfor (\n\t\t\t\t\tlet node = this._targets;\n\t\t\t\t\tnode !== undefined;\n\t\t\t\t\tnode = node._nextTarget\n\t\t\t\t) {\n\t\t\t\t\tnode._target._notify();\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tendBatch();\n\t\t\t}\n\t\t}\n\t},\n});\n\n/**\n * Create a new plain signal.\n *\n * @param value The initial value for the signal.\n * @returns A new signal.\n */\nexport function signal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function signal<T = undefined>(): Signal<T | undefined>;\nexport function signal<T>(value?: T, options?: SignalOptions<T>): Signal<T> {\n\treturn new Signal(value, options);\n}\n\n//#endregion Signal\n\n//#region Computed\n\nfunction needsToRecompute(target: Computed | Effect): boolean {\n\t// Check the dependencies for changed values. The dependency list is already\n\t// in order of use. Therefore if multiple dependencies have changed values, only\n\t// the first used dependency is re-evaluated at this point.\n\tfor (\n\t\tlet node = target._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tif (\n\t\t\t// If the dependency has definitely been updated since its version number\n\t\t\t// was observed, then we need to recompute. This first check is not strictly\n\t\t\t// necessary for correctness, but allows us to skip the refresh call if the\n\t\t\t// dependency has already been updated.\n\t\t\tnode._source._version !== node._version ||\n\t\t\t// Refresh the dependency. If there's something blocking the refresh (e.g. a\n\t\t\t// dependency cycle), then we need to recompute.\n\t\t\t!node._source._refresh() ||\n\t\t\t// If the dependency got a new version after the refresh, then we need to recompute.\n\t\t\tnode._source._version !== node._version\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\t// If none of the dependencies have changed values since last recompute then\n\t// there's no need to recompute.\n\treturn false;\n}\n\nfunction prepareSources(target: Computed | Effect) {\n\t/**\n\t * 1. Mark all current sources as re-usable nodes (version: -1)\n\t * 2. Set a rollback node if the current node is being used in a different context\n\t * 3. Point 'target._sources' to the tail of the doubly-linked list, e.g:\n\t *\n\t * { undefined <- A <-> B <-> C -> undefined }\n\t * ↑ ↑\n\t * │ └──────┐\n\t * target._sources = A; (node is head) │\n\t * ↓ │\n\t * target._sources = C; (node is tail) ─┘\n\t */\n\tfor (\n\t\tlet node = target._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tconst rollbackNode = node._source._node;\n\t\tif (rollbackNode !== undefined) {\n\t\t\tnode._rollbackNode = rollbackNode;\n\t\t}\n\t\tnode._source._node = node;\n\t\tnode._version = -1;\n\n\t\tif (node._nextSource === undefined) {\n\t\t\ttarget._sources = node;\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction cleanupSources(target: Computed | Effect) {\n\tlet node = target._sources;\n\tlet head: Node | undefined = undefined;\n\n\t/**\n\t * At this point 'target._sources' points to the tail of the doubly-linked list.\n\t * It contains all existing sources + new sources in order of use.\n\t * Iterate backwards until we find the head node while dropping old dependencies.\n\t */\n\twhile (node !== undefined) {\n\t\tconst prev = node._prevSource;\n\n\t\t/**\n\t\t * The node was not re-used, unsubscribe from its change notifications and remove itself\n\t\t * from the doubly-linked list. e.g:\n\t\t *\n\t\t * { A <-> B <-> C }\n\t\t * ↓\n\t\t * { A <-> C }\n\t\t */\n\t\tif (node._version === -1) {\n\t\t\tnode._source._unsubscribe(node);\n\n\t\t\tif (prev !== undefined) {\n\t\t\t\tprev._nextSource = node._nextSource;\n\t\t\t}\n\t\t\tif (node._nextSource !== undefined) {\n\t\t\t\tnode._nextSource._prevSource = prev;\n\t\t\t}\n\t\t} else {\n\t\t\t/**\n\t\t\t * The new head is the last node seen which wasn't removed/unsubscribed\n\t\t\t * from the doubly-linked list. e.g:\n\t\t\t *\n\t\t\t * { A <-> B <-> C }\n\t\t\t * ↑ ↑ ↑\n\t\t\t * │ │ └ head = node\n\t\t\t * │ └ head = node\n\t\t\t * └ head = node\n\t\t\t */\n\t\t\thead = node;\n\t\t}\n\n\t\tnode._source._node = node._rollbackNode;\n\t\tif (node._rollbackNode !== undefined) {\n\t\t\tnode._rollbackNode = undefined;\n\t\t}\n\n\t\tnode = prev;\n\t}\n\n\ttarget._sources = head;\n}\n\n/**\n * The base class for computed signals.\n */\ndeclare class Computed<T = any> extends Signal<T> {\n\t_fn: () => T;\n\t_sources?: Node;\n\t_globalVersion: number;\n\t_flags: number;\n\n\tconstructor(fn: () => T, options?: SignalOptions<T>);\n\n\t_notify(): void;\n\tget value(): T;\n}\n\n/** @internal */\nfunction Computed(this: Computed, fn: () => unknown, options?: SignalOptions) {\n\tSignal.call(this, undefined);\n\n\tthis._fn = fn;\n\tthis._sources = undefined;\n\tthis._globalVersion = globalVersion - 1;\n\tthis._flags = OUTDATED;\n\tthis._watched = options?.watched;\n\tthis._unwatched = options?.unwatched;\n\tthis.name = options?.name;\n}\n\nComputed.prototype = new Signal() as Computed;\n\nComputed.prototype._refresh = function () {\n\tthis._flags &= ~NOTIFIED;\n\n\tif (this._flags & RUNNING) {\n\t\treturn false;\n\t}\n\n\t// If this computed signal has subscribed to updates from its dependencies\n\t// (TRACKING flag set) and none of them have notified about changes (OUTDATED\n\t// flag not set), then the computed value can't have changed.\n\tif ((this._flags & (OUTDATED | TRACKING)) === TRACKING) {\n\t\treturn true;\n\t}\n\tthis._flags &= ~OUTDATED;\n\n\tif (this._globalVersion === globalVersion) {\n\t\treturn true;\n\t}\n\tthis._globalVersion = globalVersion;\n\n\t// Mark this computed signal running before checking the dependencies for value\n\t// changes, so that the RUNNING flag can be used to notice cyclical dependencies.\n\tthis._flags |= RUNNING;\n\tif (this._version > 0 && !needsToRecompute(this)) {\n\t\tthis._flags &= ~RUNNING;\n\t\treturn true;\n\t}\n\n\tconst prevContext = evalContext;\n\ttry {\n\t\tprepareSources(this);\n\t\tevalContext = this;\n\t\tconst value = this._fn();\n\t\tif (\n\t\t\tthis._flags & HAS_ERROR ||\n\t\t\tthis._value !== value ||\n\t\t\tthis._version === 0\n\t\t) {\n\t\t\tthis._value = value;\n\t\t\tthis._flags &= ~HAS_ERROR;\n\t\t\tthis._version++;\n\t\t}\n\t} catch (err) {\n\t\tthis._value = err;\n\t\tthis._flags |= HAS_ERROR;\n\t\tthis._version++;\n\t}\n\tevalContext = prevContext;\n\tcleanupSources(this);\n\tthis._flags &= ~RUNNING;\n\treturn true;\n};\n\nComputed.prototype._subscribe = function (node) {\n\tif (this._targets === undefined) {\n\t\tthis._flags |= OUTDATED | TRACKING;\n\n\t\t// A computed signal subscribes lazily to its dependencies when it\n\t\t// gets its first subscriber.\n\t\tfor (\n\t\t\tlet node = this._sources;\n\t\t\tnode !== undefined;\n\t\t\tnode = node._nextSource\n\t\t) {\n\t\t\tnode._source._subscribe(node);\n\t\t}\n\t}\n\tSignal.prototype._subscribe.call(this, node);\n};\n\nComputed.prototype._unsubscribe = function (node) {\n\t// Only run the unsubscribe step if the computed signal has any subscribers.\n\tif (this._targets !== undefined) {\n\t\tSignal.prototype._unsubscribe.call(this, node);\n\n\t\t// Computed signal unsubscribes from its dependencies when it loses its last subscriber.\n\t\t// This makes it possible for unreferences subgraphs of computed signals to get garbage collected.\n\t\tif (this._targets === undefined) {\n\t\t\tthis._flags &= ~TRACKING;\n\n\t\t\tfor (\n\t\t\t\tlet node = this._sources;\n\t\t\t\tnode !== undefined;\n\t\t\t\tnode = node._nextSource\n\t\t\t) {\n\t\t\t\tnode._source._unsubscribe(node);\n\t\t\t}\n\t\t}\n\t}\n};\n\nComputed.prototype._notify = function () {\n\tif (!(this._flags & NOTIFIED)) {\n\t\tthis._flags |= OUTDATED | NOTIFIED;\n\n\t\tfor (\n\t\t\tlet node = this._targets;\n\t\t\tnode !== undefined;\n\t\t\tnode = node._nextTarget\n\t\t) {\n\t\t\tnode._target._notify();\n\t\t}\n\t}\n};\n\nObject.defineProperty(Computed.prototype, \"value\", {\n\tget(this: Computed) {\n\t\tif (this._flags & RUNNING) {\n\t\t\tthrow new Error(\"Cycle detected\");\n\t\t}\n\t\tconst node = addDependency(this);\n\t\tthis._refresh();\n\t\tif (node !== undefined) {\n\t\t\tnode._version = this._version;\n\t\t}\n\t\tif (this._flags & HAS_ERROR) {\n\t\t\tthrow this._value;\n\t\t}\n\t\treturn this._value;\n\t},\n});\n\n/**\n * An interface for read-only signals.\n */\ninterface ReadonlySignal<T = any> {\n\treadonly value: T;\n\tpeek(): T;\n\n\tsubscribe(fn: (value: T) => void): () => void;\n\tvalueOf(): T;\n\ttoString(): string;\n\ttoJSON(): T;\n\tbrand: typeof BRAND_SYMBOL;\n}\n\n/**\n * Create a new signal that is computed based on the values of other signals.\n *\n * The returned computed signal is read-only, and its value is automatically\n * updated when any signals accessed from within the callback function change.\n *\n * @param fn The effect callback.\n * @returns A new read-only signal.\n */\nfunction computed<T>(\n\tfn: () => T,\n\toptions?: SignalOptions<T>\n): ReadonlySignal<T> {\n\treturn new Computed(fn, options);\n}\n\n//#endregion Computed\n\n//#region Effect\n\nfunction cleanupEffect(effect: Effect) {\n\tconst cleanup = effect._cleanup;\n\teffect._cleanup = undefined;\n\n\tif (typeof cleanup === \"function\") {\n\t\t/*@__INLINE__**/ startBatch();\n\n\t\t// Run cleanup functions always outside of any context.\n\t\tconst prevContext = evalContext;\n\t\tevalContext = undefined;\n\t\ttry {\n\t\t\tcleanup();\n\t\t} catch (err) {\n\t\t\teffect._flags &= ~RUNNING;\n\t\t\teffect._flags |= DISPOSED;\n\t\t\tdisposeEffect(effect);\n\t\t\tthrow err;\n\t\t} finally {\n\t\t\tevalContext = prevContext;\n\t\t\tendBatch();\n\t\t}\n\t}\n}\n\nfunction disposeEffect(effect: Effect) {\n\tfor (\n\t\tlet node = effect._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tnode._source._unsubscribe(node);\n\t}\n\teffect._fn = undefined;\n\teffect._sources = undefined;\n\n\tcleanupEffect(effect);\n}\n\nfunction endEffect(this: Effect, prevContext?: Computed | Effect) {\n\tif (evalContext !== this) {\n\t\tthrow new Error(\"Out-of-order effect\");\n\t}\n\tcleanupSources(this);\n\tevalContext = prevContext;\n\n\tthis._flags &= ~RUNNING;\n\tif (this._flags & DISPOSED) {\n\t\tdisposeEffect(this);\n\t}\n\tendBatch();\n}\n\ntype EffectFn =\n\t| ((this: { dispose: () => void }) => void | (() => void))\n\t| (() => void | (() => void));\n\n// Avoid hard-requiring the ESNext.Disposable lib in consuming tsconfigs.\n// When `Symbol.dispose` is available, this becomes a symbol-keyed disposer type.\ntype DisposeSymbol = typeof Symbol extends { readonly dispose: infer TDispose }\n\t? TDispose\n\t: never;\ntype DisposableLike = {\n\t[K in DisposeSymbol & PropertyKey]: () => void;\n};\ntype DisposeFn = (() => void) & DisposableLike;\n\n/**\n * The base class for reactive effects.\n */\ndeclare class Effect {\n\t_fn?: EffectFn;\n\t_cleanup?: () => void;\n\t_sources?: Node;\n\t_nextBatchedEffect?: Effect;\n\t_flags: number;\n\t_debugCallback?: () => void;\n\tname?: string;\n\n\tconstructor(fn: EffectFn, options?: EffectOptions);\n\n\t_callback(): void;\n\t_start(): () => void;\n\t_notify(): void;\n\t_dispose(): void;\n\tdispose(): void;\n}\n\nexport interface EffectOptions {\n\tname?: string;\n}\n\nlet capturedEffects: Effect[] | undefined;\n\n/** @internal */\nfunction Effect(this: Effect, fn: EffectFn, options?: EffectOptions) {\n\tthis._fn = fn;\n\tthis._cleanup = undefined;\n\tthis._sources = undefined;\n\tthis._nextBatchedEffect = undefined;\n\tthis._flags = TRACKING;\n\tthis.name = options?.name;\n\n\tif (capturedEffects) {\n\t\tcapturedEffects.push(this);\n\t}\n}\n\nEffect.prototype._callback = function () {\n\tconst finish = this._start();\n\ttry {\n\t\tif (this._flags & DISPOSED) return;\n\t\tif (this._fn === undefined) return;\n\n\t\tconst cleanup = this._fn();\n\t\tif (typeof cleanup === \"function\") {\n\t\t\tthis._cleanup = cleanup;\n\t\t}\n\t} finally {\n\t\tfinish();\n\t}\n};\n\nEffect.prototype._start = function () {\n\tif (this._flags & RUNNING) {\n\t\tthrow new Error(\"Cycle detected\");\n\t}\n\tthis._flags |= RUNNING;\n\tthis._flags &= ~DISPOSED;\n\tcleanupEffect(this);\n\tprepareSources(this);\n\n\t/*@__INLINE__**/ startBatch();\n\tconst prevContext = evalContext;\n\tevalContext = this;\n\treturn endEffect.bind(this, prevContext);\n};\n\nEffect.prototype._notify = function () {\n\tif (!(this._flags & NOTIFIED)) {\n\t\tthis._flags |= NOTIFIED;\n\t\tthis._nextBatchedEffect = batchedEffect;\n\t\tbatchedEffect = this;\n\t}\n};\n\nEffect.prototype._dispose = function () {\n\tthis._flags |= DISPOSED;\n\n\tif (!(this._flags & RUNNING)) {\n\t\tdisposeEffect(this);\n\t}\n};\n\nEffect.prototype.dispose = function () {\n\tthis._dispose();\n};\n/**\n * Create an effect to run arbitrary code in response to signal changes.\n *\n * An effect tracks which signals are accessed within the given callback\n * function `fn`, and re-runs the callback when those signals change.\n *\n * The callback may return a cleanup function. The cleanup function gets\n * run once, either when the callback is next called or when the effect\n * gets disposed, whichever happens first.\n *\n * @param fn The effect callback.\n * @returns A function for disposing the effect.\n */\nfunction effect(fn: EffectFn, options?: EffectOptions): DisposeFn {\n\tconst effect = new Effect(fn, options);\n\ttry {\n\t\teffect._callback();\n\t} catch (err) {\n\t\teffect._dispose();\n\t\tthrow err;\n\t}\n\t// Return a bound function instead of a wrapper like `() => effect._dispose()`,\n\t// because bound functions seem to be just as fast and take up a lot less memory.\n\tconst dispose = effect._dispose.bind(effect);\n\t(dispose as any)[Symbol.dispose] = dispose;\n\treturn dispose as DisposeFn;\n}\n\n//#endregion Effect\n\n//#region Action\n\nfunction action<TArgs extends unknown[], TReturn>(\n\tfn: (...args: TArgs) => TReturn\n): (...args: TArgs) => TReturn {\n\treturn function actionWrapper(this: unknown, ...args: TArgs) {\n\t\treturn batch(() => untracked(() => fn.apply(this, args)));\n\t};\n}\n\n//#endregion Action\n\n//#region createModel\n\n/** Models should only contain signals, actions, and nested objects containing only signals and actions. */\ntype ValidateModel<TModel> = {\n\t[Key in keyof TModel]: TModel[Key] extends ReadonlySignal<unknown>\n\t\t? TModel[Key]\n\t\t: TModel[Key] extends (...args: any[]) => any\n\t\t\t? TModel[Key]\n\t\t\t: TModel[Key] extends object\n\t\t\t\t? ValidateModel<TModel[Key]>\n\t\t\t\t: `Property ${Key extends string ? `'${Key}' ` : \"\"}is not a Signal, Action, or an object that contains only Signals and Actions.`;\n};\n\nexport type Model<TModel> = ValidateModel<TModel> & DisposableLike;\n\nexport type ModelFactory<TModel, TFactoryArgs extends any[] = []> = (\n\t...args: TFactoryArgs\n) => ValidateModel<TModel>;\nexport type ModelConstructor<TModel, TFactoryArgs extends any[] = []> = new (\n\t...args: TFactoryArgs\n) => Model<TModel>;\n\n/**\n * The public types for ModelConstructor require using `new` to help\n * disambiguate the function passed into `createModel` and the returned\n * constructor function. It is easier to say that `createModel` accepts\n * a factory and returns a class, then to say it accepts a factory and\n * returns a factory. In other words, this example:\n *\n * ```ts\n * const PersonModel = createModel((name: string) => ({ ... }));\n * const person = new PersonModel(\"John\");\n * ```\n *\n * is easier to understand than this example:\n *\n * ```ts\n * const createPerson = createModel((name: string) => ({ ... }));\n * const person = createPerson(\"John\");\n * ```\n *\n * However, internally we implement `createModel` to return a function\n * that can be called without `new` for simplicity. To bridge the gap\n * between the public types and the internal implementation, we define\n * this internal interface that extends the public interface but also\n * allows calling without `new`.\n *\n * This pattern is used by the Preact & React adapters to make instantiating\n * a model or a function that returns a model easier.\n *\n * @internal\n */\ninterface InternalModelConstructor<\n\tTModel,\n\tTFactoryArgs extends any[],\n> extends ModelConstructor<TModel, TFactoryArgs> {\n\t(...args: TFactoryArgs): Model<TModel>;\n}\n\nfunction startCapturingEffects(): () => Effect[] | undefined {\n\tlet prevCapturedEffects = capturedEffects;\n\tcapturedEffects = [];\n\n\treturn function stopCapturingEffects() {\n\t\tlet modelEffects = capturedEffects;\n\t\tif (capturedEffects && prevCapturedEffects) {\n\t\t\tprevCapturedEffects = prevCapturedEffects.concat(capturedEffects);\n\t\t}\n\n\t\tcapturedEffects = prevCapturedEffects;\n\n\t\treturn modelEffects;\n\t};\n}\n\nconst wrapInAction = (value: Record<string, unknown>) => {\n\tfor (const key in value) {\n\t\tconst val = value[key];\n\t\tif (typeof val === \"function\") {\n\t\t\tvalue[key] = action(val as (...args: unknown[]) => unknown);\n\t\t} else if (typeof val === \"object\" && val !== null && !(\"brand\" in val)) {\n\t\t\t// Recursively wrap nested object properties in actions. This allows users to write\n\t\t\t// nested models without worrying about wrapping their functions in `action`.\n\t\t\twrapInAction(val as Record<string, unknown>);\n\t\t}\n\t}\n};\n\nfunction createModel<TModel, TFactoryArgs extends any[] = []>(\n\tmodelFactory: ModelFactory<TModel, TFactoryArgs>\n): ModelConstructor<TModel, TFactoryArgs> {\n\treturn function SignalModel(...args: TFactoryArgs): Model<TModel> {\n\t\tlet modelEffects: Effect[] | undefined;\n\t\tlet model: Model<TModel>;\n\n\t\tconst stopCapturingEffects = startCapturingEffects();\n\t\ttry {\n\t\t\tmodel = modelFactory(...args) as Model<TModel>;\n\t\t} catch (err) {\n\t\t\t// Drop any captured effects on error. Errors from nested models will bubble\n\t\t\t// up here and recursively reset `capturedEffects` to `undefined` preventing\n\t\t\t// any captured effects from leaking\n\t\t\tcapturedEffects = undefined;\n\t\t\tthrow err;\n\t\t} finally {\n\t\t\tmodelEffects = stopCapturingEffects();\n\t\t}\n\n\t\twrapInAction(model);\n\n\t\tmodel[Symbol.dispose] = action(function disposeModel() {\n\t\t\tif (modelEffects) {\n\t\t\t\tfor (let i = 0; i < modelEffects.length; i++) {\n\t\t\t\t\tmodelEffects[i].dispose();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tmodelEffects = undefined;\n\t\t});\n\n\t\treturn model;\n\t} as InternalModelConstructor<TModel, TFactoryArgs>;\n}\n\n//#endregion createModel\n\nexport {\n\tcomputed,\n\teffect,\n\tbatch,\n\tuntracked,\n\taction,\n\tcreateModel,\n\tSignal,\n\tReadonlySignal,\n\tEffect,\n\tComputed,\n};\n"],"names":["g","f","exports","module","define","amd","globalThis","self","preactSignalsCore","this","BRAND_SYMBOL","Symbol","endBatch","batchDepth","error","hasError","snapshots","batchSnapshots","undefined","_source","_value","_version","_next","reconcileBatchSnapshots","batchedEffect","effect","batchIteration","next","_nextBatchedEffect","_flags","needsToRecompute","_callback","err","batch","fn","currentBatchSnapshotVersion","batchSnapshotVersion","evalContext","untracked","prevContext","capturedEffects","globalVersion","addDependency","signal","node","_node","_target","_prevSource","_sources","_nextSource","_prevTarget","_nextTarget","_rollbackNode","_subscribe","Signal","value","options","_targets","_batchSnapshotVersion","_watched","watched","_unwatched","unwatched","name","prototype","brand","_refresh","_this","targets","_this$_watched","call","_unsubscribe","_this2","prev","_this2$_unwatched","subscribe","_this3","valueOf","toString","toJSON","peek","Object","defineProperty","get","set","Error","source","recordBatchSnapshot","_notify","target","prepareSources","rollbackNode","cleanupSources","head","Computed","_fn","_globalVersion","OUTDATED","cleanupEffect","cleanup","_cleanup","disposeEffect","endEffect","Effect","push","finish","_start","bind","_dispose","dispose","action","_arguments","arguments","_this4","apply","slice","startCapturingEffects","prevCapturedEffects","modelEffects","concat","wrapInAction","key","val","computed","createModel","modelFactory","model","stopCapturingEffects","i","length"],"mappings":"CAEA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,kBAAA,CAAA,EAAA,CAAA,CAAAC,KAAA,SAAAP,GAAA,IAAMQ,EAAeC,OAAU,IAAC,kBAsChC,SAASC,IACR,KA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