@esportsplus/reactivity 0.1.0 → 0.1.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.
@@ -1,4 +1,4 @@
1
- import { Listener, Options } from '../types';
1
+ import { Listener, Object, Options } from '../types';
2
2
  import { ReactiveObject } from './object';
3
3
  type Events<T> = {
4
4
  fill: {
@@ -24,7 +24,7 @@ type Events<T> = {
24
24
  items: T[];
25
25
  };
26
26
  };
27
- type Node<T extends Record<PropertyKey, unknown>> = ReactiveObject<T>;
27
+ type Node<T extends Object> = ReactiveObject<T>;
28
28
  declare class ReactiveArray<T> extends Array<T> {
29
29
  #private;
30
30
  constructor(data: T[]);
@@ -45,7 +45,7 @@ declare class ReactiveArray<T> extends Array<T> {
45
45
  track(): void;
46
46
  unshift(...items: T[]): number;
47
47
  }
48
- declare class ReactiveObjectArray<T extends Record<PropertyKey, unknown>> extends ReactiveArray<Node<T>> {
48
+ declare class ReactiveObjectArray<T extends Object> extends ReactiveArray<Node<T>> {
49
49
  #private;
50
50
  constructor(data: T[], options?: Options);
51
51
  fill(): never;
@@ -1,4 +1,5 @@
1
- import { Object, Options } from '../types';
1
+ import { Computed, Object, Options, Signal } from '../types';
2
+ import { ReactiveArray, ReactiveObjectArray } from './array';
2
3
  import { ReactiveObject } from './object';
3
4
  type Guard<T> = T extends Object ? {
4
5
  [K in keyof T]: Never<K, Guard<T[K]>>;
@@ -7,5 +8,13 @@ type Infer<T> = T extends (...args: unknown[]) => unknown ? ReturnType<T> : T ex
7
8
  [K in keyof T]: T[K];
8
9
  } : T;
9
10
  type Never<K, V> = K extends keyof ReactiveObject<Object> ? never : V;
10
- declare const _default: <T extends Object>(data: Guard<T>, options?: Options) => { [K_1 in keyof T]: Infer<T[K_1]>; } & ReactiveObject<T> extends infer T_1 ? { [K in keyof T_1]: ({ [K_1 in keyof T]: Infer<T[K_1]>; } & ReactiveObject<T>)[K]; } : never;
11
+ type Node<T> = T extends (...args: unknown[]) => unknown ? Computed<T> : T extends unknown[] ? T extends Object[] ? ReactiveObjectArray<T[0]> : ReactiveArray<T> : Signal<T>;
12
+ type Nodes<T extends Object> = {
13
+ [K in keyof T]: Node<T[K]>;
14
+ };
15
+ declare const _default: <T extends Object>(data: Guard<T>, options?: Options) => { [K_1 in keyof T]: Infer<T[K_1]>; } & Omit<ReactiveObject<T>, "nodes"> & {
16
+ nodes: Nodes<T>;
17
+ } extends infer T_1 ? { [K in keyof T_1]: ({ [K_1 in keyof T]: Infer<T[K_1]>; } & Omit<ReactiveObject<T>, "nodes"> & {
18
+ nodes: Nodes<T>;
19
+ })[K]; } : never;
11
20
  export default _default;
@@ -1,12 +1,7 @@
1
- import { Computed, Options, Signal } from '../types';
1
+ import { Computed, Object, Options, Signal } from '../types';
2
2
  import { ReactiveArray, ReactiveObjectArray } from './array';
3
- type Node<T> = T extends (...args: unknown[]) => unknown ? Computed<T> : T extends unknown[] ? T extends Object[] ? ReactiveObjectArray<T[0]> : ReactiveArray<T> : Signal<T>;
4
- type Nodes<T extends Object> = {
5
- [K in keyof T]: Node<T[K]>;
6
- };
7
- type Object = Record<PropertyKey, unknown>;
8
3
  declare class ReactiveObject<T extends Object> {
9
- nodes: Nodes<T>;
4
+ nodes: Record<PropertyKey, Computed<unknown> | ReactiveObjectArray<Object> | ReactiveArray<unknown> | Signal<unknown>>;
10
5
  constructor(data: T, options?: Options);
11
6
  dispose(): void;
12
7
  reset(): void;
@@ -2,9 +2,9 @@ import { computed, read, signal, write } from '../signal';
2
2
  import { defineProperty, isArray } from '../utilities';
3
3
  import { ReactiveArray, ReactiveObjectArray } from './array';
4
4
  class ReactiveObject {
5
- nodes;
5
+ nodes = {};
6
6
  constructor(data, options = {}) {
7
- let nodes = {};
7
+ let nodes = this.nodes;
8
8
  for (let key in data) {
9
9
  let input = data[key];
10
10
  if (typeof input === 'function') {
@@ -42,7 +42,6 @@ class ReactiveObject {
42
42
  });
43
43
  }
44
44
  }
45
- this.nodes = nodes;
46
45
  }
47
46
  dispose() {
48
47
  let nodes = this.nodes;
package/package.json CHANGED
@@ -16,5 +16,5 @@
16
16
  "prepublishOnly": "npm run build"
17
17
  },
18
18
  "types": "build/index.d.ts",
19
- "version": "0.1.0"
19
+ "version": "0.1.1"
20
20
  }
@@ -1,5 +1,5 @@
1
1
  import { dispose, read, signal, write } from '~/signal';
2
- import { Listener, Options, Signal } from '~/types';
2
+ import { Listener, Object, Options, Signal } from '~/types';
3
3
  import { ReactiveObject } from './object';
4
4
 
5
5
 
@@ -14,10 +14,10 @@ type Events<T> = {
14
14
  unshift: { items: T[] };
15
15
  };
16
16
 
17
- type Node<T extends Record<PropertyKey, unknown>> = ReactiveObject<T>;
17
+ type Node<T extends Object> = ReactiveObject<T>;
18
18
 
19
19
 
20
- function factory<T extends Record<PropertyKey, unknown>>(data: T[], options: Options = {}) {
20
+ function factory<T extends Object>(data: T[], options: Options = {}) {
21
21
  let signals = [];
22
22
 
23
23
  for (let i = 0, n = data.length; i < n; i++) {
@@ -169,7 +169,7 @@ class ReactiveArray<T> extends Array<T> {
169
169
  // REMINDER:
170
170
  // - @ts-ignore flags are supressing a type mismatch error
171
171
  // - Input values are being transformed by this class into nodes
172
- class ReactiveObjectArray<T extends Record<PropertyKey, unknown>> extends ReactiveArray<Node<T>> {
172
+ class ReactiveObjectArray<T extends Object> extends ReactiveArray<Node<T>> {
173
173
  #options: Options;
174
174
 
175
175
 
@@ -1,4 +1,5 @@
1
- import { Object, Options, Prettify } from '~/types';
1
+ import { Computed, Object, Options, Prettify, Signal } from '~/types';
2
+ import { ReactiveArray, ReactiveObjectArray } from './array';
2
3
  import { ReactiveObject } from './object';
3
4
 
4
5
 
@@ -20,7 +21,18 @@ type Infer<T> =
20
21
 
21
22
  type Never<K,V> = K extends keyof ReactiveObject<Object> ? never : V;
22
23
 
24
+ type Node<T> =
25
+ T extends (...args: unknown[]) => unknown
26
+ ? Computed<T>
27
+ : T extends unknown[]
28
+ ? T extends Object[] ? ReactiveObjectArray<T[0]> : ReactiveArray<T>
29
+ : Signal<T>;
30
+
31
+ type Nodes<T extends Object> = { [K in keyof T]: Node<T[K]> };
32
+
23
33
 
24
34
  export default <T extends Object>(data: Guard<T>, options: Options = {}) => {
25
- return new ReactiveObject(data, options) as any as Prettify< { [K in keyof T]: Infer<T[K]> } & ReactiveObject<T> >;
35
+ return new ReactiveObject(data, options) as any as Prettify<
36
+ { [K in keyof T]: Infer<T[K]> } & Omit<ReactiveObject<T>, 'nodes'> & { nodes: Nodes<T> }
37
+ >;
26
38
  };
@@ -1,27 +1,15 @@
1
1
  import { computed, read, signal, write } from '~/signal';
2
- import { Computed, Options, Signal } from '~/types';
2
+ import { Computed, Object, Options, Signal } from '~/types';
3
3
  import { defineProperty, isArray } from '~/utilities';
4
4
  import { ReactiveArray, ReactiveObjectArray } from './array';
5
5
 
6
6
 
7
- type Node<T> =
8
- T extends (...args: unknown[]) => unknown
9
- ? Computed<T>
10
- : T extends unknown[]
11
- ? T extends Object[] ? ReactiveObjectArray<T[0]> : ReactiveArray<T>
12
- : Signal<T>;
13
-
14
- type Nodes<T extends Object> = { [K in keyof T]: Node<T[K]> };
15
-
16
- type Object = Record<PropertyKey, unknown>;
17
-
18
-
19
7
  class ReactiveObject<T extends Object> {
20
- nodes: Nodes<T>;
8
+ nodes: Record<PropertyKey, Computed<unknown> | ReactiveObjectArray<Object> | ReactiveArray<unknown> | Signal<unknown>> = {};
21
9
 
22
10
 
23
11
  constructor(data: T, options: Options = {}) {
24
- let nodes: Object = {};
12
+ let nodes = this.nodes;
25
13
 
26
14
  for (let key in data) {
27
15
  let input = data[key];
@@ -67,8 +55,6 @@ class ReactiveObject<T extends Object> {
67
55
  });
68
56
  }
69
57
  }
70
-
71
- this.nodes = nodes as typeof this.nodes;
72
58
  }
73
59
 
74
60