File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
libs/ngrx-toolkit/src/lib Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -382,6 +382,7 @@ public class UndoRedoComponent {
382
382
383
383
canUndo = this .store .canUndo ; // use in template or in ts
384
384
canRedo = this .store .canRedo ; // use in template or in ts
385
+ clearStack = this .store .clearStack ; // use in template or in ts
385
386
386
387
undo(): void {
387
388
if (! this .canUndo ()) return ;
@@ -392,6 +393,10 @@ public class UndoRedoComponent {
392
393
if (! this .canRedo ()) return ;
393
394
this .store .redo ();
394
395
}
396
+
397
+ clearStack(): void {
398
+ this .store .clearStack ();
399
+ }
395
400
}
396
401
```
397
402
Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ describe('withUndoRedo', () => {
21
21
'canUndo' ,
22
22
'canRedo' ,
23
23
'undo' ,
24
- 'redo'
24
+ 'redo' ,
25
+ 'clearStack'
25
26
] ) ;
26
27
} ) ;
27
28
} ) ;
@@ -190,5 +191,24 @@ describe('withUndoRedo', () => {
190
191
expect ( store . canRedo ( ) ) . toBe ( true ) ;
191
192
} ) ;
192
193
} ) ) ;
194
+
195
+ it ( 'clears undo redo stack' , ( ) => {
196
+ const Store = signalStore (
197
+ { providedIn : 'root' } ,
198
+ withState ( testState ) ,
199
+ withMethods ( store => ( { update : ( value : string ) => patchState ( store , { test : value } ) } ) ) ,
200
+ withUndoRedo ( { keys : testKeys } )
201
+ ) ;
202
+
203
+ const store = TestBed . inject ( Store ) ;
204
+
205
+ store . update ( 'Foo' ) ;
206
+ store . update ( 'Bar' ) ;
207
+ store . undo ( ) ;
208
+ store . clearStack ( ) ;
209
+
210
+ expect ( store . canUndo ( ) ) . toBe ( false ) ;
211
+ expect ( store . canRedo ( ) ) . toBe ( false ) ;
212
+ } )
193
213
} ) ;
194
214
} ) ;
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ export function withUndoRedo<
61
61
methods : {
62
62
undo : ( ) => void ;
63
63
redo : ( ) => void ;
64
+ clearStack : ( ) => void ;
64
65
} ;
65
66
}
66
67
> {
@@ -126,6 +127,11 @@ export function withUndoRedo<
126
127
127
128
updateInternal ( ) ;
128
129
} ,
130
+ clearStack ( ) : void {
131
+ undoStack . splice ( 0 ) ;
132
+ redoStack . splice ( 0 ) ;
133
+ updateInternal ( ) ;
134
+ } ,
129
135
} ) ) ,
130
136
withHooks ( {
131
137
onInit ( store ) {
You can’t perform that action at this time.
0 commit comments