@oscarpalmer/mora 0.18.0 → 0.18.1

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.
Files changed (44) hide show
  1. package/dist/helpers/is.cjs +7 -1
  2. package/dist/helpers/is.js +8 -2
  3. package/dist/helpers/proxy.cjs +43 -0
  4. package/dist/helpers/proxy.js +43 -0
  5. package/dist/helpers/value.cjs +22 -26
  6. package/dist/helpers/value.js +22 -26
  7. package/dist/index.cjs +2 -0
  8. package/dist/index.js +3 -1
  9. package/dist/mora.full.js +127 -59
  10. package/dist/node_modules/@oscarpalmer/atoms/dist/internal/is.cjs +17 -0
  11. package/dist/node_modules/@oscarpalmer/atoms/dist/internal/is.js +17 -0
  12. package/dist/value/array.cjs +15 -20
  13. package/dist/value/array.js +16 -21
  14. package/dist/value/computed.cjs +5 -5
  15. package/dist/value/computed.js +5 -5
  16. package/dist/value/reactive.cjs +5 -1
  17. package/dist/value/reactive.js +5 -1
  18. package/dist/value/signal.cjs +5 -5
  19. package/dist/value/signal.js +6 -6
  20. package/dist/value/store.cjs +36 -0
  21. package/dist/value/store.js +36 -0
  22. package/package.json +1 -1
  23. package/src/helpers/is.ts +1 -1
  24. package/src/helpers/proxy.ts +0 -1
  25. package/types/helpers/is.d.ts +3 -0
  26. package/types/helpers/proxy.d.ts +5 -0
  27. package/types/helpers/value.d.ts +3 -4
  28. package/types/index.d.ts +1 -0
  29. package/types/subscription.d.ts +4 -4
  30. package/types/value/array.d.ts +4 -4
  31. package/types/value/computed.d.ts +4 -4
  32. package/types/value/reactive.d.ts +11 -4
  33. package/types/value/signal.d.ts +3 -3
  34. package/types/value/store.d.ts +45 -0
  35. package/types/batch.d.cts +0 -72
  36. package/types/effect.d.cts +0 -16
  37. package/types/helpers/is.d.cts +0 -169
  38. package/types/helpers/value.d.cts +0 -65
  39. package/types/index.d.cts +0 -189
  40. package/types/subscription.d.cts +0 -64
  41. package/types/value/array.d.cts +0 -137
  42. package/types/value/computed.d.cts +0 -74
  43. package/types/value/reactive.d.cts +0 -61
  44. package/types/value/signal.d.cts +0 -80
package/types/batch.d.cts DELETED
@@ -1,72 +0,0 @@
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 abstract class Reactive<Value> {
18
- protected readonly state: ReactiveState<Value>;
19
- constructor(name: string, value: Value);
20
- /**
21
- * Get the value
22
- */
23
- abstract get(): Value;
24
- /**
25
- * Get the value _(without reactivity)_
26
- */
27
- peek(): Value;
28
- /**
29
- * Subscribe to changes
30
- */
31
- subscribe(callback: (value: Value) => void): Unsubscribe;
32
- /**
33
- * JSON representation of the value
34
- */
35
- toJSON(): Value;
36
- /**
37
- * String representation of the value
38
- */
39
- toString(): string;
40
- /**
41
- * Unsubscribe from changes
42
- */
43
- unsubscribe(callback: (value: Value) => void): void;
44
- }
45
- export type ReactiveState<Value> = {
46
- computeds: Set<Computed<unknown>>;
47
- effects: Set<Effect>;
48
- subscriptions: Map<(value: Value) => void, Subscription<Value>>;
49
- value: Value;
50
- };
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
- export declare function flushHandlers(): void;
61
- /**
62
- * Start batching effects _(use `stopBatch` to flush and run batched effects)_
63
- */
64
- export declare function startBatch(): void;
65
- /**
66
- * Stop batching effects and flush _(run)_ them
67
- */
68
- export declare function stopBatch(): void;
69
- export declare const batchedHandlers: Set<Effect | Subscription<unknown>>;
70
- export declare let batchDepth: number;
71
-
72
- export {};
@@ -1,16 +0,0 @@
1
- // Generated by dts-bundle-generator v9.5.1
2
-
3
- export type GenericCallback = (...args: any[]) => any;
4
- export declare class Effect {
5
- private readonly $mora;
6
- private readonly state;
7
- constructor(callback: GenericCallback);
8
- }
9
- export declare function runEffect(effect: Effect): void;
10
- /**
11
- * Create an effect
12
- */
13
- export declare function effect(callback: GenericCallback): Effect;
14
- export declare let activeEffect: Effect | undefined;
15
-
16
- export {};
@@ -1,169 +0,0 @@
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 abstract class Reactive<Value> {
18
- protected readonly state: ReactiveState<Value>;
19
- constructor(name: string, value: Value);
20
- /**
21
- * Get the value
22
- */
23
- abstract get(): Value;
24
- /**
25
- * Get the value _(without reactivity)_
26
- */
27
- peek(): Value;
28
- /**
29
- * Subscribe to changes
30
- */
31
- subscribe(callback: (value: Value) => void): Unsubscribe;
32
- /**
33
- * JSON representation of the value
34
- */
35
- toJSON(): Value;
36
- /**
37
- * String representation of the value
38
- */
39
- toString(): string;
40
- /**
41
- * Unsubscribe from changes
42
- */
43
- unsubscribe(callback: (value: Value) => void): void;
44
- }
45
- export type ReactiveState<Value> = {
46
- computeds: Set<Computed<unknown>>;
47
- effects: Set<Effect>;
48
- subscriptions: Map<(value: Value) => void, Subscription<Value>>;
49
- value: Value;
50
- };
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
- declare class ReactiveArray<Item> extends Reactive<Item[]> {
61
- #private;
62
- /**
63
- * The length of the array
64
- */
65
- get length(): number;
66
- /**
67
- * Set the length of the array
68
- */
69
- set length(value: number);
70
- constructor(value: Item[]);
71
- /**
72
- * Get an indexed item
73
- */
74
- at(index: number): Item | undefined;
75
- /**
76
- * Clear the array
77
- */
78
- clear(): void;
79
- /**
80
- * @inheritdoc
81
- */
82
- get(): Item[];
83
- /**
84
- * Create a computed, filtered array
85
- */
86
- filter(callback: (item: Item, index: number, array: Item[]) => boolean): Computed<Item[]>;
87
- /**
88
- * Create a computed, mapped array
89
- */
90
- map<Mapped>(callback: (item: Item, index: number, array: Item[]) => Mapped): Computed<Mapped[]>;
91
- /**
92
- * @inheritdoc
93
- */
94
- peek(): Item[];
95
- /**
96
- * Get the length of the array _(without reactivity)_
97
- */
98
- peek(length: true): number;
99
- /**
100
- * Remove and return the last item of the array
101
- */
102
- pop(): Item | undefined;
103
- /**
104
- * Add items to the end of the array
105
- */
106
- push(...items: Item[]): number;
107
- /**
108
- * Set the value
109
- */
110
- set(value: Item[]): void;
111
- /**
112
- * Set the value at an index
113
- */
114
- set(index: number, value: Item): void;
115
- /**
116
- * Set the length of the array
117
- */
118
- set(property: "length", value: number): void;
119
- /**
120
- * Remove and return the first item of the array
121
- */
122
- shift(): Item | undefined;
123
- /**
124
- * Remove and return items from the array _(and optionally add new items)_
125
- */
126
- splice(from: number, to?: number, ...items: Item[]): Item[];
127
- /**
128
- * Add items to the beginning of the array
129
- */
130
- unshift(...items: Item[]): number;
131
- }
132
- declare class Signal<Value> extends Reactive<Value> {
133
- constructor(value: Value);
134
- /**
135
- * @inheritdoc
136
- */
137
- get(): Value;
138
- /**
139
- * Set the value
140
- */
141
- set(value: Value): void;
142
- /**
143
- * Update the value
144
- */
145
- update(callback: (value: Value) => Value): void;
146
- }
147
- /**
148
- * Is the value a reactive array?
149
- */
150
- export declare function isArray(value: unknown): value is ReactiveArray<unknown>;
151
- /**
152
- * Is the value a computed signal?
153
- */
154
- export declare function isComputed(value: unknown): value is Computed<unknown>;
155
- /**
156
- * Is the value an effect?
157
- */
158
- export declare function isEffect(value: unknown): value is Effect;
159
- export declare function isReactive(value: unknown): value is Reactive<unknown>;
160
- /**
161
- * Is the value a signal?
162
- */
163
- export declare function isSignal(value: unknown): value is Signal<unknown>;
164
- export declare const arrayName = "array";
165
- export declare const computedName = "computed";
166
- export declare const effectName = "effect";
167
- export declare const signalName = "signal";
168
-
169
- export {};
@@ -1,65 +0,0 @@
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 abstract class Reactive<Value> {
18
- protected readonly state: ReactiveState<Value>;
19
- constructor(name: string, value: Value);
20
- /**
21
- * Get the value
22
- */
23
- abstract get(): Value;
24
- /**
25
- * Get the value _(without reactivity)_
26
- */
27
- peek(): Value;
28
- /**
29
- * Subscribe to changes
30
- */
31
- subscribe(callback: (value: Value) => void): Unsubscribe;
32
- /**
33
- * JSON representation of the value
34
- */
35
- toJSON(): Value;
36
- /**
37
- * String representation of the value
38
- */
39
- toString(): string;
40
- /**
41
- * Unsubscribe from changes
42
- */
43
- unsubscribe(callback: (value: Value) => void): void;
44
- }
45
- export type ReactiveState<Value> = {
46
- computeds: Set<Computed<unknown>>;
47
- effects: Set<Effect>;
48
- subscriptions: Map<(value: Value) => void, Subscription<Value>>;
49
- value: Value;
50
- };
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
- export declare function differentArrays(first: unknown[], second: unknown[]): boolean;
61
- export declare function differentValues(first: unknown, second: unknown): boolean;
62
- export declare function emitValue<Value>(state: ReactiveState<Value>): void;
63
- export declare function getValue<Value>(state: ReactiveState<Value>): Value;
64
-
65
- export {};
package/types/index.d.cts DELETED
@@ -1,189 +0,0 @@
1
- // Generated by dts-bundle-generator v9.5.1
2
-
3
- export type GenericCallback = (...args: any[]) => any;
4
- export declare class Effect {
5
- private readonly $mora;
6
- private readonly state;
7
- constructor(callback: GenericCallback);
8
- }
9
- /**
10
- * Create an effect
11
- */
12
- export declare function effect(callback: GenericCallback): Effect;
13
- export declare class Computed<Value> extends Reactive<Value> {
14
- private readonly effect;
15
- constructor(callback: () => Value);
16
- /**
17
- * @inheritdoc
18
- */
19
- get(): Value;
20
- }
21
- /**
22
- * Create a computed value
23
- */
24
- export declare function computed<Value>(callback: () => Value): Computed<Value>;
25
- export declare abstract class Reactive<Value> {
26
- protected readonly state: ReactiveState<Value>;
27
- constructor(name: string, value: Value);
28
- /**
29
- * Get the value
30
- */
31
- abstract get(): Value;
32
- /**
33
- * Get the value _(without reactivity)_
34
- */
35
- peek(): Value;
36
- /**
37
- * Subscribe to changes
38
- */
39
- subscribe(callback: (value: Value) => void): Unsubscribe;
40
- /**
41
- * JSON representation of the value
42
- */
43
- toJSON(): Value;
44
- /**
45
- * String representation of the value
46
- */
47
- toString(): string;
48
- /**
49
- * Unsubscribe from changes
50
- */
51
- unsubscribe(callback: (value: Value) => void): void;
52
- }
53
- export type ReactiveState<Value> = {
54
- computeds: Set<Computed<unknown>>;
55
- effects: Set<Effect>;
56
- subscriptions: Map<(value: Value) => void, Subscription<Value>>;
57
- value: Value;
58
- };
59
- declare class Subscription<Value> {
60
- state: ReactiveState<Value>;
61
- callback: GenericCallback;
62
- constructor(state: ReactiveState<Value>, callback: GenericCallback);
63
- }
64
- /**
65
- * Unsubscribe from changes
66
- */
67
- export type Unsubscribe = () => void;
68
- /**
69
- * Start batching effects _(use `stopBatch` to flush and run batched effects)_
70
- */
71
- export declare function startBatch(): void;
72
- /**
73
- * Stop batching effects and flush _(run)_ them
74
- */
75
- export declare function stopBatch(): void;
76
- export declare class ReactiveArray<Item> extends Reactive<Item[]> {
77
- #private;
78
- /**
79
- * The length of the array
80
- */
81
- get length(): number;
82
- /**
83
- * Set the length of the array
84
- */
85
- set length(value: number);
86
- constructor(value: Item[]);
87
- /**
88
- * Get an indexed item
89
- */
90
- at(index: number): Item | undefined;
91
- /**
92
- * Clear the array
93
- */
94
- clear(): void;
95
- /**
96
- * @inheritdoc
97
- */
98
- get(): Item[];
99
- /**
100
- * Create a computed, filtered array
101
- */
102
- filter(callback: (item: Item, index: number, array: Item[]) => boolean): Computed<Item[]>;
103
- /**
104
- * Create a computed, mapped array
105
- */
106
- map<Mapped>(callback: (item: Item, index: number, array: Item[]) => Mapped): Computed<Mapped[]>;
107
- /**
108
- * @inheritdoc
109
- */
110
- peek(): Item[];
111
- /**
112
- * Get the length of the array _(without reactivity)_
113
- */
114
- peek(length: true): number;
115
- /**
116
- * Remove and return the last item of the array
117
- */
118
- pop(): Item | undefined;
119
- /**
120
- * Add items to the end of the array
121
- */
122
- push(...items: Item[]): 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
- * Remove and return the first item of the array
137
- */
138
- shift(): Item | undefined;
139
- /**
140
- * Remove and return items from the array _(and optionally add new items)_
141
- */
142
- splice(from: number, to?: number, ...items: Item[]): Item[];
143
- /**
144
- * Add items to the beginning of the array
145
- */
146
- unshift(...items: Item[]): number;
147
- }
148
- /**
149
- * Create a reactive array
150
- */
151
- export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
152
- export declare class Signal<Value> extends Reactive<Value> {
153
- constructor(value: Value);
154
- /**
155
- * @inheritdoc
156
- */
157
- get(): Value;
158
- /**
159
- * Set the value
160
- */
161
- set(value: Value): void;
162
- /**
163
- * Update the value
164
- */
165
- update(callback: (value: Value) => Value): void;
166
- }
167
- /**
168
- * Create a reactive value
169
- */
170
- export declare function signal<Value>(value: Value): Signal<Value>;
171
- /**
172
- * Is the value a reactive array?
173
- */
174
- export declare function isArray(value: unknown): value is ReactiveArray<unknown>;
175
- /**
176
- * Is the value a computed signal?
177
- */
178
- export declare function isComputed(value: unknown): value is Computed<unknown>;
179
- /**
180
- * Is the value an effect?
181
- */
182
- export declare function isEffect(value: unknown): value is Effect;
183
- export declare function isReactive(value: unknown): value is Reactive<unknown>;
184
- /**
185
- * Is the value a signal?
186
- */
187
- export declare function isSignal(value: unknown): value is Signal<unknown>;
188
-
189
- export {};
@@ -1,64 +0,0 @@
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 abstract class Reactive<Value> {
18
- protected readonly state: ReactiveState<Value>;
19
- constructor(name: string, value: Value);
20
- /**
21
- * Get the value
22
- */
23
- abstract get(): Value;
24
- /**
25
- * Get the value _(without reactivity)_
26
- */
27
- peek(): Value;
28
- /**
29
- * Subscribe to changes
30
- */
31
- subscribe(callback: (value: Value) => void): Unsubscribe;
32
- /**
33
- * JSON representation of the value
34
- */
35
- toJSON(): Value;
36
- /**
37
- * String representation of the value
38
- */
39
- toString(): string;
40
- /**
41
- * Unsubscribe from changes
42
- */
43
- unsubscribe(callback: (value: Value) => void): void;
44
- }
45
- export type ReactiveState<Value> = {
46
- computeds: Set<Computed<unknown>>;
47
- effects: Set<Effect>;
48
- subscriptions: Map<(value: Value) => void, Subscription<Value>>;
49
- value: Value;
50
- };
51
- export 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
- export declare function noop(): void;
61
- export declare function subscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): Unsubscribe;
62
- export declare function unsubscribe<Value>(state: ReactiveState<Value>, callback: (value: Value) => void): void;
63
-
64
- export {};
@@ -1,137 +0,0 @@
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 abstract class Reactive<Value> {
18
- protected readonly state: ReactiveState<Value>;
19
- constructor(name: string, value: Value);
20
- /**
21
- * Get the value
22
- */
23
- abstract get(): Value;
24
- /**
25
- * Get the value _(without reactivity)_
26
- */
27
- peek(): Value;
28
- /**
29
- * Subscribe to changes
30
- */
31
- subscribe(callback: (value: Value) => void): Unsubscribe;
32
- /**
33
- * JSON representation of the value
34
- */
35
- toJSON(): Value;
36
- /**
37
- * String representation of the value
38
- */
39
- toString(): string;
40
- /**
41
- * Unsubscribe from changes
42
- */
43
- unsubscribe(callback: (value: Value) => void): void;
44
- }
45
- export type ReactiveState<Value> = {
46
- computeds: Set<Computed<unknown>>;
47
- effects: Set<Effect>;
48
- subscriptions: Map<(value: Value) => void, Subscription<Value>>;
49
- value: Value;
50
- };
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
- export declare class ReactiveArray<Item> extends Reactive<Item[]> {
61
- #private;
62
- /**
63
- * The length of the array
64
- */
65
- get length(): number;
66
- /**
67
- * Set the length of the array
68
- */
69
- set length(value: number);
70
- constructor(value: Item[]);
71
- /**
72
- * Get an indexed item
73
- */
74
- at(index: number): Item | undefined;
75
- /**
76
- * Clear the array
77
- */
78
- clear(): void;
79
- /**
80
- * @inheritdoc
81
- */
82
- get(): Item[];
83
- /**
84
- * Create a computed, filtered array
85
- */
86
- filter(callback: (item: Item, index: number, array: Item[]) => boolean): Computed<Item[]>;
87
- /**
88
- * Create a computed, mapped array
89
- */
90
- map<Mapped>(callback: (item: Item, index: number, array: Item[]) => Mapped): Computed<Mapped[]>;
91
- /**
92
- * @inheritdoc
93
- */
94
- peek(): Item[];
95
- /**
96
- * Get the length of the array _(without reactivity)_
97
- */
98
- peek(length: true): number;
99
- /**
100
- * Remove and return the last item of the array
101
- */
102
- pop(): Item | undefined;
103
- /**
104
- * Add items to the end of the array
105
- */
106
- push(...items: Item[]): number;
107
- /**
108
- * Set the value
109
- */
110
- set(value: Item[]): void;
111
- /**
112
- * Set the value at an index
113
- */
114
- set(index: number, value: Item): void;
115
- /**
116
- * Set the length of the array
117
- */
118
- set(property: "length", value: number): void;
119
- /**
120
- * Remove and return the first item of the array
121
- */
122
- shift(): Item | undefined;
123
- /**
124
- * Remove and return items from the array _(and optionally add new items)_
125
- */
126
- splice(from: number, to?: number, ...items: Item[]): Item[];
127
- /**
128
- * Add items to the beginning of the array
129
- */
130
- unshift(...items: Item[]): number;
131
- }
132
- /**
133
- * Create a reactive array
134
- */
135
- export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
136
-
137
- export {};