@vorplex/core 0.0.47 → 0.0.50
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/modules/logging/task.js +5 -3
- package/dist/modules/state/reducer.type.d.ts +30 -0
- package/dist/modules/state/reducer.type.js +0 -0
- package/dist/modules/state/state.model.d.ts +3 -22
- package/dist/modules/state/state.model.js +5 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export * from './modules/reflection/types/type.type';
|
|
|
56
56
|
export * from './modules/reflection/utils/decorator.util';
|
|
57
57
|
export * from './modules/reflection/utils/reflection.util';
|
|
58
58
|
export * from './modules/router/router.util';
|
|
59
|
+
export * from './modules/state/reducer.type';
|
|
59
60
|
export * from './modules/state/state.model';
|
|
60
61
|
export * from './modules/state/update.type';
|
|
61
62
|
export * from './modules/state/adaptors/array/array-adaptor.util';
|
package/dist/index.js
CHANGED
|
@@ -57,6 +57,7 @@ export * from './modules/reflection/types/type.type';
|
|
|
57
57
|
export * from './modules/reflection/utils/decorator.util';
|
|
58
58
|
export * from './modules/reflection/utils/reflection.util';
|
|
59
59
|
export * from './modules/router/router.util';
|
|
60
|
+
export * from './modules/state/reducer.type';
|
|
60
61
|
export * from './modules/state/state.model';
|
|
61
62
|
export * from './modules/state/update.type';
|
|
62
63
|
export * from './modules/state/adaptors/array/array-adaptor.util';
|
|
@@ -93,8 +93,10 @@ export class Task extends Subscribable {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
getStatus() {
|
|
96
|
-
if (this.status
|
|
97
|
-
return
|
|
96
|
+
if (this.status === TaskStatus.Failed)
|
|
97
|
+
return TaskStatus.Failed;
|
|
98
|
+
if (this.status === TaskStatus.Cancelled)
|
|
99
|
+
return TaskStatus.Cancelled;
|
|
98
100
|
for (const task of this.tasks) {
|
|
99
101
|
const status = task.getStatus();
|
|
100
102
|
if (status === TaskStatus.Failed)
|
|
@@ -104,7 +106,7 @@ export class Task extends Subscribable {
|
|
|
104
106
|
}
|
|
105
107
|
if (this.isCancelled())
|
|
106
108
|
return TaskStatus.Cancelled;
|
|
107
|
-
return
|
|
109
|
+
return this.status;
|
|
108
110
|
}
|
|
109
111
|
hasWarning() {
|
|
110
112
|
for (const log of this.logs) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ArrayAdaptor } from './adaptors/array/array-adaptor.util';
|
|
2
|
+
import { EntityAdaptor } from './adaptors/entity/entity-adaptor.util';
|
|
3
|
+
import { EntityMap } from './adaptors/entity/entity-map.type';
|
|
4
|
+
import { IEntity } from './adaptors/entity/entity.interface';
|
|
5
|
+
import { Update } from './update.type';
|
|
6
|
+
type EntityItem<V> = V extends EntityMap<infer U> ? U : never;
|
|
7
|
+
type ArrayItem<V> = V extends (infer U)[] ? U : never;
|
|
8
|
+
type FieldOf<TClass, K> = K extends keyof TClass ? TClass[K] : {};
|
|
9
|
+
type ReducerFieldAdaptor<TState, TReducer extends Reducer, K extends keyof TState> = TState[K] extends EntityMap<IEntity> ? {
|
|
10
|
+
entity: EntityAdaptor<TState, EntityItem<TState[K]>, K & any>;
|
|
11
|
+
} & FieldOf<TReducer, K> : TState[K] extends any[] ? {
|
|
12
|
+
array: ArrayAdaptor<TState, ArrayItem<TState[K]>, K & any>;
|
|
13
|
+
} & FieldOf<TReducer, K> : {
|
|
14
|
+
value: {
|
|
15
|
+
set: (value: TState[K]) => Update<TState>;
|
|
16
|
+
};
|
|
17
|
+
} & FieldOf<TReducer, K>;
|
|
18
|
+
type StateFields<TState, TReducer extends Reducer> = {
|
|
19
|
+
[K in keyof TState]: ReducerFieldAdaptor<TState, TReducer, K>;
|
|
20
|
+
};
|
|
21
|
+
export type ReducerFields<TState> = {
|
|
22
|
+
update: {
|
|
23
|
+
<V>(path: (state: TState) => V, fn: (value: V) => Partial<V>): Update<TState>;
|
|
24
|
+
<V>(path: (state: TState) => V, value: Partial<V>): Update<TState>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export type EmptyReducer = Record<never, never>;
|
|
28
|
+
export type Reducer = Record<string, any>;
|
|
29
|
+
export type StateReducer<TState, TReducer extends Reducer> = ReducerFields<TState> & StateFields<TState, TReducer>;
|
|
30
|
+
export {};
|
|
File without changes
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import type { Constructor } from '../reflection/types/constructor.type';
|
|
2
1
|
import { Subscribable } from '../subscribable/subscribable.model';
|
|
3
2
|
import type { Subscription } from '../subscribable/subscription.interface';
|
|
4
|
-
import {
|
|
5
|
-
import { EntityAdaptor } from './adaptors/entity/entity-adaptor.util';
|
|
6
|
-
import type { EntityMap } from './adaptors/entity/entity-map.type';
|
|
7
|
-
import type { IEntity } from './adaptors/entity/entity.interface';
|
|
3
|
+
import { EmptyReducer, Reducer, StateReducer } from './reducer.type';
|
|
8
4
|
import type { Update } from './update.type';
|
|
9
5
|
export interface StateChange<T> {
|
|
10
6
|
previousValue: T;
|
|
11
7
|
value: T;
|
|
12
8
|
}
|
|
13
9
|
export type StateEffect<T> = (value: T) => T;
|
|
14
|
-
export declare class State<T = any, TReducer extends
|
|
10
|
+
export declare class State<T = any, TReducer extends Reducer = EmptyReducer> extends Subscribable<StateChange<T>> {
|
|
15
11
|
private reducer?;
|
|
16
12
|
private _value;
|
|
17
13
|
get value(): T;
|
|
@@ -19,22 +15,7 @@ export declare class State<T = any, TReducer extends Constructor = Constructor>
|
|
|
19
15
|
static combineLatest<T extends any[]>(states: {
|
|
20
16
|
[K in keyof T]: State<T[K]>;
|
|
21
17
|
}, callback: (values: T) => void): Subscription;
|
|
22
|
-
reduce(update: (reducer:
|
|
23
|
-
update: {
|
|
24
|
-
<V>(path: (state: T) => V, update: (value: V) => Partial<V>): Update<T>;
|
|
25
|
-
<V>(path: (state: T) => V, value: Partial<V>): Update<T>;
|
|
26
|
-
};
|
|
27
|
-
} & {
|
|
28
|
-
[K in keyof T]: T[K] extends EntityMap<IEntity> ? {
|
|
29
|
-
entity: EntityAdaptor<T, T[K] extends EntityMap<infer U> ? U : never, K & any>;
|
|
30
|
-
} & (K extends keyof InstanceType<TReducer> ? InstanceType<TReducer>[K & keyof InstanceType<TReducer>] : {}) : T[K] extends any[] ? {
|
|
31
|
-
array: ArrayAdaptor<T, T[K] extends (infer U)[] ? U : never, K & any>;
|
|
32
|
-
} & (K extends keyof InstanceType<TReducer> ? InstanceType<TReducer>[K & keyof InstanceType<TReducer>] : {}) : {
|
|
33
|
-
value: {
|
|
34
|
-
set: (value: T[K]) => Update<T> & (K extends keyof InstanceType<TReducer> ? InstanceType<TReducer>[K & keyof InstanceType<TReducer>] : {});
|
|
35
|
-
} & (K extends keyof InstanceType<TReducer> ? InstanceType<TReducer>[K & keyof InstanceType<TReducer>] : {});
|
|
36
|
-
};
|
|
37
|
-
}) => Update<T>[]): void;
|
|
18
|
+
reduce(update: (reducer: StateReducer<T, TReducer>) => Update<T>[]): void;
|
|
38
19
|
subscribe(emit: (event: StateChange<T>, subscription: Subscription) => void): Subscription;
|
|
39
20
|
static update<TState>(state: TState, ...updates: Update<TState>[]): TState;
|
|
40
21
|
update(...updates: Update<T>[]): void;
|
|
@@ -42,11 +42,12 @@ export class State extends Subscribable {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
reduce(update) {
|
|
45
|
-
const
|
|
45
|
+
const reducerFields = {
|
|
46
46
|
update: (path, update) => {
|
|
47
47
|
return (state) => $Value.update(state, path, update);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const reducer = new Proxy(reducerFields, {
|
|
50
51
|
get: (target, property) => {
|
|
51
52
|
if (property === 'update')
|
|
52
53
|
return target.update;
|
|
@@ -59,7 +60,7 @@ export class State extends Subscribable {
|
|
|
59
60
|
}),
|
|
60
61
|
},
|
|
61
62
|
};
|
|
62
|
-
Object.assign(reducer,
|
|
63
|
+
Object.assign(reducer, this.reducer?.[property] ?? {});
|
|
63
64
|
return reducer;
|
|
64
65
|
},
|
|
65
66
|
});
|