@angular-architects/ngrx-toolkit 0.1.0 → 0.1.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.
- package/esm2022/angular-architects-ngrx-toolkit.mjs +5 -0
- package/esm2022/index.mjs +9 -0
- package/esm2022/lib/assertions/assertions.mjs +6 -0
- package/esm2022/lib/redux-connector/create-redux.mjs +41 -0
- package/esm2022/lib/redux-connector/index.mjs +2 -0
- package/esm2022/lib/redux-connector/model.mjs +2 -0
- package/esm2022/lib/redux-connector/rxjs-interop/index.mjs +2 -0
- package/esm2022/lib/redux-connector/rxjs-interop/redux-method.mjs +22 -0
- package/esm2022/lib/redux-connector/signal-redux-store.mjs +43 -0
- package/esm2022/lib/redux-connector/util.mjs +13 -0
- package/esm2022/lib/shared/empty.mjs +2 -0
- package/esm2022/lib/with-call-state.mjs +58 -0
- package/esm2022/lib/with-data-service.mjs +161 -0
- package/esm2022/lib/with-devtools.mjs +79 -0
- package/esm2022/lib/with-redux.mjs +95 -0
- package/esm2022/lib/with-storage-sync.mjs +56 -0
- package/esm2022/lib/with-undo-redo.mjs +93 -0
- package/fesm2022/angular-architects-ngrx-toolkit.mjs +653 -0
- package/fesm2022/angular-architects-ngrx-toolkit.mjs.map +1 -0
- package/{src/index.ts → index.d.ts} +2 -3
- package/lib/assertions/assertions.d.ts +2 -0
- package/lib/redux-connector/create-redux.d.ts +13 -0
- package/{src/lib/redux-connector/index.ts → lib/redux-connector/index.d.ts} +0 -1
- package/lib/redux-connector/model.d.ts +36 -0
- package/{src/lib/redux-connector/rxjs-interop/index.ts → lib/redux-connector/rxjs-interop/index.d.ts} +0 -1
- package/lib/redux-connector/rxjs-interop/redux-method.d.ts +11 -0
- package/lib/redux-connector/signal-redux-store.d.ts +11 -0
- package/lib/redux-connector/util.d.ts +5 -0
- package/lib/shared/empty.d.ts +1 -0
- package/lib/with-call-state.d.ts +56 -0
- package/lib/with-data-service.d.ts +115 -0
- package/lib/with-devtools.d.ts +32 -0
- package/lib/with-redux.d.ts +57 -0
- package/lib/with-storage-sync.d.ts +58 -0
- package/lib/with-undo-redo.d.ts +55 -0
- package/package.json +16 -3
- package/.eslintrc.json +0 -43
- package/jest.config.ts +0 -22
- package/ng-package.json +0 -7
- package/project.json +0 -37
- package/src/lib/assertions/assertions.ts +0 -9
- package/src/lib/redux-connector/create-redux.ts +0 -94
- package/src/lib/redux-connector/model.ts +0 -67
- package/src/lib/redux-connector/rxjs-interop/redux-method.ts +0 -61
- package/src/lib/redux-connector/signal-redux-store.ts +0 -54
- package/src/lib/redux-connector/util.ts +0 -22
- package/src/lib/shared/empty.ts +0 -2
- package/src/lib/with-call-state.spec.ts +0 -24
- package/src/lib/with-call-state.ts +0 -136
- package/src/lib/with-data-service.ts +0 -312
- package/src/lib/with-devtools.spec.ts +0 -157
- package/src/lib/with-devtools.ts +0 -128
- package/src/lib/with-redux.spec.ts +0 -100
- package/src/lib/with-redux.ts +0 -261
- package/src/lib/with-storage-sync.spec.ts +0 -237
- package/src/lib/with-storage-sync.ts +0 -160
- package/src/lib/with-undo-redo.ts +0 -184
- package/src/test-setup.ts +0 -8
- package/tsconfig.json +0 -29
- package/tsconfig.lib.json +0 -17
- package/tsconfig.lib.prod.json +0 -9
- package/tsconfig.spec.json +0 -16
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { SignalStoreFeature, patchState, signalStoreFeature, withComputed, withHooks, withMethods } from "@ngrx/signals";
|
|
2
|
-
import { EntityId, EntityMap, EntityState } from "@ngrx/signals/entities";
|
|
3
|
-
import { Signal, effect, signal, untracked, isSignal } from "@angular/core";
|
|
4
|
-
import { EntitySignals, NamedEntitySignals } from "@ngrx/signals/entities/src/models";
|
|
5
|
-
import { Entity, capitalize } from "./with-data-service";
|
|
6
|
-
import { Emtpy } from "./shared/empty";
|
|
7
|
-
|
|
8
|
-
export type StackItem = Record<string, unknown>;
|
|
9
|
-
|
|
10
|
-
export type NormalizedUndoRedoOptions = {
|
|
11
|
-
maxStackSize: number;
|
|
12
|
-
collections?: string[]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const defaultOptions: NormalizedUndoRedoOptions = {
|
|
16
|
-
maxStackSize: 100
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type NamedUndoRedoState<Collection extends string> = {
|
|
20
|
-
[K in Collection as `${K}EntityMap`]: EntityMap<Entity>;
|
|
21
|
-
} & {
|
|
22
|
-
[K in Collection as `${K}Ids`]: EntityId[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type NamedUndoRedoSignals<Collection extends string> = {
|
|
26
|
-
[K in Collection as `${K}Entities`]: Signal<Entity[]>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function getUndoRedoKeys(collections?: string[]): string[] {
|
|
30
|
-
if (collections) {
|
|
31
|
-
return collections.flatMap(c => [`${c}EntityMap`, `${c}Ids`, `selected${capitalize(c)}Ids`, `${c}Filter`])
|
|
32
|
-
}
|
|
33
|
-
return ['entityMap', 'ids', 'selectedIds', 'filter'];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function withUndoRedo<Collection extends string>(options?: { maxStackSize?: number; collections: Collection[] }): SignalStoreFeature<
|
|
37
|
-
{
|
|
38
|
-
state: Emtpy,
|
|
39
|
-
// This alternative breaks type inference:
|
|
40
|
-
// state: NamedEntityState<Entity, Collection>
|
|
41
|
-
signals: NamedEntitySignals<Entity, Collection>,
|
|
42
|
-
methods: Emtpy
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
state: Emtpy,
|
|
46
|
-
signals: {
|
|
47
|
-
canUndo: Signal<boolean>,
|
|
48
|
-
canRedo: Signal<boolean>
|
|
49
|
-
},
|
|
50
|
-
methods: {
|
|
51
|
-
undo: () => void,
|
|
52
|
-
redo: () => void
|
|
53
|
-
}
|
|
54
|
-
}>;
|
|
55
|
-
|
|
56
|
-
export function withUndoRedo(options?: { maxStackSize?: number }): SignalStoreFeature<
|
|
57
|
-
{
|
|
58
|
-
state: EntityState<Entity>,
|
|
59
|
-
signals: EntitySignals<Entity>,
|
|
60
|
-
methods: Emtpy
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
state: Emtpy,
|
|
64
|
-
signals: {
|
|
65
|
-
canUndo: Signal<boolean>,
|
|
66
|
-
canRedo: Signal<boolean>
|
|
67
|
-
},
|
|
68
|
-
methods: {
|
|
69
|
-
undo: () => void,
|
|
70
|
-
redo: () => void
|
|
71
|
-
}
|
|
72
|
-
}>;
|
|
73
|
-
|
|
74
|
-
export function withUndoRedo<Collection extends string>(options: {
|
|
75
|
-
maxStackSize?: number;
|
|
76
|
-
collections?: Collection[]
|
|
77
|
-
} = {}):
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
-
SignalStoreFeature<any, any> {
|
|
80
|
-
let previous: StackItem | null = null;
|
|
81
|
-
let skipOnce = false;
|
|
82
|
-
|
|
83
|
-
const normalized = {
|
|
84
|
-
...defaultOptions,
|
|
85
|
-
...options
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
//
|
|
89
|
-
// Design Decision: This feature has its own
|
|
90
|
-
// internal state.
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
const undoStack: StackItem[] = [];
|
|
94
|
-
const redoStack: StackItem[] = [];
|
|
95
|
-
|
|
96
|
-
const canUndo = signal(false);
|
|
97
|
-
const canRedo = signal(false);
|
|
98
|
-
|
|
99
|
-
const updateInternal = () => {
|
|
100
|
-
canUndo.set(undoStack.length !== 0);
|
|
101
|
-
canRedo.set(redoStack.length !== 0);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const keys = getUndoRedoKeys(normalized?.collections);
|
|
105
|
-
|
|
106
|
-
return signalStoreFeature(
|
|
107
|
-
|
|
108
|
-
withComputed(() => ({
|
|
109
|
-
canUndo: canUndo.asReadonly(),
|
|
110
|
-
canRedo: canRedo.asReadonly()
|
|
111
|
-
})),
|
|
112
|
-
withMethods((store) => ({
|
|
113
|
-
undo(): void {
|
|
114
|
-
const item = undoStack.pop();
|
|
115
|
-
|
|
116
|
-
if (item && previous) {
|
|
117
|
-
redoStack.push(previous);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (item) {
|
|
121
|
-
skipOnce = true;
|
|
122
|
-
patchState(store, item);
|
|
123
|
-
previous = item;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
updateInternal();
|
|
127
|
-
},
|
|
128
|
-
redo(): void {
|
|
129
|
-
const item = redoStack.pop();
|
|
130
|
-
|
|
131
|
-
if (item && previous) {
|
|
132
|
-
undoStack.push(previous);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (item) {
|
|
136
|
-
skipOnce = true;
|
|
137
|
-
patchState(store, item);
|
|
138
|
-
previous = item;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
updateInternal();
|
|
142
|
-
}
|
|
143
|
-
})),
|
|
144
|
-
withHooks({
|
|
145
|
-
onInit(store: Record<string, unknown>) {
|
|
146
|
-
effect(() => {
|
|
147
|
-
|
|
148
|
-
const cand = keys.reduce((acc, key) => {
|
|
149
|
-
const s = store[key];
|
|
150
|
-
if (s && isSignal(s)) {
|
|
151
|
-
return {
|
|
152
|
-
...acc,
|
|
153
|
-
[key]: s()
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return acc;
|
|
157
|
-
}, {});
|
|
158
|
-
|
|
159
|
-
if (skipOnce) {
|
|
160
|
-
skipOnce = false;
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Clear redoStack after recorded action
|
|
165
|
-
redoStack.splice(0);
|
|
166
|
-
|
|
167
|
-
if (previous) {
|
|
168
|
-
undoStack.push(previous);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (redoStack.length > normalized.maxStackSize) {
|
|
172
|
-
undoStack.unshift();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
previous = cand;
|
|
176
|
-
|
|
177
|
-
// Don't propogate current reactive context
|
|
178
|
-
untracked(() => updateInternal());
|
|
179
|
-
})
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
)
|
|
184
|
-
}
|
package/src/test-setup.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
|
|
2
|
-
globalThis.ngJest = {
|
|
3
|
-
testEnvironmentOptions: {
|
|
4
|
-
errorOnUnknownElements: true,
|
|
5
|
-
errorOnUnknownProperties: true,
|
|
6
|
-
},
|
|
7
|
-
};
|
|
8
|
-
import 'jest-preset-angular/setup-jest';
|
package/tsconfig.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2022",
|
|
4
|
-
"useDefineForClassFields": false,
|
|
5
|
-
"forceConsistentCasingInFileNames": true,
|
|
6
|
-
"strict": true,
|
|
7
|
-
"noImplicitOverride": true,
|
|
8
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
9
|
-
"noImplicitReturns": true,
|
|
10
|
-
"noFallthroughCasesInSwitch": true
|
|
11
|
-
},
|
|
12
|
-
"files": [],
|
|
13
|
-
"include": [],
|
|
14
|
-
"references": [
|
|
15
|
-
{
|
|
16
|
-
"path": "./tsconfig.lib.json"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"path": "./tsconfig.spec.json"
|
|
20
|
-
}
|
|
21
|
-
],
|
|
22
|
-
"extends": "../../tsconfig.base.json",
|
|
23
|
-
"angularCompilerOptions": {
|
|
24
|
-
"enableI18nLegacyMessageIdFormat": false,
|
|
25
|
-
"strictInjectionParameters": true,
|
|
26
|
-
"strictInputAccessModifiers": true,
|
|
27
|
-
"strictTemplates": true
|
|
28
|
-
}
|
|
29
|
-
}
|
package/tsconfig.lib.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"declarationMap": true,
|
|
7
|
-
"inlineSources": true,
|
|
8
|
-
"types": []
|
|
9
|
-
},
|
|
10
|
-
"exclude": [
|
|
11
|
-
"src/**/*.spec.ts",
|
|
12
|
-
"src/test-setup.ts",
|
|
13
|
-
"jest.config.ts",
|
|
14
|
-
"src/**/*.test.ts"
|
|
15
|
-
],
|
|
16
|
-
"include": ["src/**/*.ts"]
|
|
17
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"target": "es2016",
|
|
7
|
-
"types": ["jest", "node"]
|
|
8
|
-
},
|
|
9
|
-
"files": ["src/test-setup.ts"],
|
|
10
|
-
"include": [
|
|
11
|
-
"jest.config.ts",
|
|
12
|
-
"src/**/*.test.ts",
|
|
13
|
-
"src/**/*.spec.ts",
|
|
14
|
-
"src/**/*.d.ts"
|
|
15
|
-
]
|
|
16
|
-
}
|