@angular-architects/ngrx-toolkit 19.4.0 → 19.4.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/fesm2022/angular-architects-ngrx-toolkit-redux-connector.mjs +119 -0
- package/fesm2022/angular-architects-ngrx-toolkit-redux-connector.mjs.map +1 -0
- package/fesm2022/angular-architects-ngrx-toolkit.mjs +2108 -0
- package/fesm2022/angular-architects-ngrx-toolkit.mjs.map +1 -0
- package/{src/index.ts → index.d.ts} +5 -32
- package/lib/assertions/assertions.d.ts +2 -0
- package/{src/lib/devtools/features/with-disabled-name-indicies.ts → lib/devtools/features/with-disabled-name-indicies.d.ts} +1 -5
- package/{src/lib/devtools/features/with-glitch-tracking.ts → lib/devtools/features/with-glitch-tracking.d.ts} +1 -6
- package/{src/lib/devtools/features/with-mapper.ts → lib/devtools/features/with-mapper.d.ts} +1 -7
- package/lib/devtools/internal/current-action-names.d.ts +1 -0
- package/lib/devtools/internal/default-tracker.d.ts +13 -0
- package/lib/devtools/internal/devtools-feature.d.ts +24 -0
- package/lib/devtools/internal/devtools-syncer.service.d.ts +39 -0
- package/lib/devtools/internal/glitch-tracker.service.d.ts +18 -0
- package/lib/devtools/internal/models.d.ts +24 -0
- package/{src/lib/devtools/provide-devtools-config.ts → lib/devtools/provide-devtools-config.d.ts} +4 -16
- package/lib/devtools/rename-devtools-name.d.ts +7 -0
- package/lib/devtools/update-state.d.ts +15 -0
- package/{src/lib/devtools/with-dev-tools-stub.ts → lib/devtools/with-dev-tools-stub.d.ts} +1 -2
- package/lib/devtools/with-devtools.d.ts +24 -0
- package/lib/flattening-operator.d.ts +14 -0
- package/lib/immutable-state/deep-freeze.d.ts +11 -0
- package/lib/immutable-state/is-dev-mode.d.ts +1 -0
- package/lib/immutable-state/with-immutable-state.d.ts +60 -0
- package/lib/mutation/http-mutation.d.ts +86 -0
- package/lib/mutation/mutation.d.ts +20 -0
- package/lib/mutation/rx-mutation.d.ts +76 -0
- package/{src/lib/shared/signal-store-models.ts → lib/shared/signal-store-models.d.ts} +4 -8
- package/lib/shared/throw-if-null.d.ts +1 -0
- package/lib/storage-sync/features/with-indexed-db.d.ts +2 -0
- package/lib/storage-sync/features/with-local-storage.d.ts +3 -0
- package/lib/storage-sync/internal/indexeddb.service.d.ts +29 -0
- package/lib/storage-sync/internal/local-storage.service.d.ts +8 -0
- package/lib/storage-sync/internal/models.d.ts +45 -0
- package/lib/storage-sync/internal/session-storage.service.d.ts +8 -0
- package/lib/storage-sync/with-storage-sync.d.ts +45 -0
- package/lib/with-call-state.d.ts +58 -0
- package/{src/lib/with-conditional.ts → lib/with-conditional.d.ts} +7 -31
- package/lib/with-data-service.d.ts +109 -0
- package/{src/lib/with-feature-factory.ts → lib/with-feature-factory.d.ts} +4 -32
- package/lib/with-mutations.d.ts +51 -0
- package/lib/with-pagination.d.ts +98 -0
- package/lib/with-redux.d.ts +147 -0
- package/lib/with-reset.d.ts +29 -0
- package/lib/with-undo-redo.d.ts +31 -0
- package/package.json +21 -4
- package/redux-connector/index.d.ts +2 -0
- package/redux-connector/src/lib/create-redux.d.ts +13 -0
- package/redux-connector/src/lib/model.d.ts +40 -0
- package/redux-connector/src/lib/rxjs-interop/redux-method.d.ts +14 -0
- package/redux-connector/src/lib/signal-redux-store.d.ts +11 -0
- package/redux-connector/src/lib/util.d.ts +5 -0
- package/eslint.config.cjs +0 -43
- package/jest.config.ts +0 -22
- package/ng-package.json +0 -7
- package/project.json +0 -37
- package/redux-connector/docs/README.md +0 -131
- package/redux-connector/index.ts +0 -6
- package/redux-connector/ng-package.json +0 -5
- package/redux-connector/src/lib/create-redux.ts +0 -102
- package/redux-connector/src/lib/model.ts +0 -89
- package/redux-connector/src/lib/rxjs-interop/redux-method.ts +0 -66
- package/redux-connector/src/lib/signal-redux-store.ts +0 -59
- package/redux-connector/src/lib/util.ts +0 -22
- package/src/lib/assertions/assertions.ts +0 -9
- package/src/lib/devtools/internal/current-action-names.ts +0 -1
- package/src/lib/devtools/internal/default-tracker.ts +0 -60
- package/src/lib/devtools/internal/devtools-feature.ts +0 -37
- package/src/lib/devtools/internal/devtools-syncer.service.ts +0 -202
- package/src/lib/devtools/internal/glitch-tracker.service.ts +0 -61
- package/src/lib/devtools/internal/models.ts +0 -29
- package/src/lib/devtools/rename-devtools-name.ts +0 -21
- package/src/lib/devtools/tests/action-name.spec.ts +0 -48
- package/src/lib/devtools/tests/basic.spec.ts +0 -111
- package/src/lib/devtools/tests/connecting.spec.ts +0 -37
- package/src/lib/devtools/tests/helpers.spec.ts +0 -43
- package/src/lib/devtools/tests/naming.spec.ts +0 -216
- package/src/lib/devtools/tests/provide-devtools-config.spec.ts +0 -25
- package/src/lib/devtools/tests/types.spec.ts +0 -19
- package/src/lib/devtools/tests/update-state.spec.ts +0 -29
- package/src/lib/devtools/tests/with-devtools.spec.ts +0 -5
- package/src/lib/devtools/tests/with-glitch-tracking.spec.ts +0 -272
- package/src/lib/devtools/tests/with-mapper.spec.ts +0 -69
- package/src/lib/devtools/update-state.ts +0 -38
- package/src/lib/devtools/with-devtools.ts +0 -81
- package/src/lib/flattening-operator.ts +0 -42
- package/src/lib/immutable-state/deep-freeze.ts +0 -43
- package/src/lib/immutable-state/is-dev-mode.ts +0 -6
- package/src/lib/immutable-state/tests/with-immutable-state.spec.ts +0 -260
- package/src/lib/immutable-state/with-immutable-state.ts +0 -115
- package/src/lib/mutation/http-mutation.spec.ts +0 -473
- package/src/lib/mutation/http-mutation.ts +0 -172
- package/src/lib/mutation/mutation.ts +0 -26
- package/src/lib/mutation/rx-mutation.spec.ts +0 -594
- package/src/lib/mutation/rx-mutation.ts +0 -208
- package/src/lib/shared/prettify.ts +0 -3
- package/src/lib/shared/throw-if-null.ts +0 -7
- package/src/lib/storage-sync/features/with-indexed-db.ts +0 -81
- package/src/lib/storage-sync/features/with-local-storage.ts +0 -58
- package/src/lib/storage-sync/internal/indexeddb.service.ts +0 -124
- package/src/lib/storage-sync/internal/local-storage.service.ts +0 -19
- package/src/lib/storage-sync/internal/models.ts +0 -62
- package/src/lib/storage-sync/internal/session-storage.service.ts +0 -18
- package/src/lib/storage-sync/tests/indexeddb.service.spec.ts +0 -99
- package/src/lib/storage-sync/tests/with-storage-async.spec.ts +0 -308
- package/src/lib/storage-sync/tests/with-storage-sync.spec.ts +0 -268
- package/src/lib/storage-sync/with-storage-sync.ts +0 -233
- package/src/lib/with-call-state.spec.ts +0 -42
- package/src/lib/with-call-state.ts +0 -195
- package/src/lib/with-conditional.spec.ts +0 -125
- package/src/lib/with-data-service.spec.ts +0 -564
- package/src/lib/with-data-service.ts +0 -433
- package/src/lib/with-feature-factory.spec.ts +0 -69
- package/src/lib/with-mutations.spec.ts +0 -537
- package/src/lib/with-mutations.ts +0 -146
- package/src/lib/with-pagination.spec.ts +0 -90
- package/src/lib/with-pagination.ts +0 -353
- package/src/lib/with-redux.spec.ts +0 -258
- package/src/lib/with-redux.ts +0 -387
- package/src/lib/with-reset.spec.ts +0 -112
- package/src/lib/with-reset.ts +0 -62
- package/src/lib/with-undo-redo.spec.ts +0 -287
- package/src/lib/with-undo-redo.ts +0 -199
- 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 -17
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import { computed, inject } from '@angular/core';
|
|
2
|
-
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
|
|
3
|
-
import {
|
|
4
|
-
patchState,
|
|
5
|
-
signalStore,
|
|
6
|
-
type,
|
|
7
|
-
withComputed,
|
|
8
|
-
withMethods,
|
|
9
|
-
withState,
|
|
10
|
-
} from '@ngrx/signals';
|
|
11
|
-
import { addEntity, withEntities } from '@ngrx/signals/entities';
|
|
12
|
-
import { withCallState } from './with-call-state';
|
|
13
|
-
import { withUndoRedo } from './with-undo-redo';
|
|
14
|
-
|
|
15
|
-
const testState = { test: '' };
|
|
16
|
-
const testKeys = ['test' as const];
|
|
17
|
-
const newValue = 'new value';
|
|
18
|
-
const newerValue = 'newer value';
|
|
19
|
-
|
|
20
|
-
describe('withUndoRedo', () => {
|
|
21
|
-
it('adds methods for undo, redo, canUndo, canRedo', () => {
|
|
22
|
-
TestBed.runInInjectionContext(() => {
|
|
23
|
-
const Store = signalStore(
|
|
24
|
-
withState(testState),
|
|
25
|
-
withUndoRedo({ keys: testKeys }),
|
|
26
|
-
);
|
|
27
|
-
const store = new Store();
|
|
28
|
-
|
|
29
|
-
expect(Object.keys(store)).toEqual([
|
|
30
|
-
'test',
|
|
31
|
-
'canUndo',
|
|
32
|
-
'canRedo',
|
|
33
|
-
'undo',
|
|
34
|
-
'redo',
|
|
35
|
-
'clearStack',
|
|
36
|
-
]);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should check keys and collection types', () => {
|
|
41
|
-
signalStore(
|
|
42
|
-
withState(testState),
|
|
43
|
-
// @ts-expect-error - should not allow invalid keys
|
|
44
|
-
withUndoRedo({ keys: ['tes'] }),
|
|
45
|
-
);
|
|
46
|
-
signalStore(
|
|
47
|
-
withState(testState),
|
|
48
|
-
withEntities({ entity: type(), collection: 'flight' }),
|
|
49
|
-
// @ts-expect-error - should not allow invalid keys when entities are present
|
|
50
|
-
withUndoRedo({ keys: ['flightIdsTest'] }),
|
|
51
|
-
);
|
|
52
|
-
signalStore(
|
|
53
|
-
withState(testState),
|
|
54
|
-
// @ts-expect-error - should not allow collections without named entities
|
|
55
|
-
withUndoRedo({ collections: ['tee'] }),
|
|
56
|
-
);
|
|
57
|
-
signalStore(
|
|
58
|
-
withState(testState),
|
|
59
|
-
withComputed((store) => ({ testComputed: computed(() => store.test()) })),
|
|
60
|
-
// @ts-expect-error - should not allow collections without named entities with other computed
|
|
61
|
-
withUndoRedo({ collections: ['tested'] }),
|
|
62
|
-
);
|
|
63
|
-
signalStore(
|
|
64
|
-
withEntities({ entity: type() }),
|
|
65
|
-
// @ts-expect-error - should not allow collections without named entities
|
|
66
|
-
withUndoRedo({ collections: ['test'] }),
|
|
67
|
-
);
|
|
68
|
-
signalStore(
|
|
69
|
-
withEntities({ entity: type(), collection: 'flight' }),
|
|
70
|
-
// @ts-expect-error - should not allow invalid collections
|
|
71
|
-
withUndoRedo({ collections: ['test'] }),
|
|
72
|
-
);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('undo and redo', () => {
|
|
76
|
-
it('restores previous state for regular store key', fakeAsync(() => {
|
|
77
|
-
TestBed.runInInjectionContext(() => {
|
|
78
|
-
const Store = signalStore(
|
|
79
|
-
withState(testState),
|
|
80
|
-
withMethods((store) => ({
|
|
81
|
-
updateTest: (newTest: string) =>
|
|
82
|
-
patchState(store, { test: newTest }),
|
|
83
|
-
})),
|
|
84
|
-
withUndoRedo({ keys: testKeys }),
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const store = new Store();
|
|
88
|
-
tick(1);
|
|
89
|
-
|
|
90
|
-
store.updateTest(newValue);
|
|
91
|
-
tick(1);
|
|
92
|
-
expect(store.test()).toEqual(newValue);
|
|
93
|
-
expect(store.canUndo()).toBe(true);
|
|
94
|
-
expect(store.canRedo()).toBe(false);
|
|
95
|
-
|
|
96
|
-
store.undo();
|
|
97
|
-
tick(1);
|
|
98
|
-
|
|
99
|
-
expect(store.test()).toEqual('');
|
|
100
|
-
expect(store.canUndo()).toBe(false);
|
|
101
|
-
expect(store.canRedo()).toBe(true);
|
|
102
|
-
});
|
|
103
|
-
}));
|
|
104
|
-
|
|
105
|
-
it('restores previous state for regular store key and respects skip', fakeAsync(() => {
|
|
106
|
-
TestBed.runInInjectionContext(() => {
|
|
107
|
-
const Store = signalStore(
|
|
108
|
-
withState(testState),
|
|
109
|
-
withMethods((store) => ({
|
|
110
|
-
updateTest: (newTest: string) =>
|
|
111
|
-
patchState(store, { test: newTest }),
|
|
112
|
-
})),
|
|
113
|
-
withUndoRedo({ keys: testKeys, skip: 1 }),
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const store = new Store();
|
|
117
|
-
tick(1);
|
|
118
|
-
|
|
119
|
-
store.updateTest(newValue);
|
|
120
|
-
tick(1);
|
|
121
|
-
expect(store.test()).toEqual(newValue);
|
|
122
|
-
|
|
123
|
-
store.updateTest(newerValue);
|
|
124
|
-
tick(1);
|
|
125
|
-
|
|
126
|
-
store.undo();
|
|
127
|
-
tick(1);
|
|
128
|
-
|
|
129
|
-
expect(store.test()).toEqual(newValue);
|
|
130
|
-
expect(store.canUndo()).toBe(false);
|
|
131
|
-
|
|
132
|
-
store.undo();
|
|
133
|
-
tick(1);
|
|
134
|
-
|
|
135
|
-
// should not change
|
|
136
|
-
expect(store.test()).toEqual(newValue);
|
|
137
|
-
});
|
|
138
|
-
}));
|
|
139
|
-
|
|
140
|
-
it('undoes and redoes previous state for entity', fakeAsync(() => {
|
|
141
|
-
const Store = signalStore(
|
|
142
|
-
withEntities({ entity: type<{ id: string }>() }),
|
|
143
|
-
withMethods((store) => ({
|
|
144
|
-
addEntity: (newTest: string) =>
|
|
145
|
-
patchState(store, addEntity({ id: newTest })),
|
|
146
|
-
})),
|
|
147
|
-
withUndoRedo(),
|
|
148
|
-
);
|
|
149
|
-
TestBed.configureTestingModule({ providers: [Store] });
|
|
150
|
-
TestBed.runInInjectionContext(() => {
|
|
151
|
-
const store = inject(Store);
|
|
152
|
-
tick(1);
|
|
153
|
-
expect(store.entities()).toEqual([]);
|
|
154
|
-
expect(store.canUndo()).toBe(false);
|
|
155
|
-
expect(store.canRedo()).toBe(false);
|
|
156
|
-
|
|
157
|
-
store.addEntity(newValue);
|
|
158
|
-
tick(1);
|
|
159
|
-
expect(store.entities()).toEqual([{ id: newValue }]);
|
|
160
|
-
expect(store.canUndo()).toBe(true);
|
|
161
|
-
expect(store.canRedo()).toBe(false);
|
|
162
|
-
|
|
163
|
-
store.addEntity(newerValue);
|
|
164
|
-
tick(1);
|
|
165
|
-
expect(store.entities()).toEqual([
|
|
166
|
-
{ id: newValue },
|
|
167
|
-
{ id: newerValue },
|
|
168
|
-
]);
|
|
169
|
-
expect(store.canUndo()).toBe(true);
|
|
170
|
-
expect(store.canRedo()).toBe(false);
|
|
171
|
-
|
|
172
|
-
store.undo();
|
|
173
|
-
|
|
174
|
-
expect(store.entities()).toEqual([{ id: newValue }]);
|
|
175
|
-
expect(store.canUndo()).toBe(true);
|
|
176
|
-
expect(store.canRedo()).toBe(true);
|
|
177
|
-
|
|
178
|
-
store.undo();
|
|
179
|
-
|
|
180
|
-
expect(store.entities()).toEqual([]);
|
|
181
|
-
expect(store.canUndo()).toBe(false);
|
|
182
|
-
expect(store.canRedo()).toBe(true);
|
|
183
|
-
|
|
184
|
-
store.redo();
|
|
185
|
-
tick(1);
|
|
186
|
-
|
|
187
|
-
expect(store.entities()).toEqual([{ id: newValue }]);
|
|
188
|
-
expect(store.canUndo()).toBe(true);
|
|
189
|
-
expect(store.canRedo()).toBe(true);
|
|
190
|
-
|
|
191
|
-
// should return canRedo=false after a change
|
|
192
|
-
store.addEntity('newest');
|
|
193
|
-
tick(1);
|
|
194
|
-
expect(store.canUndo()).toBe(true);
|
|
195
|
-
expect(store.canRedo()).toBe(false);
|
|
196
|
-
});
|
|
197
|
-
}));
|
|
198
|
-
|
|
199
|
-
it('restores previous state for named entity', fakeAsync(() => {
|
|
200
|
-
TestBed.runInInjectionContext(() => {
|
|
201
|
-
const Store = signalStore(
|
|
202
|
-
withEntities({
|
|
203
|
-
entity: type<{ id: string }>(),
|
|
204
|
-
collection: 'flight',
|
|
205
|
-
}),
|
|
206
|
-
withMethods((store) => ({
|
|
207
|
-
addEntity: (newTest: string) =>
|
|
208
|
-
patchState(
|
|
209
|
-
store,
|
|
210
|
-
addEntity({ id: newTest }, { collection: 'flight' }),
|
|
211
|
-
),
|
|
212
|
-
})),
|
|
213
|
-
withCallState({ collection: 'flight' }),
|
|
214
|
-
withUndoRedo({ collections: ['flight'] }),
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
const store = new Store();
|
|
218
|
-
tick(1);
|
|
219
|
-
|
|
220
|
-
store.addEntity(newValue);
|
|
221
|
-
tick(1);
|
|
222
|
-
expect(store.flightEntities()).toEqual([{ id: newValue }]);
|
|
223
|
-
expect(store.canUndo()).toBe(true);
|
|
224
|
-
expect(store.canRedo()).toBe(false);
|
|
225
|
-
|
|
226
|
-
store.undo();
|
|
227
|
-
tick(1);
|
|
228
|
-
|
|
229
|
-
expect(store.flightEntities()).toEqual([]);
|
|
230
|
-
expect(store.canUndo()).toBe(false);
|
|
231
|
-
expect(store.canRedo()).toBe(true);
|
|
232
|
-
});
|
|
233
|
-
}));
|
|
234
|
-
|
|
235
|
-
it('clears undo redo stack', () => {
|
|
236
|
-
const Store = signalStore(
|
|
237
|
-
{ providedIn: 'root' },
|
|
238
|
-
withState(testState),
|
|
239
|
-
withMethods((store) => ({
|
|
240
|
-
update: (value: string) => patchState(store, { test: value }),
|
|
241
|
-
})),
|
|
242
|
-
withUndoRedo({ keys: testKeys }),
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
const store = TestBed.inject(Store);
|
|
246
|
-
|
|
247
|
-
store.update('Foo');
|
|
248
|
-
store.update('Bar');
|
|
249
|
-
store.undo();
|
|
250
|
-
store.clearStack();
|
|
251
|
-
|
|
252
|
-
expect(store.canUndo()).toBe(false);
|
|
253
|
-
expect(store.canRedo()).toBe(false);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it('cannot undo after clearing and setting a new value', fakeAsync(() => {
|
|
257
|
-
const Store = signalStore(
|
|
258
|
-
{ providedIn: 'root' },
|
|
259
|
-
withState(testState),
|
|
260
|
-
withMethods((store) => ({
|
|
261
|
-
update: (value: string) => patchState(store, { test: value }),
|
|
262
|
-
})),
|
|
263
|
-
withUndoRedo({ keys: testKeys }),
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
const store = TestBed.inject(Store);
|
|
267
|
-
|
|
268
|
-
store.update('Alan');
|
|
269
|
-
tick(1);
|
|
270
|
-
|
|
271
|
-
store.update('Gordon');
|
|
272
|
-
tick(1);
|
|
273
|
-
|
|
274
|
-
store.clearStack();
|
|
275
|
-
tick(1);
|
|
276
|
-
|
|
277
|
-
// After clearing the undo/redo stack, there is no previous item anymore.
|
|
278
|
-
// The following update becomes the first value.
|
|
279
|
-
// Since there is no other value before, it cannot be undone.
|
|
280
|
-
store.update('Hugh');
|
|
281
|
-
tick(1);
|
|
282
|
-
|
|
283
|
-
expect(store.canUndo()).toBe(false);
|
|
284
|
-
expect(store.canRedo()).toBe(false);
|
|
285
|
-
}));
|
|
286
|
-
});
|
|
287
|
-
});
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { Signal, effect, isSignal, signal, untracked } from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
EmptyFeatureResult,
|
|
4
|
-
SignalStoreFeature,
|
|
5
|
-
SignalStoreFeatureResult,
|
|
6
|
-
patchState,
|
|
7
|
-
signalStoreFeature,
|
|
8
|
-
withComputed,
|
|
9
|
-
withHooks,
|
|
10
|
-
withMethods,
|
|
11
|
-
} from '@ngrx/signals';
|
|
12
|
-
import { capitalize } from './with-data-service';
|
|
13
|
-
|
|
14
|
-
export type StackItem = Record<string, unknown>;
|
|
15
|
-
|
|
16
|
-
export type NormalizedUndoRedoOptions = {
|
|
17
|
-
maxStackSize: number;
|
|
18
|
-
collections?: string[];
|
|
19
|
-
keys: string[];
|
|
20
|
-
skip: number;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const defaultOptions: NormalizedUndoRedoOptions = {
|
|
24
|
-
maxStackSize: 100,
|
|
25
|
-
keys: [],
|
|
26
|
-
skip: 0,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export function getUndoRedoKeys(collections?: string[]): string[] {
|
|
30
|
-
if (collections) {
|
|
31
|
-
return collections.flatMap((c) => [
|
|
32
|
-
`${c}EntityMap`,
|
|
33
|
-
`${c}Ids`,
|
|
34
|
-
`selected${capitalize(c)}Ids`,
|
|
35
|
-
`${c}Filter`,
|
|
36
|
-
]);
|
|
37
|
-
}
|
|
38
|
-
return ['entityMap', 'ids', 'selectedIds', 'filter'];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type NonNever<T> = T extends never ? never : T;
|
|
42
|
-
|
|
43
|
-
type ExtractEntityCollection<T> = T extends `${infer U}Entities` ? U : never;
|
|
44
|
-
|
|
45
|
-
type ExtractEntityCollections<Store extends SignalStoreFeatureResult> =
|
|
46
|
-
NonNever<
|
|
47
|
-
{
|
|
48
|
-
[K in keyof Store['props']]: ExtractEntityCollection<K>;
|
|
49
|
-
}[keyof Store['props']]
|
|
50
|
-
>;
|
|
51
|
-
|
|
52
|
-
type OptionsForState<Store extends SignalStoreFeatureResult> = Partial<
|
|
53
|
-
Omit<NormalizedUndoRedoOptions, 'collections' | 'keys'>
|
|
54
|
-
> & {
|
|
55
|
-
collections?: ExtractEntityCollections<Store>[];
|
|
56
|
-
keys?: (keyof Store['state'])[];
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export function withUndoRedo<Input extends EmptyFeatureResult>(
|
|
60
|
-
options?: OptionsForState<Input>,
|
|
61
|
-
): SignalStoreFeature<
|
|
62
|
-
Input,
|
|
63
|
-
EmptyFeatureResult & {
|
|
64
|
-
props: {
|
|
65
|
-
canUndo: Signal<boolean>;
|
|
66
|
-
canRedo: Signal<boolean>;
|
|
67
|
-
};
|
|
68
|
-
methods: {
|
|
69
|
-
undo: () => void;
|
|
70
|
-
redo: () => void;
|
|
71
|
-
clearStack: () => void;
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
> {
|
|
75
|
-
let previous: StackItem | null = null;
|
|
76
|
-
let skipOnce = false;
|
|
77
|
-
|
|
78
|
-
const normalized = {
|
|
79
|
-
...defaultOptions,
|
|
80
|
-
...options,
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
//
|
|
84
|
-
// Design Decision: This feature has its own
|
|
85
|
-
// internal state.
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
const undoStack: StackItem[] = [];
|
|
89
|
-
const redoStack: StackItem[] = [];
|
|
90
|
-
|
|
91
|
-
const canUndo = signal(false);
|
|
92
|
-
const canRedo = signal(false);
|
|
93
|
-
|
|
94
|
-
const updateInternal = () => {
|
|
95
|
-
canUndo.set(undoStack.length !== 0);
|
|
96
|
-
canRedo.set(redoStack.length !== 0);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const keys = [...getUndoRedoKeys(normalized.collections), ...normalized.keys];
|
|
100
|
-
|
|
101
|
-
return signalStoreFeature(
|
|
102
|
-
withComputed(() => ({
|
|
103
|
-
canUndo: canUndo.asReadonly(),
|
|
104
|
-
canRedo: canRedo.asReadonly(),
|
|
105
|
-
})),
|
|
106
|
-
withMethods((store) => ({
|
|
107
|
-
undo(): void {
|
|
108
|
-
const item = undoStack.pop();
|
|
109
|
-
|
|
110
|
-
if (item && previous) {
|
|
111
|
-
redoStack.push(previous);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (item) {
|
|
115
|
-
skipOnce = true;
|
|
116
|
-
patchState(store, item);
|
|
117
|
-
previous = item;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
updateInternal();
|
|
121
|
-
},
|
|
122
|
-
redo(): void {
|
|
123
|
-
const item = redoStack.pop();
|
|
124
|
-
|
|
125
|
-
if (item && previous) {
|
|
126
|
-
undoStack.push(previous);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (item) {
|
|
130
|
-
skipOnce = true;
|
|
131
|
-
patchState(store, item);
|
|
132
|
-
previous = item;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
updateInternal();
|
|
136
|
-
},
|
|
137
|
-
clearStack(): void {
|
|
138
|
-
undoStack.splice(0);
|
|
139
|
-
redoStack.splice(0);
|
|
140
|
-
previous = null;
|
|
141
|
-
updateInternal();
|
|
142
|
-
},
|
|
143
|
-
})),
|
|
144
|
-
withHooks({
|
|
145
|
-
onInit(store) {
|
|
146
|
-
effect(() => {
|
|
147
|
-
const cand = keys.reduce((acc, key) => {
|
|
148
|
-
const s = (store as Record<string | keyof Input['state'], unknown>)[
|
|
149
|
-
key
|
|
150
|
-
];
|
|
151
|
-
if (s && isSignal(s)) {
|
|
152
|
-
return {
|
|
153
|
-
...acc,
|
|
154
|
-
[key]: s(),
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
return acc;
|
|
158
|
-
}, {});
|
|
159
|
-
|
|
160
|
-
if (normalized.skip > 0) {
|
|
161
|
-
normalized.skip--;
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (skipOnce) {
|
|
166
|
-
skipOnce = false;
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
//
|
|
171
|
-
// Deep Comparison to prevent duplicated entries
|
|
172
|
-
// on the stack. This can e.g. happen after an undo
|
|
173
|
-
// if the component sends back the undone filter
|
|
174
|
-
// to the store.
|
|
175
|
-
//
|
|
176
|
-
if (JSON.stringify(cand) === JSON.stringify(previous)) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Clear redoStack after recorded action
|
|
181
|
-
redoStack.splice(0);
|
|
182
|
-
|
|
183
|
-
if (previous) {
|
|
184
|
-
undoStack.push(previous);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (redoStack.length > normalized.maxStackSize) {
|
|
188
|
-
undoStack.unshift();
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
previous = cand;
|
|
192
|
-
|
|
193
|
-
// Don't propogate current reactive context
|
|
194
|
-
untracked(() => updateInternal());
|
|
195
|
-
});
|
|
196
|
-
},
|
|
197
|
-
}),
|
|
198
|
-
);
|
|
199
|
-
}
|
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,17 +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
|
-
"src/lib/storage-sync/tests/with-storage-sync-indexedb.spec.ts"
|
|
16
|
-
]
|
|
17
|
-
}
|