@rlabs-inc/signals 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ A complete standalone mirror of Svelte 5's reactivity system. No compiler needed
|
|
|
8
8
|
|
|
9
9
|
- **True Fine-Grained Reactivity** - Changes to deeply nested properties only trigger effects that read that exact path
|
|
10
10
|
- **Per-Property Tracking** - Proxy-based deep reactivity with lazy signal creation per property
|
|
11
|
+
- **Reactive Bindings** - Two-way data binding with `bind()` for connecting reactive values
|
|
11
12
|
- **Three-State Dirty Tracking** - Efficient CLEAN/MAYBE_DIRTY/DIRTY propagation
|
|
12
13
|
- **Automatic Cleanup** - Effects clean up when disposed, no memory leaks
|
|
13
14
|
- **Batching** - Group updates to prevent redundant effect runs
|
|
@@ -94,6 +95,76 @@ Deriveds are:
|
|
|
94
95
|
- **Cached** - Value is memoized until dependencies change
|
|
95
96
|
- **Pure** - Cannot write to signals inside (throws error)
|
|
96
97
|
|
|
98
|
+
### Bindings
|
|
99
|
+
|
|
100
|
+
#### `bind<T>(source: WritableSignal<T>): Binding<T>`
|
|
101
|
+
|
|
102
|
+
Create a reactive binding that forwards reads and writes to a source signal. Useful for two-way data binding and connecting reactive values across components.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const source = signal(0)
|
|
106
|
+
const binding = bind(source)
|
|
107
|
+
|
|
108
|
+
// Reading through binding reads from source
|
|
109
|
+
console.log(binding.value) // 0
|
|
110
|
+
|
|
111
|
+
// Writing through binding writes to source
|
|
112
|
+
binding.value = 42
|
|
113
|
+
console.log(source.value) // 42
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Use cases:**
|
|
117
|
+
- Two-way binding for form inputs
|
|
118
|
+
- Connecting parent state to child components
|
|
119
|
+
- Creating reactive links between signals
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// Two-way binding example
|
|
123
|
+
const username = signal('')
|
|
124
|
+
const inputBinding = bind(username)
|
|
125
|
+
|
|
126
|
+
// When user types (e.g., in a UI framework):
|
|
127
|
+
inputBinding.value = 'alice' // Updates username signal!
|
|
128
|
+
|
|
129
|
+
// When username changes programmatically:
|
|
130
|
+
username.value = 'bob' // inputBinding.value is now 'bob'
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### `bindReadonly<T>(source: ReadableSignal<T>): ReadonlyBinding<T>`
|
|
134
|
+
|
|
135
|
+
Create a read-only binding. Attempting to write throws an error.
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
const source = signal(0)
|
|
139
|
+
const readonly = bindReadonly(source)
|
|
140
|
+
|
|
141
|
+
console.log(readonly.value) // 0
|
|
142
|
+
// readonly.value = 42 // Would throw at compile time
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### `isBinding(value): boolean`
|
|
146
|
+
|
|
147
|
+
Check if a value is a binding.
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
const binding = bind(signal(0))
|
|
151
|
+
console.log(isBinding(binding)) // true
|
|
152
|
+
console.log(isBinding(signal(0))) // false
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### `unwrap<T>(value: T | Binding<T>): T`
|
|
156
|
+
|
|
157
|
+
Get the value from a binding, or return the value directly if not a binding.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const arr: (string | Binding<string>)[] = [
|
|
161
|
+
'static',
|
|
162
|
+
bind(signal('dynamic'))
|
|
163
|
+
]
|
|
164
|
+
|
|
165
|
+
arr.map(unwrap) // ['static', 'dynamic']
|
|
166
|
+
```
|
|
167
|
+
|
|
97
168
|
### Effects
|
|
98
169
|
|
|
99
170
|
#### `effect(fn: () => void | CleanupFn): DisposeFn`
|
|
@@ -367,6 +438,7 @@ This library is designed for performance:
|
|
|
367
438
|
| DOM integration | Yes | No |
|
|
368
439
|
| Fine-grained reactivity | Yes | Yes |
|
|
369
440
|
| Deep proxy reactivity | Yes | Yes |
|
|
441
|
+
| Reactive bindings | `bind:` directive | `bind()` function |
|
|
370
442
|
| Batching | Yes | Yes |
|
|
371
443
|
| Effect cleanup | Yes | Yes |
|
|
372
444
|
| TypeScript | Yes | Yes |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rlabs-inc/signals",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Production-grade fine-grained reactivity for TypeScript. A complete standalone mirror of Svelte 5's reactivity system - signals, effects, derived values, deep reactivity, reactive collections, and reactive bindings.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -37,6 +37,9 @@
|
|
|
37
37
|
"derived",
|
|
38
38
|
"computed",
|
|
39
39
|
"observable",
|
|
40
|
+
"bind",
|
|
41
|
+
"binding",
|
|
42
|
+
"two-way-binding",
|
|
40
43
|
"svelte",
|
|
41
44
|
"typescript"
|
|
42
45
|
],
|