@manyducks.co/dolla 0.69.1 → 0.69.3

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/lib/state.d.ts CHANGED
@@ -4,11 +4,12 @@ declare const OBSERVE: unique symbol;
4
4
  */
5
5
  export type StopFunction = () => void;
6
6
  type ObserveMethod<T> = (callback: (currentValue: T) => void) => StopFunction;
7
+ type Value<T> = T extends Readable<infer V> ? V : T;
7
8
  /**
8
9
  * Extracts value types from an array of Readables.
9
10
  */
10
- export type ReadableValues<T extends Readable<any>[]> = {
11
- [K in keyof T]: T[K] extends Readable<infer U> ? U : never;
11
+ export type ReadableValues<T extends MaybeReadable<any>[]> = {
12
+ [K in keyof T]: Value<T[K]>;
12
13
  };
13
14
  export interface Observable<T> {
14
15
  /**
@@ -34,7 +35,6 @@ export interface Writable<T> extends Readable<T> {
34
35
  update(callback: (currentValue: T) => T): void;
35
36
  }
36
37
  export type MaybeReadable<T> = Readable<T> | T;
37
- type Value<T> = T extends Readable<infer V> ? V : T;
38
38
  export declare function isReadable<T>(value: any): value is Readable<T>;
39
39
  export declare function isWritable<T>(value: any): value is Writable<T>;
40
40
  export declare function $$<T>(value: Writable<T>): Writable<T>;
package/notes/views.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ```js
2
- import { View, Store, State } from "@manyducks.co/dolla";
2
+ import { View, Store, $, $$ } from "@manyducks.co/dolla";
3
3
 
4
4
  const SomeView = View("SomeView")
5
5
  .props((t) => ({
@@ -13,16 +13,10 @@ const SomeView = View("SomeView")
13
13
  });
14
14
 
15
15
  const SomeStore = Store("SomeStore").build((ctx) => {
16
- const $$value = State(0);
16
+ const $$value = $$(0);
17
17
 
18
18
  return {
19
- $value: $$value.readable(),
19
+ $value: $($$value),
20
20
  };
21
21
  });
22
-
23
- // Stores can be configured in an app like so:
24
-
25
- const app = App();
26
-
27
- app.addStore(SomeStore.configure(options));
28
22
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manyducks.co/dolla",
3
- "version": "0.69.1",
3
+ "version": "0.69.3",
4
4
  "description": "Front-end components, routing and state management.",
5
5
  "main": "lib/index.js",
6
6
  "types": "./index.d.ts",
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.