@manyducks.co/dolla 2.0.0-alpha.14 → 2.0.0-alpha.16
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 +20 -15
- package/dist/index.d.ts +4 -4
- package/dist/index.js +368 -345
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-runtime.js +2 -2
- package/dist/markup.d.ts +1 -9
- package/dist/modules/dolla.d.ts +15 -3
- package/dist/nodes/html.d.ts +3 -2
- package/dist/passthrough-DUh0_zQF.js +1398 -0
- package/dist/passthrough-DUh0_zQF.js.map +1 -0
- package/dist/state.d.ts +49 -12
- package/dist/types.d.ts +2 -2
- package/dist/view.d.ts +2 -2
- package/package.json +2 -1
- package/dist/passthrough-MfPKbG0F.js +0 -1303
- package/dist/passthrough-MfPKbG0F.js.map +0 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Let's first get into some examples.
|
|
|
21
21
|
### Basic State API
|
|
22
22
|
|
|
23
23
|
```jsx
|
|
24
|
-
import { createState, toState, valueOf, derive } from "@manyducks.co/dolla";
|
|
24
|
+
import { createState, toState, valueOf, derive, createWatcher } from "@manyducks.co/dolla";
|
|
25
25
|
|
|
26
26
|
const [$count, setCount] = createState(72);
|
|
27
27
|
|
|
@@ -36,11 +36,9 @@ $count.get(); // 300
|
|
|
36
36
|
setCount((current) => current + 1);
|
|
37
37
|
$count.get(); // 301
|
|
38
38
|
|
|
39
|
-
//
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
unwatch(); // Stop watching for changes
|
|
39
|
+
// Derive a new state from one or more other states. Whenever $count changes, $doubled will follow.
|
|
40
|
+
const $doubled = derive([$count], (count) => count * 2);
|
|
41
|
+
const $sum = derive([$count, $doubled], (count, doubled) => count + doubled);
|
|
44
42
|
|
|
45
43
|
// Returns the value of a state. If the value is not a state it is returned as is.
|
|
46
44
|
const count = valueOf($count);
|
|
@@ -50,9 +48,14 @@ const bool = valueOf(true);
|
|
|
50
48
|
const $bool = toState(true);
|
|
51
49
|
const $anotherCount = toState($count);
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
const watcher = createWatcher();
|
|
52
|
+
|
|
53
|
+
// Watch for changes to the value
|
|
54
|
+
const stop = watcher.watch([$count], (value) => [
|
|
55
|
+
// This function is called immediately with the current value, then again each time the value changes.
|
|
56
|
+
]);
|
|
57
|
+
stop(); // Stop watching for changes
|
|
58
|
+
|
|
56
59
|
```
|
|
57
60
|
|
|
58
61
|
States also come in a settable variety that includes the setter on the same object. Sometimes you want to pass around a two-way binding and this is what SettableState is for.
|
|
@@ -60,9 +63,11 @@ States also come in a settable variety that includes the setter on the same obje
|
|
|
60
63
|
```jsx
|
|
61
64
|
import { createSettableState, fromSettable, toSettable } from "@manyducks.co/dolla";
|
|
62
65
|
|
|
63
|
-
// Settable states
|
|
66
|
+
// Settable states can be set by passing a value when they are called.
|
|
64
67
|
const $$value = createSettableState("Test");
|
|
65
|
-
$$value
|
|
68
|
+
$$value(); // "Test"
|
|
69
|
+
$$value("New Value");
|
|
70
|
+
$$value(); // "New Value"
|
|
66
71
|
|
|
67
72
|
// They can also be split into a State and Setter
|
|
68
73
|
const [$value, setValue] = fromSettableState($$value);
|
|
@@ -92,12 +97,12 @@ const setDoubled = createSetter($doubled, (next, current) => {
|
|
|
92
97
|
const $$doubled = toSettableState($doubled, setDoubled);
|
|
93
98
|
|
|
94
99
|
// Setting the doubled state...
|
|
95
|
-
$$doubled
|
|
100
|
+
$$doubled(100);
|
|
96
101
|
|
|
97
102
|
// ... will be reflected everywhere.
|
|
98
|
-
$$doubled
|
|
99
|
-
$doubled
|
|
100
|
-
$value
|
|
103
|
+
$$doubled(); // 100
|
|
104
|
+
$doubled(); // 100
|
|
105
|
+
$value(); // 50
|
|
101
106
|
```
|
|
102
107
|
|
|
103
108
|
## Views [id="section-views"]
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { createSettableState, createSetter, createState, derive, toSettableState, toState, valueOf } from "./state.js";
|
|
2
|
-
export type { MaybeState, SettableState, State, StopFunction } from "./state.js";
|
|
3
|
-
export { cond, createMarkup,
|
|
4
|
-
export type { Markup, MarkupElement
|
|
1
|
+
export { createRef, createSettableState, createSetter, createState, derive, isRef, toSettableState, toState, valueOf, } from "./state.js";
|
|
2
|
+
export type { MaybeState, Ref, SettableState, State, StopFunction } from "./state.js";
|
|
3
|
+
export { cond, createMarkup, html, portal, repeat } from "./markup.js";
|
|
4
|
+
export type { Markup, MarkupElement } from "./markup.js";
|
|
5
5
|
import { Dolla } from "./modules/dolla.js";
|
|
6
6
|
declare const dolla: Dolla;
|
|
7
7
|
export default dolla;
|