@oscarpalmer/mora 0.12.0 → 0.13.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/types/batch.d.cts CHANGED
@@ -14,6 +14,15 @@ declare class Computed<Value> extends Reactive<Value> {
14
14
  */
15
15
  get(): Value;
16
16
  }
17
+ declare class Subscription<Value> {
18
+ state: ReactiveState<Value>;
19
+ callback: GenericCallback;
20
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
21
+ }
22
+ /**
23
+ * Unsubscribe from changes
24
+ */
25
+ export type Unsubscribe = () => void;
17
26
  declare abstract class Reactive<Value> {
18
27
  protected readonly state: ReactiveState<Value>;
19
28
  constructor(name: string, value: Value);
@@ -29,6 +38,14 @@ declare abstract class Reactive<Value> {
29
38
  * Subscribe to changes
30
39
  */
31
40
  subscribe(callback: (value: Value) => void): Unsubscribe;
41
+ /**
42
+ * JSON representation of the value
43
+ */
44
+ toJSON(): Value;
45
+ /**
46
+ * String representation of the value
47
+ */
48
+ toString(): string;
32
49
  /**
33
50
  * Unsubscribe from changes
34
51
  */
@@ -40,15 +57,6 @@ export type ReactiveState<Value> = {
40
57
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
41
58
  value: Value;
42
59
  };
43
- declare class Subscription<Value> {
44
- state: ReactiveState<Value>;
45
- callback: GenericCallback;
46
- constructor(state: ReactiveState<Value>, callback: GenericCallback);
47
- }
48
- /**
49
- * Unsubscribe from changes
50
- */
51
- export type Unsubscribe = () => void;
52
60
  export declare function flushEffects(): void;
53
61
  /**
54
62
  * Start batching effects _(use `stopBatch` to flush and run batched effects)_
@@ -27,6 +27,15 @@ export declare class Computed<Value> extends Reactive<Value> {
27
27
  * Create a computed value
28
28
  */
29
29
  export declare function computed<Value>(callback: () => Value): Computed<Value>;
30
+ declare class Subscription<Value> {
31
+ state: ReactiveState<Value>;
32
+ callback: GenericCallback;
33
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
34
+ }
35
+ /**
36
+ * Unsubscribe from changes
37
+ */
38
+ export type Unsubscribe = () => void;
30
39
  declare abstract class Reactive<Value> {
31
40
  protected readonly state: ReactiveState<Value>;
32
41
  constructor(name: string, value: Value);
@@ -42,6 +51,14 @@ declare abstract class Reactive<Value> {
42
51
  * Subscribe to changes
43
52
  */
44
53
  subscribe(callback: (value: Value) => void): Unsubscribe;
54
+ /**
55
+ * JSON representation of the value
56
+ */
57
+ toJSON(): Value;
58
+ /**
59
+ * String representation of the value
60
+ */
61
+ toString(): string;
45
62
  /**
46
63
  * Unsubscribe from changes
47
64
  */
@@ -53,14 +70,5 @@ export type ReactiveState<Value> = {
53
70
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
54
71
  value: Value;
55
72
  };
56
- declare class Subscription<Value> {
57
- state: ReactiveState<Value>;
58
- callback: GenericCallback;
59
- constructor(state: ReactiveState<Value>, callback: GenericCallback);
60
- }
61
- /**
62
- * Unsubscribe from changes
63
- */
64
- export type Unsubscribe = () => void;
65
73
 
66
74
  export {};
package/types/index.d.cts CHANGED
@@ -22,6 +22,15 @@ export declare class Computed<Value> extends Reactive<Value> {
22
22
  * Create a computed value
23
23
  */
24
24
  export declare function computed<Value>(callback: () => Value): Computed<Value>;
25
+ declare class Subscription<Value> {
26
+ state: ReactiveState<Value>;
27
+ callback: GenericCallback;
28
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
29
+ }
30
+ /**
31
+ * Unsubscribe from changes
32
+ */
33
+ export type Unsubscribe = () => void;
25
34
  export declare abstract class Reactive<Value> {
26
35
  protected readonly state: ReactiveState<Value>;
27
36
  constructor(name: string, value: Value);
@@ -37,6 +46,14 @@ export declare abstract class Reactive<Value> {
37
46
  * Subscribe to changes
38
47
  */
39
48
  subscribe(callback: (value: Value) => void): Unsubscribe;
49
+ /**
50
+ * JSON representation of the value
51
+ */
52
+ toJSON(): Value;
53
+ /**
54
+ * String representation of the value
55
+ */
56
+ toString(): string;
40
57
  /**
41
58
  * Unsubscribe from changes
42
59
  */
@@ -48,15 +65,6 @@ export type ReactiveState<Value> = {
48
65
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
49
66
  value: Value;
50
67
  };
51
- declare class Subscription<Value> {
52
- state: ReactiveState<Value>;
53
- callback: GenericCallback;
54
- constructor(state: ReactiveState<Value>, callback: GenericCallback);
55
- }
56
- /**
57
- * Unsubscribe from changes
58
- */
59
- export type Unsubscribe = () => void;
60
68
  export declare class Signal<Value> extends Reactive<Value> {
61
69
  constructor(value: Value);
62
70
  /**
@@ -72,6 +80,9 @@ export declare class Signal<Value> extends Reactive<Value> {
72
80
  */
73
81
  update(callback: (value: Value) => Value): void;
74
82
  }
83
+ /**
84
+ * Create a reactive value
85
+ */
75
86
  export declare function signal<Value>(value: Value): Signal<Value>;
76
87
  /**
77
88
  * Is the value a computed signal?
@@ -86,6 +97,46 @@ export declare function isReactive(value: unknown): value is Reactive<unknown>;
86
97
  * Is the value a signal?
87
98
  */
88
99
  export declare function isSignal(value: unknown): value is Signal<unknown>;
100
+ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
101
+ #private;
102
+ /**
103
+ * The length of the array
104
+ */
105
+ get length(): number;
106
+ /**
107
+ * Set the length of the array
108
+ */
109
+ set length(value: number);
110
+ constructor(value: Item[]);
111
+ /**
112
+ * @inheritdoc
113
+ */
114
+ get(): Item[];
115
+ /**
116
+ * @inheritdoc
117
+ */
118
+ peek(): Item[];
119
+ /**
120
+ * Get the length of the array _(without reactivity)_
121
+ */
122
+ peek(length: true): number;
123
+ /**
124
+ * Set the value
125
+ */
126
+ set(value: Item[]): void;
127
+ /**
128
+ * Set the value at an index
129
+ */
130
+ set(index: number, value: Item): void;
131
+ /**
132
+ * Set the length of the array
133
+ */
134
+ set(property: "length", value: number): void;
135
+ }
136
+ /**
137
+ * Create a reactive array
138
+ */
139
+ export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
89
140
  /**
90
141
  * Start batching effects _(use `stopBatch` to flush and run batched effects)_
91
142
  */
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { array, type ReactiveArray } from './array';
1
2
  export { startBatch, stopBatch } from './batch';
2
3
  export { computed, type Computed } from './computed';
3
4
  export { effect, type Effect } from './effect';
package/types/is.d.cts CHANGED
@@ -14,6 +14,15 @@ declare class Computed<Value> extends Reactive<Value> {
14
14
  */
15
15
  get(): Value;
16
16
  }
17
+ declare class Subscription<Value> {
18
+ state: ReactiveState<Value>;
19
+ callback: GenericCallback;
20
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
21
+ }
22
+ /**
23
+ * Unsubscribe from changes
24
+ */
25
+ export type Unsubscribe = () => void;
17
26
  declare abstract class Reactive<Value> {
18
27
  protected readonly state: ReactiveState<Value>;
19
28
  constructor(name: string, value: Value);
@@ -29,6 +38,14 @@ declare abstract class Reactive<Value> {
29
38
  * Subscribe to changes
30
39
  */
31
40
  subscribe(callback: (value: Value) => void): Unsubscribe;
41
+ /**
42
+ * JSON representation of the value
43
+ */
44
+ toJSON(): Value;
45
+ /**
46
+ * String representation of the value
47
+ */
48
+ toString(): string;
32
49
  /**
33
50
  * Unsubscribe from changes
34
51
  */
@@ -40,15 +57,6 @@ export type ReactiveState<Value> = {
40
57
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
41
58
  value: Value;
42
59
  };
43
- declare class Subscription<Value> {
44
- state: ReactiveState<Value>;
45
- callback: GenericCallback;
46
- constructor(state: ReactiveState<Value>, callback: GenericCallback);
47
- }
48
- /**
49
- * Unsubscribe from changes
50
- */
51
- export type Unsubscribe = () => void;
52
60
  declare class Signal<Value> extends Reactive<Value> {
53
61
  constructor(value: Value);
54
62
  /**
@@ -14,6 +14,15 @@ declare class Computed<Value> extends Reactive<Value> {
14
14
  */
15
15
  get(): Value;
16
16
  }
17
+ declare class Subscription<Value> {
18
+ state: ReactiveState<Value>;
19
+ callback: GenericCallback;
20
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
21
+ }
22
+ /**
23
+ * Unsubscribe from changes
24
+ */
25
+ export type Unsubscribe = () => void;
17
26
  export declare abstract class Reactive<Value> {
18
27
  protected readonly state: ReactiveState<Value>;
19
28
  constructor(name: string, value: Value);
@@ -29,6 +38,14 @@ export declare abstract class Reactive<Value> {
29
38
  * Subscribe to changes
30
39
  */
31
40
  subscribe(callback: (value: Value) => void): Unsubscribe;
41
+ /**
42
+ * JSON representation of the value
43
+ */
44
+ toJSON(): Value;
45
+ /**
46
+ * String representation of the value
47
+ */
48
+ toString(): string;
32
49
  /**
33
50
  * Unsubscribe from changes
34
51
  */
@@ -40,14 +57,5 @@ export type ReactiveState<Value> = {
40
57
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
41
58
  value: Value;
42
59
  };
43
- declare class Subscription<Value> {
44
- state: ReactiveState<Value>;
45
- callback: GenericCallback;
46
- constructor(state: ReactiveState<Value>, callback: GenericCallback);
47
- }
48
- /**
49
- * Unsubscribe from changes
50
- */
51
- export type Unsubscribe = () => void;
52
60
 
53
61
  export {};
@@ -16,6 +16,14 @@ export declare abstract class Reactive<Value> {
16
16
  * Subscribe to changes
17
17
  */
18
18
  subscribe(callback: (value: Value) => void): Unsubscribe;
19
+ /**
20
+ * JSON representation of the value
21
+ */
22
+ toJSON(): Value;
23
+ /**
24
+ * String representation of the value
25
+ */
26
+ toString(): string;
19
27
  /**
20
28
  * Unsubscribe from changes
21
29
  */
@@ -14,6 +14,15 @@ declare class Computed<Value> extends Reactive<Value> {
14
14
  */
15
15
  get(): Value;
16
16
  }
17
+ declare class Subscription<Value> {
18
+ state: ReactiveState<Value>;
19
+ callback: GenericCallback;
20
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
21
+ }
22
+ /**
23
+ * Unsubscribe from changes
24
+ */
25
+ export type Unsubscribe = () => void;
17
26
  declare abstract class Reactive<Value> {
18
27
  protected readonly state: ReactiveState<Value>;
19
28
  constructor(name: string, value: Value);
@@ -29,6 +38,14 @@ declare abstract class Reactive<Value> {
29
38
  * Subscribe to changes
30
39
  */
31
40
  subscribe(callback: (value: Value) => void): Unsubscribe;
41
+ /**
42
+ * JSON representation of the value
43
+ */
44
+ toJSON(): Value;
45
+ /**
46
+ * String representation of the value
47
+ */
48
+ toString(): string;
32
49
  /**
33
50
  * Unsubscribe from changes
34
51
  */
@@ -40,15 +57,6 @@ export type ReactiveState<Value> = {
40
57
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
41
58
  value: Value;
42
59
  };
43
- declare class Subscription<Value> {
44
- state: ReactiveState<Value>;
45
- callback: GenericCallback;
46
- constructor(state: ReactiveState<Value>, callback: GenericCallback);
47
- }
48
- /**
49
- * Unsubscribe from changes
50
- */
51
- export type Unsubscribe = () => void;
52
60
  export declare class Signal<Value> extends Reactive<Value> {
53
61
  constructor(value: Value);
54
62
  /**
@@ -64,6 +72,9 @@ export declare class Signal<Value> extends Reactive<Value> {
64
72
  */
65
73
  update(callback: (value: Value) => Value): void;
66
74
  }
75
+ /**
76
+ * Create a reactive value
77
+ */
67
78
  export declare function signal<Value>(value: Value): Signal<Value>;
68
79
 
69
80
  export {};
package/types/signal.d.ts CHANGED
@@ -14,4 +14,7 @@ export declare class Signal<Value> extends Reactive<Value> {
14
14
  */
15
15
  update(callback: (value: Value) => Value): void;
16
16
  }
17
+ /**
18
+ * Create a reactive value
19
+ */
17
20
  export declare function signal<Value>(value: Value): Signal<Value>;
@@ -14,6 +14,18 @@ declare class Computed<Value> extends Reactive<Value> {
14
14
  */
15
15
  get(): Value;
16
16
  }
17
+ export declare class Subscription<Value> {
18
+ state: ReactiveState<Value>;
19
+ callback: GenericCallback;
20
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
21
+ }
22
+ /**
23
+ * Unsubscribe from changes
24
+ */
25
+ export type Unsubscribe = () => void;
26
+ export declare function noop(): void;
27
+ export declare function subscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): Unsubscribe;
28
+ export declare function unsubscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): void;
17
29
  declare abstract class Reactive<Value> {
18
30
  protected readonly state: ReactiveState<Value>;
19
31
  constructor(name: string, value: Value);
@@ -29,6 +41,14 @@ declare abstract class Reactive<Value> {
29
41
  * Subscribe to changes
30
42
  */
31
43
  subscribe(callback: (value: Value) => void): Unsubscribe;
44
+ /**
45
+ * JSON representation of the value
46
+ */
47
+ toJSON(): Value;
48
+ /**
49
+ * String representation of the value
50
+ */
51
+ toString(): string;
32
52
  /**
33
53
  * Unsubscribe from changes
34
54
  */
@@ -40,17 +60,5 @@ export type ReactiveState<Value> = {
40
60
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
41
61
  value: Value;
42
62
  };
43
- export declare class Subscription<Value> {
44
- state: ReactiveState<Value>;
45
- callback: GenericCallback;
46
- constructor(state: ReactiveState<Value>, callback: GenericCallback);
47
- }
48
- /**
49
- * Unsubscribe from changes
50
- */
51
- export type Unsubscribe = () => void;
52
- export declare function noop(): void;
53
- export declare function subscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): Unsubscribe;
54
- export declare function unsubscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): void;
55
63
 
56
64
  export {};
@@ -0,0 +1,64 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export type GenericCallback = (...args: any[]) => any;
4
+ declare class Effect {
5
+ private readonly $mora;
6
+ private readonly state;
7
+ constructor(callback: GenericCallback);
8
+ }
9
+ declare class Computed<Value> extends Reactive<Value> {
10
+ private readonly effect;
11
+ constructor(callback: () => Value);
12
+ /**
13
+ * @inheritdoc
14
+ */
15
+ get(): Value;
16
+ }
17
+ declare class Subscription<Value> {
18
+ state: ReactiveState<Value>;
19
+ callback: GenericCallback;
20
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
21
+ }
22
+ /**
23
+ * Unsubscribe from changes
24
+ */
25
+ export type Unsubscribe = () => void;
26
+ declare abstract class Reactive<Value> {
27
+ protected readonly state: ReactiveState<Value>;
28
+ constructor(name: string, value: Value);
29
+ /**
30
+ * Get the value
31
+ */
32
+ abstract get(): Value;
33
+ /**
34
+ * Get the value _(without reactivity)_
35
+ */
36
+ peek(): Value;
37
+ /**
38
+ * Subscribe to changes
39
+ */
40
+ subscribe(callback: (value: Value) => void): Unsubscribe;
41
+ /**
42
+ * JSON representation of the value
43
+ */
44
+ toJSON(): Value;
45
+ /**
46
+ * String representation of the value
47
+ */
48
+ toString(): string;
49
+ /**
50
+ * Unsubscribe from changes
51
+ */
52
+ unsubscribe(callback: (value: Value) => void): void;
53
+ }
54
+ export type ReactiveState<Value> = {
55
+ computeds: Set<Computed<unknown>>;
56
+ effects: Set<Effect>;
57
+ subscriptions: Map<(value: Value) => void, Subscription<Value>>;
58
+ value: Value;
59
+ };
60
+ export declare function emitValue<Value>(state: ReactiveState<Value>): void;
61
+ export declare function getValue<Value>(state: ReactiveState<Value>): Value;
62
+ export declare function setValue<Value>(state: ReactiveState<Value>, value: Value): void;
63
+
64
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { ReactiveState } from './reactive';
2
+ export declare function emitValue<Value>(state: ReactiveState<Value>): void;
3
+ export declare function getValue<Value>(state: ReactiveState<Value>): Value;
4
+ export declare function setValue<Value>(state: ReactiveState<Value>, value: Value): void;