@oscarpalmer/mora 0.15.0 → 0.17.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 (44) hide show
  1. package/dist/batch.cjs +3 -3
  2. package/dist/batch.js +3 -3
  3. package/dist/helpers/value.cjs +44 -8
  4. package/dist/helpers/value.js +45 -9
  5. package/dist/mora.full.js +75 -64
  6. package/dist/value/array.cjs +15 -9
  7. package/dist/value/array.js +14 -8
  8. package/dist/value/computed.cjs +6 -6
  9. package/dist/value/computed.js +6 -6
  10. package/dist/value/reactive.cjs +5 -1
  11. package/dist/value/reactive.js +5 -1
  12. package/dist/value/signal.cjs +8 -5
  13. package/dist/value/signal.js +9 -6
  14. package/package.json +3 -3
  15. package/src/batch.ts +2 -2
  16. package/src/helpers/is.ts +1 -1
  17. package/src/helpers/value.ts +66 -14
  18. package/src/subscription.ts +3 -3
  19. package/src/value/array.ts +22 -12
  20. package/src/value/computed.ts +12 -9
  21. package/src/value/reactive.ts +17 -4
  22. package/src/value/signal.ts +14 -7
  23. package/types/batch.d.cts +15 -8
  24. package/types/batch.d.ts +1 -1
  25. package/types/helpers/is.d.cts +21 -10
  26. package/types/helpers/is.d.ts +1 -1
  27. package/types/helpers/value.d.cts +18 -9
  28. package/types/helpers/value.d.ts +4 -2
  29. package/types/index.d.cts +24 -13
  30. package/types/subscription.d.cts +16 -9
  31. package/types/subscription.d.ts +4 -4
  32. package/types/value/array.d.cts +21 -10
  33. package/types/value/array.d.ts +8 -4
  34. package/types/value/computed.d.cts +16 -9
  35. package/types/value/computed.d.ts +5 -6
  36. package/types/value/reactive.d.cts +14 -7
  37. package/types/value/reactive.d.ts +11 -4
  38. package/types/value/signal.d.cts +16 -9
  39. package/types/value/signal.d.ts +3 -3
  40. package/dist/helpers/emit.cjs +0 -42
  41. package/dist/helpers/emit.js +0 -42
  42. package/src/helpers/emit.ts +0 -52
  43. package/types/helpers/emit.d.cts +0 -63
  44. package/types/helpers/emit.d.ts +0 -3
@@ -1,42 +0,0 @@
1
- import { batchedHandlers, batchDepth, flushEffects } from "../batch.js";
2
- function emitArrayChanges(first, second) {
3
- let { length } = first;
4
- if (length !== second.length) {
5
- return true;
6
- }
7
- let offset = 0;
8
- if (length >= 100) {
9
- offset = Math.round(length / 10);
10
- offset = offset > 25 ? 25 : offset;
11
- for (let index = 0; index < offset; index += 1) {
12
- if (!Object.is(first[index], second[index])) {
13
- return true;
14
- }
15
- }
16
- }
17
- length -= offset;
18
- for (let index = offset; index < length; index += 1) {
19
- if (!Object.is(first[index], second[index])) {
20
- return true;
21
- }
22
- }
23
- return false;
24
- }
25
- function emitValue(state) {
26
- for (const computed of state.computeds) {
27
- computed.effect.dirty = true;
28
- }
29
- for (const effect of state.effects) {
30
- batchedHandlers.add(effect);
31
- }
32
- for (const [, subscription] of state.subscriptions) {
33
- batchedHandlers.add(subscription);
34
- }
35
- if (batchDepth === 0) {
36
- flushEffects();
37
- }
38
- }
39
- export {
40
- emitArrayChanges,
41
- emitValue
42
- };
@@ -1,52 +0,0 @@
1
- import {batchDepth, batchedHandlers, flushEffects} from '../batch';
2
- import type {InternalComputed} from '../value/computed';
3
- import type {ReactiveState} from '../value/reactive';
4
-
5
- export function emitArrayChanges(first: unknown[], second: unknown[]): boolean {
6
- let {length} = first;
7
-
8
- if (length !== second.length) {
9
- return true;
10
- }
11
-
12
- let offset = 0;
13
-
14
- if (length >= 100) {
15
- offset = Math.round(length / 10);
16
- offset = offset > 25 ? 25 : offset;
17
-
18
- for (let index = 0; index < offset; index += 1) {
19
- if (!Object.is(first[index], second[index])) {
20
- return true;
21
- }
22
- }
23
- }
24
-
25
- length -= offset;
26
-
27
- for (let index = offset; index < length; index += 1) {
28
- if (!Object.is(first[index], second[index])) {
29
- return true;
30
- }
31
- }
32
-
33
- return false;
34
- }
35
-
36
- export function emitValue<Value>(state: ReactiveState<Value>): void {
37
- for (const computed of state.computeds) {
38
- (computed as unknown as InternalComputed).effect.dirty = true;
39
- }
40
-
41
- for (const effect of state.effects) {
42
- batchedHandlers.add(effect);
43
- }
44
-
45
- for (const [, subscription] of state.subscriptions) {
46
- batchedHandlers.add(subscription as never);
47
- }
48
-
49
- if (batchDepth === 0) {
50
- flushEffects();
51
- }
52
- }
@@ -1,63 +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 emitArrayChanges(first: unknown[], second: unknown[]): boolean;
61
- export declare function emitValue<Value>(state: ReactiveState<Value>): void;
62
-
63
- export {};
@@ -1,3 +0,0 @@
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;