@esportsplus/reactivity 0.0.24 → 0.0.26

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,2 +1,7 @@
1
- declare const _default: (fn: (this: import("../types").Context, previous: unknown) => unknown, options?: import("../types").Options | undefined) => Required<Partial<import("../types").Context>>;
1
+ declare const _default: (fn: (this: import("../types").Context, previous: unknown) => unknown, options?: import("../types").Options | undefined) => {
2
+ dispose: () => void;
3
+ on: (event: symbol, listener: import("../types").Listener) => void;
4
+ once: (event: symbol, listener: import("../types").Listener) => void;
5
+ reset: () => void;
6
+ };
2
7
  export default _default;
@@ -1,4 +1,4 @@
1
1
  export { default as effect } from './effect';
2
2
  export { default as macro } from './macro';
3
3
  export { default as promise } from './promise';
4
- export { default as reactive } from './reactive';
4
+ export { default as store } from './store';
@@ -1,4 +1,4 @@
1
1
  export { default as effect } from './effect';
2
2
  export { default as macro } from './macro';
3
3
  export { default as promise } from './promise';
4
- export { default as reactive } from './reactive';
4
+ export { default as store } from './store';
@@ -1,4 +1,9 @@
1
1
  import { computed } from '../signal';
2
2
  import { Computed } from '../types';
3
- declare const _default: <T extends <A, R>(...args: A[]) => R>(fn: T extends Promise<unknown> ? never : (this: import("../types").Context, previous: T) => T, options?: Parameters<typeof computed>[1]) => Required<((...args: Parameters<ReturnType<T extends Promise<unknown> ? never : (this: import("../types").Context, previous: T) => T>>) => unknown) & Partial<import("../types").Context>>;
3
+ declare const _default: <T extends <A, R>(...args: A[]) => R>(fn: T extends Promise<unknown> ? never : (this: import("../types").Context, previous: T) => T, options?: Parameters<typeof computed>[1]) => {
4
+ dispose: () => void;
5
+ on: (event: symbol, listener: import("../types").Listener) => void;
6
+ once: (event: symbol, listener: import("../types").Listener) => void;
7
+ reset: () => void;
8
+ };
4
9
  export default _default;
@@ -1,3 +1,8 @@
1
1
  import { computed } from '../signal';
2
- declare const _default: (fn: <A, R extends Promise<any>>(...args: A[]) => R, options?: Parameters<typeof computed>[1]) => Required<((this: any, ...args: unknown[]) => void) & Partial<import("../types").Context>>;
2
+ declare const _default: (fn: <A, R extends Promise<any>>(...args: A[]) => R, options?: Parameters<typeof computed>[1]) => {
3
+ dispose: () => void;
4
+ on: (event: symbol, listener: import("../types").Listener) => void;
5
+ once: (event: symbol, listener: import("../types").Listener) => void;
6
+ reset: () => void;
7
+ };
3
8
  export default _default;
@@ -0,0 +1,11 @@
1
+ import { computed, signal } from '../signal';
2
+ import { Context } from '../types';
3
+ type Infer<T> = T extends (...args: unknown[]) => unknown ? ReturnType<T> : T extends Record<PropertyKey, unknown> ? {
4
+ [K in keyof T]: Infer<T[K]>;
5
+ } : T;
6
+ type Never = {
7
+ [K in keyof Context]?: never;
8
+ };
9
+ type Options = Parameters<typeof computed>[1] | Parameters<typeof signal>[1];
10
+ declare const _default: <T extends Record<PropertyKey, unknown>>(data: T & Never, options?: Options) => Required<Infer<T> & Context & Partial<Context>> extends infer T_1 ? { [K in keyof T_1]: Required<Infer<T> & Context & Partial<Context>>[K]; } : never;
11
+ export default _default;
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- node: <T>(host: T & Partial<import("../types").Context>, node: import("../signal").default<any>) => Required<T & Partial<import("../types").Context>>;
3
- nodes: <T_1>(host: T_1 & Partial<import("../types").Context>, nodes: Record<PropertyKey, import("../signal").default<any>>) => Required<T_1 & Partial<import("../types").Context>>;
2
+ node: <T>(host: T & Partial<import("../types").Context>, node: import("../signal").default<any>) => Required<T & Partial<import("../types").Context>> extends infer T_1 ? { [K in keyof T_1]: Required<T & Partial<import("../types").Context>>[K]; } : never;
3
+ nodes: <T_2>(host: T_2 & Partial<import("../types").Context>, nodes: Record<PropertyKey, import("../signal").default<any>>) => Required<T_2 & Partial<import("../types").Context>> extends infer T_3 ? { [K_1 in keyof T_3]: Required<T_2 & Partial<import("../types").Context>>[K_1]; } : never;
4
4
  };
5
5
  export default _default;
@@ -3,5 +3,5 @@ import { Context, Signal } from '../types';
3
3
  type Internals = {
4
4
  [NODE]: Signal<any>;
5
5
  };
6
- declare const _default: <T>(host: T & Partial<Context>, node: Internals[typeof NODE]) => Required<T & Partial<Context>>;
6
+ declare const _default: <T>(host: T & Partial<Context>, node: Internals[typeof NODE]) => Required<T & Partial<Context>> extends infer T_1 ? { [K in keyof T_1]: Required<T & Partial<Context>>[K]; } : never;
7
7
  export default _default;
@@ -3,5 +3,5 @@ import { Context, Signal } from '../types';
3
3
  type Internals = {
4
4
  [NODES]: Record<PropertyKey, Signal<any>>;
5
5
  };
6
- declare const _default: <T>(host: T & Partial<Context>, nodes: Internals[typeof NODES]) => Required<T & Partial<Context>>;
6
+ declare const _default: <T>(host: T & Partial<Context>, nodes: Internals[typeof NODES]) => Required<T & Partial<Context>> extends infer T_1 ? { [K in keyof T_1]: Required<T & Partial<Context>>[K]; } : never;
7
7
  export default _default;
package/build/signal.js CHANGED
@@ -204,7 +204,7 @@ const effect = (fn, options = {}) => {
204
204
  node.fn = fn;
205
205
  node.root = scope;
206
206
  node.task = () => read(node);
207
- update(node);
207
+ node.root.scheduler(node.task);
208
208
  return node;
209
209
  };
210
210
  const read = (node) => {
package/build/types.d.ts CHANGED
@@ -17,9 +17,6 @@ type Effect<T> = {
17
17
  task: NonNullable<Signal<T>['task']>;
18
18
  } & Omit<Computed<T>, 'fn' | 'root' | 'task'>;
19
19
  type Event = symbol;
20
- type Infer<T> = T extends (...args: any[]) => any ? ReturnType<T> : T extends Record<PropertyKey, unknown> ? {
21
- [K in keyof T]: Infer<T[K]>;
22
- } : T;
23
20
  type Listener = {
24
21
  once?: boolean;
25
22
  <T>(value: T): void;
@@ -30,7 +27,10 @@ type Options = {
30
27
  type Root = {
31
28
  scheduler: Scheduler;
32
29
  };
30
+ type Prettify<T> = {
31
+ [K in keyof T]: T[K];
32
+ } & {};
33
33
  type Scheduler = (fn: (...args: unknown[]) => Promise<unknown> | unknown) => unknown;
34
34
  type State = typeof CHECK | typeof CLEAN | typeof DIRTY | typeof DISPOSED;
35
35
  type Type = typeof COMPUTED | typeof EFFECT | typeof SIGNAL;
36
- export { Changed, Computed, Context, Effect, Event, Infer, Listener, Options, Root, Scheduler, Signal, State, Type };
36
+ export { Changed, Computed, Context, Effect, Event, Listener, Options, Prettify, Root, Scheduler, Signal, State, Type };
package/package.json CHANGED
@@ -14,5 +14,5 @@
14
14
  "prepublishOnly": "npm run build"
15
15
  },
16
16
  "types": "build/index.d.ts",
17
- "version": "0.0.24"
17
+ "version": "0.0.26"
18
18
  }
package/src/api/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { default as effect } from './effect';
2
2
  export { default as macro } from './macro';
3
3
  export { default as promise } from './promise';
4
- export { default as reactive } from './reactive';
4
+ export { default as store } from './store';
@@ -2,6 +2,9 @@ import { computed, read, root, signal, write } from '~/signal';
2
2
  import context from '~/context';
3
3
 
4
4
 
5
+ // TODO:
6
+ // - Add status value
7
+ // - Add reject/stop method
5
8
  export default (fn: <A, R extends Promise<any>>(...args: A[]) => R, options: Parameters<typeof computed>[1] = {}) => {
6
9
  let input: unknown,
7
10
  nodes = {
@@ -1,22 +1,27 @@
1
1
  import { computed, read, signal, write } from '~/signal';
2
- import { Computed, Context, Infer, Signal } from '~/types';
2
+ import { Context, Signal } from '~/types';
3
3
  import context from '~/context';
4
4
 
5
5
 
6
- type Data = {
7
- [key in keyof Context]: never
8
- } & Record<PropertyKey, Parameters<typeof computed>[0] | Parameters<typeof signal>[0]>;
6
+ type Infer<T> =
7
+ T extends (...args: unknown[]) => unknown
8
+ ? ReturnType<T>
9
+ : T extends Record<PropertyKey, unknown>
10
+ ? { [K in keyof T]: Infer<T[K]> }
11
+ : T;
12
+
13
+ type Never = { [K in keyof Context]?: never };
9
14
 
10
15
  type Options = Parameters<typeof computed>[1] | Parameters<typeof signal>[1];
11
16
 
12
17
 
13
- export default <T>(data: Data, options: Options = {}) => {
18
+ export default <T extends Record<PropertyKey, unknown>>(data: T & Never, options: Options = {}) => {
14
19
  let host = {},
15
- nodes: Record<PropertyKey, Signal<any>> = {};
20
+ nodes: Record<PropertyKey, Signal<unknown>> = {};
16
21
 
17
- for (let key in data) {
22
+ for (let key in (data as T)) {
18
23
  if (typeof data[key] === 'function') {
19
- nodes[key] = computed(data[key] as Computed<T>['fn'], options);
24
+ nodes[key] = computed(data[key] as Parameters<typeof computed>[0], options);
20
25
 
21
26
  Object.defineProperty(host, key, {
22
27
  get() {
@@ -38,5 +43,5 @@ export default <T>(data: Data, options: Options = {}) => {
38
43
  }
39
44
  }
40
45
 
41
- return context.nodes(host as Infer<typeof data>, nodes);
46
+ return context.nodes(host as Infer<T> & Context, nodes);
42
47
  };
@@ -1,5 +1,5 @@
1
1
  import { NODE } from '~/symbols';
2
- import { Context, Event, Listener, Signal } from '~/types';
2
+ import { Context, Event, Listener, Prettify, Signal } from '~/types';
3
3
 
4
4
 
5
5
  type Internals = {
@@ -32,5 +32,5 @@ export default <T>(host: T & Partial<Context>, node: Internals[typeof NODE]) =>
32
32
  host.once = once;
33
33
  host.reset = reset;
34
34
 
35
- return host as Required<typeof host>;
35
+ return host as Prettify< Required<typeof host> >;
36
36
  };
@@ -1,5 +1,5 @@
1
1
  import { NODES } from '~/symbols';
2
- import { Context, Event, Listener, Signal } from '~/types';
2
+ import { Context, Event, Listener, Prettify, Signal } from '~/types';
3
3
 
4
4
 
5
5
  type Internals = {
@@ -48,5 +48,5 @@ export default <T>(host: T & Partial<Context>, nodes: Internals[typeof NODES]) =
48
48
  host.once = once;
49
49
  host.reset = reset;
50
50
 
51
- return host as Required<typeof host>;
51
+ return host as Prettify< Required<typeof host> >;
52
52
  };
package/src/signal.ts CHANGED
@@ -274,7 +274,7 @@ const effect = <T>(fn: Effect<T>['fn'], options: Options = {}) => {
274
274
  node.root = scope;
275
275
  node.task = () => read(node);
276
276
 
277
- update(node);
277
+ node.root.scheduler(node.task);
278
278
 
279
279
  return node as Effect<void>;
280
280
  };
package/src/types.ts CHANGED
@@ -24,13 +24,6 @@ type Effect<T> = {
24
24
 
25
25
  type Event = symbol;
26
26
 
27
- type Infer<T> =
28
- T extends (...args: any[]) => any
29
- ? ReturnType<T>
30
- : T extends Record<PropertyKey, unknown>
31
- ? { [K in keyof T]: Infer<T[K]> }
32
- : T;
33
-
34
27
  type Listener = {
35
28
  once?: boolean;
36
29
 
@@ -45,6 +38,10 @@ type Root = {
45
38
  scheduler: Scheduler
46
39
  };
47
40
 
41
+ type Prettify<T> = {
42
+ [K in keyof T]: T[K];
43
+ } & {};
44
+
48
45
  type Scheduler = (fn: (...args: unknown[]) => Promise<unknown> | unknown) => unknown;
49
46
 
50
47
  type State = typeof CHECK | typeof CLEAN | typeof DIRTY | typeof DISPOSED;
@@ -52,4 +49,4 @@ type State = typeof CHECK | typeof CLEAN | typeof DIRTY | typeof DISPOSED;
52
49
  type Type = typeof COMPUTED | typeof EFFECT | typeof SIGNAL;
53
50
 
54
51
 
55
- export { Changed, Computed, Context, Effect, Event, Infer, Listener, Options, Root, Scheduler, Signal, State, Type };
52
+ export { Changed, Computed, Context, Effect, Event, Listener, Options, Prettify, Root, Scheduler, Signal, State, Type };
@@ -1,16 +0,0 @@
1
- import { computed, signal } from '../signal';
2
- import { Context } from '../types';
3
- type Data = {
4
- [key in keyof Context]: never;
5
- } & Record<PropertyKey, Parameters<typeof computed>[0] | Parameters<typeof signal>[0]>;
6
- type Options = Parameters<typeof computed>[1] | Parameters<typeof signal>[1];
7
- declare const _default: <T>(data: Data, options?: Options) => Required<{
8
- [x: string]: unknown;
9
- [x: number]: unknown;
10
- [x: symbol]: unknown;
11
- dispose: never;
12
- on: never;
13
- once: never;
14
- reset: never;
15
- } & Partial<Context>>;
16
- export default _default;
File without changes