@esportsplus/reactivity 0.2.0 → 0.2.2

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,5 +1,5 @@
1
+ import { isInstanceOf, isNumber, isObject } from '@esportsplus/utilities';
1
2
  import { dispose, signal, Reactive } from '../signal';
2
- import { isInstanceOf, isNumber, isObject } from '../utilities';
3
3
  import { ReactiveObject } from './object';
4
4
  let handler = {
5
5
  get(target, prop) {
@@ -4,7 +4,7 @@ import { ReactiveArray } from './array';
4
4
  import { ReactiveObject } from './object';
5
5
  type Guard<T> = T extends Record<PropertyKey, unknown> ? {
6
6
  [K in keyof T]: Never<K, Guard<T[K]>>;
7
- } : T extends unknown[] ? T : never;
7
+ } : T extends unknown[] ? T : T extends Function ? never : T;
8
8
  type Infer<T> = T extends (...args: unknown[]) => unknown ? ReturnType<T> : T extends (infer U)[] ? Prettify<Omit<U[], 'map'> & Pick<ReactiveArray<U>, 'dispatch' | 'dispose' | 'map' | 'on' | 'once'>> : T extends Record<PropertyKey, unknown> ? {
9
9
  [K in keyof T]: T[K];
10
10
  } : T;
@@ -1,6 +1,6 @@
1
+ import { isArray, isObject } from '@esportsplus/utilities';
1
2
  import { default as array } from './array';
2
3
  import { default as object } from './object';
3
- import { isArray, isObject } from '../utilities';
4
4
  export default (data, options = {}) => {
5
5
  let value;
6
6
  if (isArray(data)) {
@@ -10,7 +10,7 @@ export default (data, options = {}) => {
10
10
  value = object(data, options);
11
11
  }
12
12
  else {
13
- throw new Error('Reactivity: received invalid input for `reactive()`', data);
13
+ throw new Error(`Reactivity: 'reactive' received invalid input - ${JSON.stringify(data)}`);
14
14
  }
15
15
  return value;
16
16
  };
@@ -1,5 +1,5 @@
1
+ import { defineProperty, isArray, isFunction } from '@esportsplus/utilities';
1
2
  import { computed, signal } from '../signal';
2
- import { defineProperty, isArray, isFunction } from '../utilities';
3
3
  import { default as array } from './array';
4
4
  class ReactiveObject {
5
5
  signals = {};
package/build/signal.js CHANGED
@@ -1,5 +1,5 @@
1
+ import { isArray } from '@esportsplus/utilities';
1
2
  import { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, ROOT, SIGNAL } from './constants';
2
- import { isArray } from './utilities';
3
3
  let index = 0, observer = null, observers = null, scope = null;
4
4
  class Reactive {
5
5
  changed = null;
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "author": "ICJR",
3
3
  "dependencies": {
4
- "@esportsplus/custom-function": "^0.0.7"
4
+ "@esportsplus/custom-function": "^0.0.7",
5
+ "@esportsplus/utilities": "^0.0.7"
5
6
  },
6
7
  "devDependencies": {
7
8
  "@esportsplus/typescript": "^0.4.9"
@@ -16,5 +17,5 @@
16
17
  "prepublishOnly": "npm run build"
17
18
  },
18
19
  "types": "build/index.d.ts",
19
- "version": "0.2.0"
20
+ "version": "0.2.2"
20
21
  }
@@ -1,6 +1,6 @@
1
+ import { isInstanceOf, isNumber, isObject } from '@esportsplus/utilities';
1
2
  import { dispose, signal, Reactive } from '~/signal';
2
3
  import { Listener, Options, Signal } from '~/types';
3
- import { isInstanceOf, isNumber, isObject } from '~/utilities';
4
4
  import { ReactiveObject } from './object';
5
5
 
6
6
 
@@ -1,8 +1,8 @@
1
1
  import { Prettify } from '@esportsplus/typescript';
2
+ import { isArray, isObject } from '@esportsplus/utilities';
2
3
  import { Options } from '~/types';
3
4
  import { default as array, ReactiveArray } from './array';
4
5
  import { default as object, ReactiveObject } from './object';
5
- import { isArray, isObject } from '~/utilities';
6
6
 
7
7
 
8
8
  type Guard<T> =
@@ -10,7 +10,9 @@ type Guard<T> =
10
10
  ? { [K in keyof T]: Never<K, Guard<T[K]>> }
11
11
  : T extends unknown[]
12
12
  ? T
13
- : never;
13
+ : T extends Function
14
+ ? never
15
+ : T;
14
16
 
15
17
  type Infer<T> =
16
18
  T extends (...args: unknown[]) => unknown
@@ -34,7 +36,7 @@ export default <T>(data: Guard<T>, options: Options = {}) => {
34
36
  value = object(data as { [K in keyof T]: T[K] }, options);
35
37
  }
36
38
  else {
37
- throw new Error('Reactivity: received invalid input for `reactive()`', data);
39
+ throw new Error(`Reactivity: 'reactive' received invalid input - ${JSON.stringify(data)}`);
38
40
  }
39
41
 
40
42
  return value as T extends Record<PropertyKey, unknown> ? { [K in keyof T]: Infer<T[K]> } : Infer<T>;
@@ -1,6 +1,6 @@
1
+ import { defineProperty, isArray, isFunction } from '@esportsplus/utilities';
1
2
  import { computed, signal } from '~/signal';
2
3
  import { Computed, Options, Signal } from '~/types';
3
- import { defineProperty, isArray, isFunction } from '~/utilities';
4
4
  import { default as array, ReactiveArray } from './array';
5
5
 
6
6
 
package/src/signal.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import { isArray } from '@esportsplus/utilities';
1
2
  import { CHECK, CLEAN, COMPUTED, DIRTY, DISPOSED, EFFECT, ROOT, SIGNAL } from './constants';
2
3
  import { Computed, Changed, Effect, Event, Function, Listener, NeverAsync, Options, Root, Scheduler, Signal, State, Type } from './types';
3
- import { isArray } from './utilities';
4
4
 
5
5
 
6
6
  let index = 0,
@@ -1,8 +0,0 @@
1
- declare const defineProperty: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T;
2
- declare const isArray: (arg: any) => arg is any[];
3
- declare const isFunction: (value: unknown) => value is Function;
4
- declare const isInstanceOf: <T>(instance: unknown, match: new (...args: any) => T) => instance is T;
5
- declare const isNumber: (value: any) => value is number;
6
- declare const isObject: (value: unknown) => value is Record<PropertyKey, unknown>;
7
- declare const isString: (value: unknown) => value is string;
8
- export { defineProperty, isArray, isFunction, isInstanceOf, isNumber, isObject, isString };
@@ -1,18 +0,0 @@
1
- const { defineProperty } = Object;
2
- const { isArray } = Array;
3
- const isFunction = (value) => {
4
- return typeof value === 'function';
5
- };
6
- const isInstanceOf = (instance, match) => {
7
- return typeof instance === 'object' && instance !== null && instance.constructor === match;
8
- };
9
- const isNumber = (value) => {
10
- return !isNaN(value);
11
- };
12
- const isObject = (value) => {
13
- return typeof value === 'object' && value !== null && value.constructor === Object;
14
- };
15
- const isString = (value) => {
16
- return typeof value === 'string';
17
- };
18
- export { defineProperty, isArray, isFunction, isInstanceOf, isNumber, isObject, isString };
package/src/utilities.ts DELETED
@@ -1,26 +0,0 @@
1
- const { defineProperty } = Object;
2
-
3
- const { isArray } = Array;
4
-
5
- const isFunction = (value: unknown): value is Function => {
6
- return typeof value === 'function';
7
- };
8
-
9
- const isInstanceOf = <T>(instance: unknown, match: new (...args: any) => T): instance is T => {
10
- return typeof instance === 'object' && instance !== null && instance.constructor === match;
11
- };
12
-
13
- const isNumber = (value: any): value is number => {
14
- return !isNaN(value);
15
- };
16
-
17
- const isObject = (value: unknown): value is Record<PropertyKey, unknown> => {
18
- return typeof value === 'object' && value !== null && value.constructor === Object;
19
- };
20
-
21
- const isString = (value: unknown): value is string => {
22
- return typeof value === 'string';
23
- };
24
-
25
-
26
- export { defineProperty, isArray, isFunction, isInstanceOf, isNumber, isObject, isString };