@manyducks.co/dolla 2.0.0-alpha.14 → 2.0.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -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
- // Watch for changes to the value
40
- const unwatch = $count.watch((value) => {
41
- // This function is called immediately with the current value, then again each time the value changes.
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
- // Derive a new state from one or more other states. Whenever $count changes, $doubled will follow.
54
- const $doubled = derive([$count], (count) => count * 2);
55
- const $sum = derive([$count, $doubled], (count, doubled) => count + doubled);
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 have their setter included.
66
+ // Settable states can be set by passing a value when they are called.
64
67
  const $$value = createSettableState("Test");
65
- $$value.set("New 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.set(100);
100
+ $$doubled(100);
96
101
 
97
102
  // ... will be reflected everywhere.
98
- $$doubled.get(); // 100
99
- $doubled.get(); // 100
100
- $value.get(); // 50
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, createRef, html, isRef, portal, repeat } from "./markup.js";
4
- export type { Markup, MarkupElement, Ref } from "./markup.js";
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;