@esportsplus/reactivity 0.1.6 → 0.1.8

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.
package/build/signal.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Changed, Computed, Effect, Event, Listener, Options, Root, Scheduler, State, SyncFunction, Type } from './types';
1
+ import { Changed, Computed, Effect, Event, Listener, NeverAsync, Options, Root, Scheduler, State, Type } from './types';
2
2
  declare class Signal<T> {
3
3
  changed: Changed | null;
4
4
  fn: Computed<T>['fn'] | Effect['fn'] | null;
@@ -18,7 +18,7 @@ declare class Signal<T> {
18
18
  once(event: Event, listener: Listener<any>): void;
19
19
  reset(): void;
20
20
  }
21
- declare const computed: <T>(fn: ((previous: T) => T) extends infer T_1 ? T_1 extends (previous: T) => T ? T_1 extends (...args: unknown[]) => unknown ? SyncFunction<((previous: T) => T) extends infer T_2 ? T_2 extends (previous: T) => T ? T_2 extends (...args: unknown[]) => unknown ? ReturnType<T_2> : T_2 : never : never, (((previous: T) => T) extends infer T_2 ? T_2 extends (previous: T) => T ? T_2 extends (...args: unknown[]) => unknown ? ReturnType<T_2> : T_2 : never : never) extends infer T_3 ? T_3 extends (((previous: T) => T) extends infer T_2 ? T_2 extends (previous: T) => T ? T_2 extends (...args: unknown[]) => unknown ? ReturnType<T_2> : T_2 : never : never) ? T_3 extends (...args: unknown[]) => unknown ? ReturnType<T_3> : T_3 : never : never> extends never ? never : T_1 : T_1 : never : never, options?: Options) => Computed<T>;
21
+ declare const computed: <T>(fn: ((previous: T) => T) extends infer T_1 ? T_1 extends (previous: T) => T ? T_1 extends (...args: unknown[]) => unknown ? (...args: Parameters<T_1>) => ReturnType<T_1> extends NeverAsync<T_1> ? NeverAsync<T_1> & ReturnType<T_1> : NeverAsync<ReturnType<T_1>> : T_1 : never : never, options?: Options) => Computed<T>;
22
22
  declare const dispose: <T extends {
23
23
  dispose: () => void;
24
24
  }>(dispose?: T | T[] | undefined) => T | T[] | undefined;
@@ -27,7 +27,7 @@ declare const read: <T>(node: Signal<T>) => T;
27
27
  declare const reset: <T extends {
28
28
  reset: () => void;
29
29
  }>(reset?: T | T[] | undefined) => T | T[] | undefined;
30
- declare const root: <T>(fn: SyncFunction<T, T extends (...args: unknown[]) => unknown ? ReturnType<T> : T> extends never ? never : () => T, properties?: Root) => T;
30
+ declare function root<T>(fn: NeverAsync<() => T>, properties?: Root): T extends () => T extends any ? T : NeverAsync<T> ? T : NeverAsync<T>;
31
31
  declare const signal: <T>(data: T, options?: Omit<Options, 'value'>) => Signal<T>;
32
32
  declare const write: <T>(node: Signal<T>, value: unknown) => T;
33
33
  export default Signal;
package/build/signal.js CHANGED
@@ -266,7 +266,7 @@ const reset = (reset) => {
266
266
  }
267
267
  return reset;
268
268
  };
269
- const root = (fn, properties) => {
269
+ function root(fn, properties) {
270
270
  let o = observer, s = scope;
271
271
  if (properties === undefined) {
272
272
  if (scope === null) {
@@ -280,7 +280,8 @@ const root = (fn, properties) => {
280
280
  observer = o;
281
281
  scope = s;
282
282
  return result;
283
- };
283
+ }
284
+ ;
284
285
  const signal = (data, options = {}) => {
285
286
  return new Signal(data, CLEAN, SIGNAL, options);
286
287
  };
package/build/types.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { Function, Prettify, SyncFunction } from '@esportsplus/typescript';
1
+ import { Function, NeverAsync, Prettify } from '@esportsplus/typescript';
2
2
  import { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, SIGNAL } from './constants';
3
3
  import Signal from './signal';
4
4
  type Changed = (a: unknown, b: unknown) => boolean;
5
5
  type Computed<T> = {
6
- fn: SyncFunction<(previous: T) => T>;
6
+ fn: NeverAsync<(previous: T) => T>;
7
7
  } & Omit<Signal<T>, 'fn'>;
8
8
  type Effect = {
9
- fn: SyncFunction<(node: Effect) => void>;
9
+ fn: NeverAsync<(node: Effect) => void>;
10
10
  root: Root;
11
11
  task: Function;
12
12
  value: void;
@@ -30,4 +30,4 @@ type Root = {
30
30
  type Scheduler = (fn: Function) => unknown;
31
31
  type State = typeof CHECK | typeof CLEAN | typeof DIRTY | typeof DISPOSED;
32
32
  type Type = typeof COMPUTED | typeof EFFECT | typeof SIGNAL;
33
- export { Changed, Computed, Effect, Event, Listener, Object, Options, Prettify, Root, Scheduler, Signal, State, SyncFunction, Type };
33
+ export { Changed, Computed, Effect, Event, Listener, Object, Options, NeverAsync, Prettify, Root, Scheduler, Signal, State, Type };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "@esportsplus/custom-function": "^0.0.1"
5
5
  },
6
6
  "devDependencies": {
7
- "@esportsplus/typescript": "^0.0.6"
7
+ "@esportsplus/typescript": "^0.0.9"
8
8
  },
9
9
  "main": "build/index.js",
10
10
  "name": "@esportsplus/reactivity",
@@ -16,5 +16,5 @@
16
16
  "prepublishOnly": "npm run build"
17
17
  },
18
18
  "types": "build/index.d.ts",
19
- "version": "0.1.6"
19
+ "version": "0.1.8"
20
20
  }
package/src/macro.ts CHANGED
@@ -7,7 +7,7 @@ type Function<A extends unknown[], R> = Computed<(...args: A) => R>['fn'];
7
7
 
8
8
 
9
9
  class Macro<A extends unknown[], R> extends CustomFunction {
10
- #factory: Computed< ReturnType<Function<A,R>> >;
10
+ #factory: Computed<(...args: A) => R>;
11
11
 
12
12
 
13
13
  constructor(fn: Function<A,R>, options: Options = {}) {
package/src/signal.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, SIGNAL } from './constants';
2
- import { Changed, Computed, Effect, Event, Listener, Options, Root, Scheduler, State, SyncFunction, Type } from './types';
2
+ import { Changed, Computed, Effect, Event, Listener, NeverAsync, Options, Root, Scheduler, State, Type } from './types';
3
3
  import { isArray } from './utilities';
4
4
 
5
5
 
@@ -208,9 +208,8 @@ function update<T>(node: Signal<T>) {
208
208
  node.dispatch('update');
209
209
  node.updating = true;
210
210
 
211
- let value = (
212
- node as typeof node extends Effect ? Effect : Computed<T>
213
- ).fn.call(node, node.value);
211
+ // @ts-ignore
212
+ let value = node.fn.call(node, node.value);
214
213
 
215
214
  node.updating = null;
216
215
 
@@ -348,7 +347,7 @@ const reset = <T extends { reset: () => void }>(reset?: T[] | T) => {
348
347
  return reset;
349
348
  };
350
349
 
351
- const root = <T>(fn: SyncFunction<() => T>, properties?: Root) => {
350
+ function root<T>(fn: NeverAsync<() => T>, properties?: Root) {
352
351
  let o = observer,
353
352
  s = scope;
354
353
 
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Function, Prettify, SyncFunction } from '@esportsplus/typescript'
1
+ import { Function, NeverAsync, Prettify } from '@esportsplus/typescript'
2
2
  import { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, SIGNAL } from './constants';
3
3
  import Signal from './signal';
4
4
 
@@ -6,11 +6,11 @@ import Signal from './signal';
6
6
  type Changed = (a: unknown, b: unknown) => boolean;
7
7
 
8
8
  type Computed<T> = {
9
- fn: SyncFunction<(previous: T) => T>;
9
+ fn: NeverAsync<(previous: T) => T>;
10
10
  } & Omit<Signal<T>, 'fn'>;
11
11
 
12
12
  type Effect = {
13
- fn: SyncFunction<(node: Effect) => void>;
13
+ fn: NeverAsync<(node: Effect) => void>;
14
14
  root: Root;
15
15
  task: Function
16
16
  value: void;
@@ -42,4 +42,4 @@ type State = typeof CHECK | typeof CLEAN | typeof DIRTY | typeof DISPOSED;
42
42
  type Type = typeof COMPUTED | typeof EFFECT | typeof SIGNAL;
43
43
 
44
44
 
45
- export { Changed, Computed, Effect, Event, Listener, Object, Options, Prettify, Root, Scheduler, Signal, State, SyncFunction, Type };
45
+ export { Changed, Computed, Effect, Event, Listener, Object, Options, NeverAsync, Prettify, Root, Scheduler, Signal, State, Type };