@oscarpalmer/mora 0.13.0 → 0.14.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.
Files changed (60) hide show
  1. package/dist/batch.cjs +2 -2
  2. package/dist/batch.js +1 -1
  3. package/dist/effect.cjs +2 -1
  4. package/dist/effect.js +2 -1
  5. package/dist/helpers/emit.cjs +42 -0
  6. package/dist/helpers/emit.js +42 -0
  7. package/dist/helpers/is.cjs +34 -0
  8. package/dist/helpers/is.js +34 -0
  9. package/dist/helpers/value.cjs +22 -0
  10. package/dist/helpers/value.js +22 -0
  11. package/dist/index.cjs +12 -11
  12. package/dist/index.js +5 -4
  13. package/dist/mora.full.js +152 -140
  14. package/dist/{array.cjs → value/array.cjs} +27 -49
  15. package/dist/{array.js → value/array.js} +9 -31
  16. package/dist/{computed.cjs → value/computed.cjs} +6 -5
  17. package/dist/{computed.js → value/computed.js} +4 -3
  18. package/dist/{reactive.cjs → value/reactive.cjs} +1 -1
  19. package/dist/{reactive.js → value/reactive.js} +1 -1
  20. package/dist/value/signal.cjs +33 -0
  21. package/dist/{signal.js → value/signal.js} +3 -2
  22. package/package.json +1 -1
  23. package/src/batch.ts +1 -1
  24. package/src/effect.ts +12 -11
  25. package/src/helpers/emit.ts +52 -0
  26. package/src/helpers/is.ts +56 -0
  27. package/src/helpers/value.ts +27 -0
  28. package/src/index.ts +11 -5
  29. package/src/subscription.ts +1 -1
  30. package/src/{array.ts → value/array.ts} +10 -41
  31. package/src/{computed.ts → value/computed.ts} +4 -3
  32. package/src/{reactive.ts → value/reactive.ts} +3 -3
  33. package/src/{signal.ts → value/signal.ts} +3 -2
  34. package/types/batch.d.cts +9 -9
  35. package/types/helpers/emit.d.cts +63 -0
  36. package/types/helpers/emit.d.ts +3 -0
  37. package/types/{is.d.cts → helpers/is.d.cts} +53 -9
  38. package/types/helpers/is.d.ts +26 -0
  39. package/types/{value.d.cts → helpers/value.d.cts} +9 -10
  40. package/types/{value.d.ts → helpers/value.d.ts} +1 -2
  41. package/types/index.d.cts +42 -38
  42. package/types/index.d.ts +5 -5
  43. package/types/subscription.d.cts +12 -12
  44. package/types/subscription.d.ts +1 -1
  45. package/types/{computed.d.ts → value/computed.d.ts} +1 -1
  46. package/types/{reactive.d.ts → value/reactive.d.ts} +2 -2
  47. package/dist/is.cjs +0 -21
  48. package/dist/is.js +0 -21
  49. package/dist/signal.cjs +0 -32
  50. package/dist/value.cjs +0 -38
  51. package/dist/value.js +0 -38
  52. package/src/is.ts +0 -39
  53. package/src/value.ts +0 -47
  54. package/types/is.d.ts +0 -17
  55. package/types/{array.d.cts → value/array.d.cts} +9 -9
  56. package/types/{array.d.ts → value/array.d.ts} +0 -0
  57. package/types/{computed.d.cts → value/computed.d.cts} +9 -9
  58. package/types/{reactive.d.cts → value/reactive.d.cts} +9 -9
  59. package/types/{signal.d.cts → value/signal.d.cts} +9 -9
  60. /package/types/{signal.d.ts → value/signal.d.ts} +0 -0
package/types/batch.d.cts CHANGED
@@ -14,15 +14,6 @@ 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;
26
17
  declare abstract class Reactive<Value> {
27
18
  protected readonly state: ReactiveState<Value>;
28
19
  constructor(name: string, value: Value);
@@ -57,6 +48,15 @@ export type ReactiveState<Value> = {
57
48
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
58
49
  value: Value;
59
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
60
  export declare function flushEffects(): void;
61
61
  /**
62
62
  * Start batching effects _(use `stopBatch` to flush and run batched effects)_
@@ -0,0 +1,63 @@
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 emitArrayChanges(first: unknown[], second: unknown[]): boolean;
61
+ export declare function emitValue<Value>(state: ReactiveState<Value>): void;
62
+
63
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { ReactiveState } from '../value/reactive';
2
+ export declare function emitArrayChanges(first: unknown[], second: unknown[]): boolean;
3
+ export declare function emitValue<Value>(state: ReactiveState<Value>): void;
@@ -14,15 +14,6 @@ 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;
26
17
  declare abstract class Reactive<Value> {
27
18
  protected readonly state: ReactiveState<Value>;
28
19
  constructor(name: string, value: Value);
@@ -57,6 +48,51 @@ export type ReactiveState<Value> = {
57
48
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
58
49
  value: Value;
59
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
+ * @inheritdoc
73
+ */
74
+ get(): Item[];
75
+ /**
76
+ * @inheritdoc
77
+ */
78
+ peek(): Item[];
79
+ /**
80
+ * Get the length of the array _(without reactivity)_
81
+ */
82
+ peek(length: true): number;
83
+ /**
84
+ * Set the value
85
+ */
86
+ set(value: Item[]): void;
87
+ /**
88
+ * Set the value at an index
89
+ */
90
+ set(index: number, value: Item): void;
91
+ /**
92
+ * Set the length of the array
93
+ */
94
+ set(property: "length", value: number): void;
95
+ }
60
96
  declare class Signal<Value> extends Reactive<Value> {
61
97
  constructor(value: Value);
62
98
  /**
@@ -72,6 +108,10 @@ declare class Signal<Value> extends Reactive<Value> {
72
108
  */
73
109
  update(callback: (value: Value) => Value): void;
74
110
  }
111
+ /**
112
+ * Is the value a reactive array?
113
+ */
114
+ export declare function isArray(value: unknown): value is ReactiveArray<unknown>;
75
115
  /**
76
116
  * Is the value a computed signal?
77
117
  */
@@ -85,5 +125,9 @@ export declare function isReactive(value: unknown): value is Reactive<unknown>;
85
125
  * Is the value a signal?
86
126
  */
87
127
  export declare function isSignal(value: unknown): value is Signal<unknown>;
128
+ export declare const arrayName = "array";
129
+ export declare const computedName = "computed";
130
+ export declare const effectName = "effect";
131
+ export declare const signalName = "signal";
88
132
 
89
133
  export {};
@@ -0,0 +1,26 @@
1
+ import type { Effect } from '../effect';
2
+ import type { ReactiveArray } from '../value/array';
3
+ import type { Computed } from '../value/computed';
4
+ import type { Reactive } from '../value/reactive';
5
+ import { type Signal } from '../value/signal';
6
+ /**
7
+ * Is the value a reactive array?
8
+ */
9
+ export declare function isArray(value: unknown): value is ReactiveArray<unknown>;
10
+ /**
11
+ * Is the value a computed signal?
12
+ */
13
+ export declare function isComputed(value: unknown): value is Computed<unknown>;
14
+ /**
15
+ * Is the value an effect?
16
+ */
17
+ export declare function isEffect(value: unknown): value is Effect;
18
+ export declare function isReactive(value: unknown): value is Reactive<unknown>;
19
+ /**
20
+ * Is the value a signal?
21
+ */
22
+ export declare function isSignal(value: unknown): value is Signal<unknown>;
23
+ export declare const arrayName = "array";
24
+ export declare const computedName = "computed";
25
+ export declare const effectName = "effect";
26
+ export declare const signalName = "signal";
@@ -14,15 +14,6 @@ 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;
26
17
  declare abstract class Reactive<Value> {
27
18
  protected readonly state: ReactiveState<Value>;
28
19
  constructor(name: string, value: Value);
@@ -57,7 +48,15 @@ export type ReactiveState<Value> = {
57
48
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
58
49
  value: Value;
59
50
  };
60
- export declare function emitValue<Value>(state: ReactiveState<Value>): void;
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;
61
60
  export declare function getValue<Value>(state: ReactiveState<Value>): Value;
62
61
  export declare function setValue<Value>(state: ReactiveState<Value>, value: Value): void;
63
62
 
@@ -1,4 +1,3 @@
1
- import type { ReactiveState } from './reactive';
2
- export declare function emitValue<Value>(state: ReactiveState<Value>): void;
1
+ import type { ReactiveState } from '../value/reactive';
3
2
  export declare function getValue<Value>(state: ReactiveState<Value>): Value;
4
3
  export declare function setValue<Value>(state: ReactiveState<Value>, value: Value): void;
package/types/index.d.cts CHANGED
@@ -22,15 +22,6 @@ 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;
34
25
  export declare abstract class Reactive<Value> {
35
26
  protected readonly state: ReactiveState<Value>;
36
27
  constructor(name: string, value: Value);
@@ -65,38 +56,23 @@ export type ReactiveState<Value> = {
65
56
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
66
57
  value: Value;
67
58
  };
68
- export declare class Signal<Value> extends Reactive<Value> {
69
- constructor(value: Value);
70
- /**
71
- * @inheritdoc
72
- */
73
- get(): Value;
74
- /**
75
- * Set the value
76
- */
77
- set(value: Value): void;
78
- /**
79
- * Update the value
80
- */
81
- update(callback: (value: Value) => Value): void;
59
+ declare class Subscription<Value> {
60
+ state: ReactiveState<Value>;
61
+ callback: GenericCallback;
62
+ constructor(state: ReactiveState<Value>, callback: GenericCallback);
82
63
  }
83
64
  /**
84
- * Create a reactive value
85
- */
86
- export declare function signal<Value>(value: Value): Signal<Value>;
87
- /**
88
- * Is the value a computed signal?
65
+ * Unsubscribe from changes
89
66
  */
90
- export declare function isComputed(value: unknown): value is Computed<unknown>;
67
+ export type Unsubscribe = () => void;
91
68
  /**
92
- * Is the value an effect?
69
+ * Start batching effects _(use `stopBatch` to flush and run batched effects)_
93
70
  */
94
- export declare function isEffect(value: unknown): value is Effect;
95
- export declare function isReactive(value: unknown): value is Reactive<unknown>;
71
+ export declare function startBatch(): void;
96
72
  /**
97
- * Is the value a signal?
73
+ * Stop batching effects and flush _(run)_ them
98
74
  */
99
- export declare function isSignal(value: unknown): value is Signal<unknown>;
75
+ export declare function stopBatch(): void;
100
76
  export declare class ReactiveArray<Item> extends Reactive<Item[]> {
101
77
  #private;
102
78
  /**
@@ -137,13 +113,41 @@ export declare class ReactiveArray<Item> extends Reactive<Item[]> {
137
113
  * Create a reactive array
138
114
  */
139
115
  export declare function array<Item>(value: Item[]): ReactiveArray<Item>;
116
+ export declare class Signal<Value> extends Reactive<Value> {
117
+ constructor(value: Value);
118
+ /**
119
+ * @inheritdoc
120
+ */
121
+ get(): Value;
122
+ /**
123
+ * Set the value
124
+ */
125
+ set(value: Value): void;
126
+ /**
127
+ * Update the value
128
+ */
129
+ update(callback: (value: Value) => Value): void;
130
+ }
140
131
  /**
141
- * Start batching effects _(use `stopBatch` to flush and run batched effects)_
132
+ * Create a reactive value
142
133
  */
143
- export declare function startBatch(): void;
134
+ export declare function signal<Value>(value: Value): Signal<Value>;
144
135
  /**
145
- * Stop batching effects and flush _(run)_ them
136
+ * Is the value a reactive array?
146
137
  */
147
- export declare function stopBatch(): void;
138
+ export declare function isArray(value: unknown): value is ReactiveArray<unknown>;
139
+ /**
140
+ * Is the value a computed signal?
141
+ */
142
+ export declare function isComputed(value: unknown): value is Computed<unknown>;
143
+ /**
144
+ * Is the value an effect?
145
+ */
146
+ export declare function isEffect(value: unknown): value is Effect;
147
+ export declare function isReactive(value: unknown): value is Reactive<unknown>;
148
+ /**
149
+ * Is the value a signal?
150
+ */
151
+ export declare function isSignal(value: unknown): value is Signal<unknown>;
148
152
 
149
153
  export {};
package/types/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { array, type ReactiveArray } from './array';
2
1
  export { startBatch, stopBatch } from './batch';
3
- export { computed, type Computed } from './computed';
4
2
  export { effect, type Effect } from './effect';
5
- export { isComputed, isEffect, isReactive, isSignal } from './is';
6
- export type { Reactive } from './reactive';
7
- export { signal, type Signal } from './signal';
3
+ export { isArray, isComputed, isEffect, isReactive, isSignal, } from './helpers/is';
4
+ export { array, type ReactiveArray } from './value/array';
5
+ export { computed, type Computed } from './value/computed';
6
+ export type { Reactive } from './value/reactive';
7
+ export { signal, type Signal } from './value/signal';
@@ -14,18 +14,6 @@ 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;
29
17
  declare abstract class Reactive<Value> {
30
18
  protected readonly state: ReactiveState<Value>;
31
19
  constructor(name: string, value: Value);
@@ -60,5 +48,17 @@ export type ReactiveState<Value> = {
60
48
  subscriptions: Map<(value: Value) => void, Subscription<Value>>;
61
49
  value: Value;
62
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
63
 
64
64
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { GenericCallback } from '@oscarpalmer/atoms/models';
2
- import type { ReactiveState } from './reactive';
2
+ import type { ReactiveState } from './value/reactive';
3
3
  export declare class Subscription<Value> {
4
4
  state: ReactiveState<Value>;
5
5
  callback: GenericCallback;
@@ -1,4 +1,4 @@
1
- import { type Effect } from './effect';
1
+ import { type Effect } from '../effect';
2
2
  import { Reactive, type ReactiveState } from './reactive';
3
3
  type ComputedEffect = {
4
4
  dirty: boolean;
@@ -1,6 +1,6 @@
1
+ import type { Effect } from '../effect';
2
+ import { type Subscription, type Unsubscribe } from '../subscription';
1
3
  import type { Computed } from './computed';
2
- import type { Effect } from './effect';
3
- import { type Subscription, type Unsubscribe } from './subscription';
4
4
  export declare abstract class Reactive<Value> {
5
5
  protected readonly state: ReactiveState<Value>;
6
6
  constructor(name: string, value: Value);
package/dist/is.cjs DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- function isComputed(value) {
4
- return isMora(value, "computed");
5
- }
6
- function isEffect(value) {
7
- return isMora(value, "effect");
8
- }
9
- function isMora(value, name) {
10
- return typeof value === "object" && value != null && "$mora" in value && value.$mora === name;
11
- }
12
- function isReactive(value) {
13
- return isComputed(value) || isSignal(value);
14
- }
15
- function isSignal(value) {
16
- return isMora(value, "signal");
17
- }
18
- exports.isComputed = isComputed;
19
- exports.isEffect = isEffect;
20
- exports.isReactive = isReactive;
21
- exports.isSignal = isSignal;
package/dist/is.js DELETED
@@ -1,21 +0,0 @@
1
- function isComputed(value) {
2
- return isMora(value, "computed");
3
- }
4
- function isEffect(value) {
5
- return isMora(value, "effect");
6
- }
7
- function isMora(value, name) {
8
- return typeof value === "object" && value != null && "$mora" in value && value.$mora === name;
9
- }
10
- function isReactive(value) {
11
- return isComputed(value) || isSignal(value);
12
- }
13
- function isSignal(value) {
14
- return isMora(value, "signal");
15
- }
16
- export {
17
- isComputed,
18
- isEffect,
19
- isReactive,
20
- isSignal
21
- };
package/dist/signal.cjs DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const reactive = require("./reactive.cjs");
4
- const value = require("./value.cjs");
5
- class Signal extends reactive.Reactive {
6
- constructor(value2) {
7
- super("signal", value2);
8
- }
9
- /**
10
- * @inheritdoc
11
- */
12
- get() {
13
- return value.getValue(this.state);
14
- }
15
- /**
16
- * Set the value
17
- */
18
- set(value$1) {
19
- value.setValue(this.state, value$1);
20
- }
21
- /**
22
- * Update the value
23
- */
24
- update(callback) {
25
- this.set(callback(this.state.value));
26
- }
27
- }
28
- function signal(value2) {
29
- return new Signal(value2);
30
- }
31
- exports.Signal = Signal;
32
- exports.signal = signal;
package/dist/value.cjs DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const batch = require("./batch.cjs");
4
- const computed = require("./computed.cjs");
5
- const effect = require("./effect.cjs");
6
- function emitValue(state) {
7
- for (const computed2 of state.computeds) {
8
- computed2.effect.dirty = true;
9
- }
10
- for (const effect2 of state.effects) {
11
- batch.batchedHandlers.add(effect2);
12
- }
13
- for (const [, subscription] of state.subscriptions) {
14
- batch.batchedHandlers.add(subscription);
15
- }
16
- if (batch.batchDepth === 0) {
17
- batch.flushEffects();
18
- }
19
- }
20
- function getValue(state) {
21
- if (computed.activeComputed != null) {
22
- state.computeds.add(computed.activeComputed);
23
- }
24
- if (effect.activeEffect != null) {
25
- state.effects.add(effect.activeEffect);
26
- }
27
- return state.value;
28
- }
29
- function setValue(state, value) {
30
- if (Object.is(state.value, value)) {
31
- return;
32
- }
33
- state.value = value;
34
- emitValue(state);
35
- }
36
- exports.emitValue = emitValue;
37
- exports.getValue = getValue;
38
- exports.setValue = setValue;
package/dist/value.js DELETED
@@ -1,38 +0,0 @@
1
- import { batchedHandlers, flushEffects, batchDepth } from "./batch.js";
2
- import { activeComputed } from "./computed.js";
3
- import { activeEffect } from "./effect.js";
4
- function emitValue(state) {
5
- for (const computed of state.computeds) {
6
- computed.effect.dirty = true;
7
- }
8
- for (const effect of state.effects) {
9
- batchedHandlers.add(effect);
10
- }
11
- for (const [, subscription] of state.subscriptions) {
12
- batchedHandlers.add(subscription);
13
- }
14
- if (batchDepth === 0) {
15
- flushEffects();
16
- }
17
- }
18
- function getValue(state) {
19
- if (activeComputed != null) {
20
- state.computeds.add(activeComputed);
21
- }
22
- if (activeEffect != null) {
23
- state.effects.add(activeEffect);
24
- }
25
- return state.value;
26
- }
27
- function setValue(state, value) {
28
- if (Object.is(state.value, value)) {
29
- return;
30
- }
31
- state.value = value;
32
- emitValue(state);
33
- }
34
- export {
35
- emitValue,
36
- getValue,
37
- setValue
38
- };
package/src/is.ts DELETED
@@ -1,39 +0,0 @@
1
- import type {PlainObject} from '@oscarpalmer/atoms/models';
2
- import type {Computed} from './computed';
3
- import type {Effect} from './effect';
4
- import type {Reactive} from './reactive';
5
- import type {Signal} from './signal';
6
-
7
- /**
8
- * Is the value a computed signal?
9
- */
10
- export function isComputed(value: unknown): value is Computed<unknown> {
11
- return isMora<Computed<unknown>>(value, 'computed');
12
- }
13
-
14
- /**
15
- * Is the value an effect?
16
- */
17
- export function isEffect(value: unknown): value is Effect {
18
- return isMora<Effect>(value, 'effect');
19
- }
20
-
21
- function isMora<T>(value: unknown, name: string): value is T {
22
- return (
23
- typeof value === 'object' &&
24
- value != null &&
25
- '$mora' in value &&
26
- (value as PlainObject).$mora === name
27
- );
28
- }
29
-
30
- export function isReactive(value: unknown): value is Reactive<unknown> {
31
- return isComputed(value) || isSignal(value);
32
- }
33
-
34
- /**
35
- * Is the value a signal?
36
- */
37
- export function isSignal(value: unknown): value is Signal<unknown> {
38
- return isMora<Signal<unknown>>(value, 'signal');
39
- }