@manyducks.co/dolla 0.69.2 → 0.69.4
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 +64 -50
- package/lib/classes/EventEmitter.d.ts +44 -0
- package/lib/index.js +274 -272
- package/lib/index.js.map +4 -4
- package/lib/nodes/text.d.ts +1 -1
- package/lib/routing.d.ts +79 -0
- package/lib/routing.test.d.ts +1 -0
- package/lib/state.d.ts +1 -1
- package/lib/store.d.ts +1 -1
- package/lib/typeChecking.d.ts +191 -0
- package/lib/types.d.ts +1 -1
- package/notes/views.md +3 -9
- package/package.json +8 -9
- package/tests/state.test.js +52 -52
- package/notes/state.md +0 -71
package/notes/state.md
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# State
|
|
2
|
-
|
|
3
|
-
I want to update the state API to be a single constructor object, similar to built-ins like `Math` and `Array`. The current API has a lot of separate functions that work together in various ways, but I feel it would be easier to explain and understand if these functions were under one namespace.
|
|
4
|
-
|
|
5
|
-
Current API:
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { readable, writable, computed, unwrap, proxy, type Readable, type Writable } from "@manyducks.co/dolla";
|
|
9
|
-
|
|
10
|
-
const $$writable = writable({ someValue: 5, otherValue: "test" });
|
|
11
|
-
const $readable = readable($$writable);
|
|
12
|
-
const $computed = computed($$writable, (value) => value.someValue * 256);
|
|
13
|
-
const unwrapped = unwrap($computed);
|
|
14
|
-
const $$proxy = proxy($$writable, {
|
|
15
|
-
get(source) {
|
|
16
|
-
return source.get().someValue;
|
|
17
|
-
},
|
|
18
|
-
set(source, value) {
|
|
19
|
-
source.update((current) => {
|
|
20
|
-
return { ...current, someValue: value };
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
const $multiComputed = computed([$one, $$two, $three], ([one, two, three], [oldOne, oldTwo, oldThree]) => {
|
|
25
|
-
return one + two + three;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
$$writable.get();
|
|
29
|
-
$$writable.set({ someValue: 12, otherValue: null });
|
|
30
|
-
$$writable.update((current) => ({ ...current, someValue: 100 }));
|
|
31
|
-
|
|
32
|
-
$readable.get();
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
The main problem with the above is that we have two things (readable and writable) and a bunch of disconnected utility functions.
|
|
36
|
-
|
|
37
|
-
Proposed API:
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
import { State, type Readable, type Writable } from "@manyducks.co/dolla";
|
|
41
|
-
|
|
42
|
-
const $$writable = State.writable({ someValue: 5, otherValue: "test" }); // Longhand
|
|
43
|
-
const $$writable = State({ someValue: 5, otherValue: "test" }); // Shorthand
|
|
44
|
-
const $readable = State.readable($$writable);
|
|
45
|
-
const $readable = $$writable.readable(); // Directly from a writable
|
|
46
|
-
const $computed = State.from($$writable, (value) => value.someValue * 256);
|
|
47
|
-
const unwrapped = State.unwrap($computed);
|
|
48
|
-
const $$proxy = State.proxy($$writable, {
|
|
49
|
-
get(current) {
|
|
50
|
-
return current.someValue;
|
|
51
|
-
},
|
|
52
|
-
set(value, update) {
|
|
53
|
-
update((current) => {
|
|
54
|
-
return { ...current, someValue: value };
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
const $multiComputed = State.from($one, $$two, $three, (one, two, three, ctx) => {
|
|
59
|
-
// ctx.lastValues = [oldOne, oldTwo, oldThree];
|
|
60
|
-
// ctx.lastReturned = oldOne + oldTwo + oldThree
|
|
61
|
-
return one + two + three;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
$$writable.get();
|
|
65
|
-
$$writable.set({ someValue: 12, otherValue: null });
|
|
66
|
-
$$writable.update((current) => ({ ...current, someValue: 100 }));
|
|
67
|
-
|
|
68
|
-
$readable.get();
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Now we have one state primitive (`State`), all instances of which implement `Readable` and some of which implement `Writable`. All utility functions are under the same namespace. This also avoids conflicts with Node streams' Readable and Writable which can be an issue with automatic imports.
|