@esportsplus/reactivity 0.0.27 → 0.0.29

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,7 +1,7 @@
1
1
  import { computed, signal } from '../signal';
2
2
  import { Context } from '../types';
3
3
  type Infer<T> = T extends (...args: unknown[]) => unknown ? ReturnType<T> : T extends Record<PropertyKey, unknown> ? {
4
- [K in keyof T]: Infer<T[K]>;
4
+ [K in keyof T]: T[K];
5
5
  } : T;
6
6
  type Never = {
7
7
  [K in keyof Context]?: never;
@@ -0,0 +1,7 @@
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
+ };
7
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { effect } from './signal';
2
+ import context from './context';
3
+ export default (...args) => context.node({}, effect(...args));
package/build/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
- export * from './api';
1
+ export { default as effect } from './effect';
2
+ export { default as macro } from './macro';
3
+ export { default as promise } from './promise';
2
4
  export * as core from './signal';
5
+ export { root } from './signal';
6
+ export { default as reactive } from './reactive';
3
7
  export { DISPOSE, RESET, UPDATE } from './symbols';
package/build/index.js CHANGED
@@ -1,3 +1,7 @@
1
- export * from './api';
1
+ export { default as effect } from './effect';
2
+ export { default as macro } from './macro';
3
+ export { default as promise } from './promise';
2
4
  export * as core from './signal';
5
+ export { root } from './signal';
6
+ export { default as reactive } from './reactive';
3
7
  export { DISPOSE, RESET, UPDATE } from './symbols';
@@ -0,0 +1,9 @@
1
+ import { computed } from './signal';
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]) => {
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
+ };
9
+ export default _default;
package/build/macro.js ADDED
@@ -0,0 +1,8 @@
1
+ import { computed, read } from './signal';
2
+ import context from './context';
3
+ export default (fn, options = {}) => {
4
+ let node = computed(fn, options);
5
+ return context.node((...args) => {
6
+ return read(node)(...args);
7
+ }, node);
8
+ };
@@ -0,0 +1,8 @@
1
+ import { computed } from './signal';
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
+ };
8
+ export default _default;
@@ -0,0 +1,38 @@
1
+ import { read, root, signal, write } from './signal';
2
+ import context from './context';
3
+ export default (fn, options = {}) => {
4
+ let input, nodes = {
5
+ data: signal(options?.value, options),
6
+ status: signal(undefined, options)
7
+ };
8
+ function host(...args) {
9
+ input = args;
10
+ root(() => {
11
+ fn(...args)
12
+ .then((value) => {
13
+ write(nodes.data, value);
14
+ })
15
+ .catch(() => {
16
+ write(nodes.data, undefined);
17
+ });
18
+ });
19
+ }
20
+ Object.defineProperties(host, {
21
+ data: {
22
+ get() {
23
+ return read(nodes.data);
24
+ }
25
+ },
26
+ input: {
27
+ get() {
28
+ return input;
29
+ }
30
+ },
31
+ status: {
32
+ get() {
33
+ return read(nodes.status);
34
+ }
35
+ }
36
+ });
37
+ return context.nodes(host, nodes);
38
+ };
@@ -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]: 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;
@@ -0,0 +1,27 @@
1
+ import { computed, read, signal, write } from './signal';
2
+ import context from './context';
3
+ export default (data, options = {}) => {
4
+ let host = {}, nodes = {};
5
+ for (let key in data) {
6
+ if (typeof data[key] === 'function') {
7
+ nodes[key] = computed(data[key], options);
8
+ Object.defineProperty(host, key, {
9
+ get() {
10
+ return read(nodes[key]);
11
+ }
12
+ });
13
+ }
14
+ else {
15
+ nodes[key] = signal(data[key], options);
16
+ Object.defineProperty(host, key, {
17
+ get() {
18
+ return read(nodes[key]);
19
+ },
20
+ set(data) {
21
+ write(nodes[key], data);
22
+ }
23
+ });
24
+ }
25
+ }
26
+ return context.nodes(host, nodes);
27
+ };
package/package.json CHANGED
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "author": "ICJR",
3
- "description": "Reactivity",
4
3
  "devDependencies": {
5
4
  "@esportsplus/rspack": "^0.0.15"
6
5
  },
@@ -14,5 +13,5 @@
14
13
  "prepublishOnly": "npm run build"
15
14
  },
16
15
  "types": "build/index.d.ts",
17
- "version": "0.0.27"
16
+ "version": "0.0.29"
18
17
  }
package/src/effect.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { effect } from './signal';
2
+ import context from './context';
3
+
4
+
5
+ export default (...args: Parameters<typeof effect>) => context.node({}, effect(...args));
package/src/index.ts CHANGED
@@ -1,3 +1,7 @@
1
- export * from './api';
1
+ export { default as effect } from './effect';
2
+ export { default as macro } from './macro';
3
+ export { default as promise } from './promise';
2
4
  export * as core from './signal';
5
+ export { root } from './signal';
6
+ export { default as reactive } from './reactive';
3
7
  export { DISPOSE, RESET, UPDATE } from './symbols';
@@ -1,6 +1,6 @@
1
- import { computed, read } from '~/signal';
2
- import { Computed } from '~/types';
3
- import context from '~/context';
1
+ import { computed, read } from './signal';
2
+ import { Computed } from './types';
3
+ import context from './context';
4
4
 
5
5
 
6
6
  export default <T extends <A, R>(...args: A[]) => R>(fn: Computed<T>['fn'], options: Parameters<typeof computed>[1] = {}) => {
@@ -1,5 +1,5 @@
1
- import { computed, read, root, signal, write } from '~/signal';
2
- import context from '~/context';
1
+ import { computed, read, root, signal, write } from './signal';
2
+ import context from './context';
3
3
 
4
4
 
5
5
  // TODO:
@@ -1,13 +1,13 @@
1
- import { computed, read, signal, write } from '~/signal';
2
- import { Context, Signal } from '~/types';
3
- import context from '~/context';
1
+ import { computed, read, signal, write } from './signal';
2
+ import { Context, Signal } from './types';
3
+ import context from './context';
4
4
 
5
5
 
6
6
  type Infer<T> =
7
7
  T extends (...args: unknown[]) => unknown
8
8
  ? ReturnType<T>
9
9
  : T extends Record<PropertyKey, unknown>
10
- ? { [K in keyof T]: Infer<T[K]> }
10
+ ? { [K in keyof T]: T[K] }
11
11
  : T;
12
12
 
13
13
  type Never = { [K in keyof Context]?: never };
package/src/api/effect.ts DELETED
@@ -1,5 +0,0 @@
1
- import { effect } from '~/signal';
2
- import context from '~/context';
3
-
4
-
5
- export default (...args: Parameters<typeof effect>) => context.node({}, effect(...args));
package/src/api/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export { default as effect } from './effect';
2
- export { default as macro } from './macro';
3
- export { default as promise } from './promise';
4
- export { default as store } from './store';