From fc22cb6d27fcfe700125427990a1538a149e18c9 Mon Sep 17 00:00:00 2001 From: Garefild Date: Fri, 12 May 2023 19:25:51 +0300 Subject: [PATCH 1/7] undo-state.component: return same state on validation failed --- .../undo/src/components/undo-state.component.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/angular-redux2/undo/src/components/undo-state.component.ts b/projects/angular-redux2/undo/src/components/undo-state.component.ts index dfabb6f..3485a8a 100644 --- a/projects/angular-redux2/undo/src/components/undo-state.component.ts +++ b/projects/angular-redux2/undo/src/components/undo-state.component.ts @@ -80,7 +80,7 @@ export class NgUndoStateActions { const { state, undoState } = this.getStates(currentState); if (undoState.past.length === 0) { - return state; + return currentState; } const pastSnapshot = undoState.past.pop(); @@ -102,7 +102,7 @@ export class NgUndoStateActions { const { state, undoState } = this.getStates(currentState); if (undoState.future.length === 0) { - return state; + return currentState; } const futureSnapshot = undoState.future.shift(); @@ -160,7 +160,7 @@ export class NgUndoStateActions { const { state, undoState } = this.getStates(currentState); if (index < 0 || index >= undoState.future.length) { - return state; + return currentState; } const snapshot = get(state, this.path); @@ -186,7 +186,7 @@ export class NgUndoStateActions { const { state, undoState } = this.getStates(currentState); if (index < 0 || index >= undoState.past.length) { - return state; + return currentState; } const snapshot = get(state, this.path); From 3d250069390dcc1c0f673a0363e4ce3a4403c0d0 Mon Sep 17 00:00:00 2001 From: Garefild Date: Fri, 12 May 2023 19:52:20 +0300 Subject: [PATCH 2/7] undo.service: add settings with filter and limit and path --- .../components/undo-state.component.spec.ts | 20 +++++----- .../src/components/undo-state.component.ts | 38 ++++++++++++++----- .../undo/src/interfaces/undo.interface.ts | 19 +++++++++- .../undo/src/services/undo.service.spec.ts | 10 +---- .../undo/src/services/undo.service.ts | 5 ++- 5 files changed, 62 insertions(+), 30 deletions(-) diff --git a/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts b/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts index 7f97aca..0ba3d5a 100644 --- a/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts +++ b/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts @@ -8,7 +8,7 @@ import { HISTORY_STATE_KEY } from '../interfaces/undo.interface'; describe('NgUndoStateActions', () => { describe('insert', () => { test('should insert a snapshot into the past history', () => { - const undoStateActions = new NgUndoStateActions('key', [ 'path', 'to', 'watcher' ]); + const undoStateActions = new NgUndoStateActions('key', { path: [ 'path', 'to', 'watcher' ] }); const currentState = { data: 'initial data' }; @@ -23,7 +23,7 @@ describe('NgUndoStateActions', () => { }); test('should return the current state if the snapshot is undefined', () => { - const undoStateActions = new NgUndoStateActions('key', [ 'path', 'to', 'watcher' ]); + const undoStateActions = new NgUndoStateActions('key', { path: [ 'path', 'to', 'watcher' ] }); const currentState = { data: 'initial data' }; @@ -37,7 +37,7 @@ describe('NgUndoStateActions', () => { describe('undo', () => { test('should undo the last snapshot in the past history', () => { - const undoStateActions = new NgUndoStateActions('key', [ 'path', 'to', 'watcher' ]); + const undoStateActions = new NgUndoStateActions('key', { path: [ 'path', 'to', 'watcher' ] }); const currentState = { data: 'initial data', [HISTORY_STATE_KEY]: { @@ -63,7 +63,7 @@ describe('NgUndoStateActions', () => { }); test('should return the current state if there are no snapshots in the past history', () => { - const undoStateActions = new NgUndoStateActions('key', [ 'path', 'to', 'watcher' ]); + const undoStateActions = new NgUndoStateActions('key', { path: [ 'path', 'to', 'watcher' ] }); const currentState = { data: 'initial data', [HISTORY_STATE_KEY]: { @@ -87,7 +87,7 @@ describe('NgUndoStateActions', () => { describe('redo', () => { test('should redo the last snapshot in the future history', () => { - const undoStateActions = new NgUndoStateActions('key', [ 'path', 'to', 'watcher' ]); + const undoStateActions = new NgUndoStateActions('key', { path: [ 'path', 'to', 'watcher' ] }); const currentState = { data: 'initial data', [HISTORY_STATE_KEY]: { @@ -113,7 +113,7 @@ describe('NgUndoStateActions', () => { }); test('should return the current state if there are no snapshots in the future history', () => { - const undoStateActions = new NgUndoStateActions('key', [ 'path', 'to', 'watcher' ]); + const undoStateActions = new NgUndoStateActions('key', { path: [ 'path', 'to', 'watcher' ] }); const currentState = { data: 'initial data', [HISTORY_STATE_KEY]: { @@ -137,7 +137,7 @@ describe('NgUndoStateActions', () => { describe('jump', () => { test('should jump to the specified index in the future history', () => { - const undoStateActions = new NgUndoStateActions('key', [ 'path', 'to', 'watcher' ]); + const undoStateActions = new NgUndoStateActions('key', { path: [ 'path', 'to', 'watcher' ] }); const currentState = { data: 'initial data', [HISTORY_STATE_KEY]: { @@ -164,7 +164,7 @@ describe('NgUndoStateActions', () => { }); test('should jump to the specified index in the past history', () => { - const undoStateActions = new NgUndoStateActions('key', [ 'path', 'to', 'watcher' ]); + const undoStateActions = new NgUndoStateActions('key', { path: [ 'path', 'to', 'watcher' ] }); const currentState = { data: 'initial data', [HISTORY_STATE_KEY]: { @@ -191,7 +191,7 @@ describe('NgUndoStateActions', () => { }); test('should return the current state if the index is zero', () => { - const undoStateActions = new NgUndoStateActions('key', [ 'path', 'to', 'watcher' ]); + const undoStateActions = new NgUndoStateActions('key', { path: [ 'path', 'to', 'watcher' ] }); const currentState = { data: 'initial data', [HISTORY_STATE_KEY]: { @@ -215,7 +215,7 @@ describe('NgUndoStateActions', () => { }); test('should return the current state if the index is out of range', () => { - const undoStateActions = new NgUndoStateActions('key', [ 'path', 'to', 'watcher' ]); + const undoStateActions = new NgUndoStateActions('key', { path: [ 'path', 'to', 'watcher' ] }); const currentState = { data: 'initial data', [HISTORY_STATE_KEY]: { diff --git a/projects/angular-redux2/undo/src/components/undo-state.component.ts b/projects/angular-redux2/undo/src/components/undo-state.component.ts index 3485a8a..0672173 100644 --- a/projects/angular-redux2/undo/src/components/undo-state.component.ts +++ b/projects/angular-redux2/undo/src/components/undo-state.component.ts @@ -8,19 +8,13 @@ import { get, set } from '@angular-redux2/store'; * angular-redux2/undo */ -import { HISTORY_STATE_KEY } from '../interfaces/undo.interface'; +import { HISTORY_STATE_KEY, Settings } from '../interfaces/undo.interface'; /** * Represents the actions for managing undo state. */ export class NgUndoStateActions { - /** - * The path to the key in the state object. - * @type {Array} - */ - - path: Array; /** * The key associated with the history. @@ -30,17 +24,40 @@ export class NgUndoStateActions { protected key: string; + /** + * + * @protected + */ + + protected settings: { + filter: () => boolean; + path: Array + limit: number; + }; + /** * Creates a new instance of the HistoryManager class. * * @param {string} key - The key associated with the history. - * @param {Array} path - The path to the key in the state object. + * @param {Settings} settings - The settings for tracking the state action. * @constructor */ - constructor(key: string, path: Array) { + constructor(key: string, settings: Settings) { this.key = key; - this.path = path; + this.settings = Object.assign({ + limit: 0, + filter: () => true + }, settings); + } + + /** + * The path to the key in the state object. + * @return {Array} + */ + + get path(): Array { + return this.settings.path; } /** @@ -61,6 +78,7 @@ export class NgUndoStateActions { const { state, undoState } = this.getStates(currentState); undoState.future = []; + return set(state, [ HISTORY_STATE_KEY, this.key, 'past' ], [ ...undoState.past, snapshot diff --git a/projects/angular-redux2/undo/src/interfaces/undo.interface.ts b/projects/angular-redux2/undo/src/interfaces/undo.interface.ts index 25f96af..e24d30e 100644 --- a/projects/angular-redux2/undo/src/interfaces/undo.interface.ts +++ b/projects/angular-redux2/undo/src/interfaces/undo.interface.ts @@ -111,6 +111,23 @@ export interface NgUndoAction { export interface StateWatchMap { [key: string]: { - path: string + path: string; + filter?: () => boolean; + limit?: number; } } + +/** + * Represents the settings for tracking a specific property in the state for undo/redo operations. + * + * @param path - The path to the property in the state object. It is represented as an array of strings and numbers. + * @param limit - (Optional) The maximum number of actions to keep in the undo/redo history. + * If not specified, all actions will be kept. + * @param filter - (Optional) A filter function that determines whether an action should be included in the undo/redo history. + */ + +export interface Settings { + path: Array; + filter?: () => boolean; + limit?: number; +} diff --git a/projects/angular-redux2/undo/src/services/undo.service.spec.ts b/projects/angular-redux2/undo/src/services/undo.service.spec.ts index 29e57dc..362493c 100644 --- a/projects/angular-redux2/undo/src/services/undo.service.spec.ts +++ b/projects/angular-redux2/undo/src/services/undo.service.spec.ts @@ -13,26 +13,20 @@ jest.mock('@angular-redux2/store', () => ({ describe('UndoService', () => { describe('constructor', () => { test('should create watchStateMap with correct values', () => { - // Mock input data const stateWatchMap = { 'testKey1': { path: 'path1.to.data' }, 'testKey2': { path: 'path2.to.data' }, }; - // Create an instance of UndoService const undoService = new UndoService(stateWatchMap); - // Verify the watchStateMap values - expect((undoService as any).watchStateMap).toEqual({ - 'testKey1': new NgUndoStateActions('testKey1', [ 'path1', 'to', 'data' ]), - 'testKey2': new NgUndoStateActions('testKey2', [ 'path2', 'to', 'data' ]), - }); + expect((undoService as any).watchStateMap).toHaveProperty('testKey1'); + expect((undoService as any).watchStateMap).toHaveProperty('testKey2'); }); }); describe('watcherState', () => { test('should call watcherAction and detectChange methods', () => { - // Mock input data const state = { /* mock state object */ }; const action = { type: UNDO_REDUCER_PREFIX }; const next = jest.fn(); diff --git a/projects/angular-redux2/undo/src/services/undo.service.ts b/projects/angular-redux2/undo/src/services/undo.service.ts index 9b84b43..97ca542 100644 --- a/projects/angular-redux2/undo/src/services/undo.service.ts +++ b/projects/angular-redux2/undo/src/services/undo.service.ts @@ -45,7 +45,10 @@ export class UndoService { constructor(stateWatchMap: StateWatchMap) { for (const key in stateWatchMap) { - this.watchStateMap[key] = new NgUndoStateActions(key, stateWatchMap[key].path.split('.')); + const settings: any = { ...stateWatchMap[key] }; + settings.path = settings.path.split('.'); + + this.watchStateMap[key] = new NgUndoStateActions(key, settings); } } From 3dc350f7326a7813a391d0474461f96570e0fc2c Mon Sep 17 00:00:00 2001 From: Garefild Date: Fri, 12 May 2023 19:53:39 +0300 Subject: [PATCH 3/7] undo-state.component: add filter() in insert() --- .../angular-redux2/undo/src/components/undo-state.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/angular-redux2/undo/src/components/undo-state.component.ts b/projects/angular-redux2/undo/src/components/undo-state.component.ts index 0672173..a383321 100644 --- a/projects/angular-redux2/undo/src/components/undo-state.component.ts +++ b/projects/angular-redux2/undo/src/components/undo-state.component.ts @@ -71,7 +71,7 @@ export class NgUndoStateActions { */ insert(currentState: any, snapshot: any): any { - if (snapshot === undefined) { + if (snapshot === undefined || !this.settings.filter()) { return currentState; } From 64b77e3ed157a83c6bf1badb1c3c4fa212dd7338 Mon Sep 17 00:00:00 2001 From: Garefild Date: Fri, 12 May 2023 19:56:43 +0300 Subject: [PATCH 4/7] undo-state.component: add limit support in insert() --- .../components/undo-state.component.spec.ts | 84 +++++++++++++++++++ .../src/components/undo-state.component.ts | 16 +++- 2 files changed, 96 insertions(+), 4 deletions(-) diff --git a/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts b/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts index 0ba3d5a..22ccb17 100644 --- a/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts +++ b/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts @@ -33,6 +33,90 @@ describe('NgUndoStateActions', () => { expect(nextState).toBe(currentState); // Ensure the current state is returned }); + + test('should return the currentState if snapshot is undefined', () => { + const key = 'test'; + const settings = { + path: [], + filter: () => true, + limit: 5 + }; + + const currentState = { [HISTORY_STATE_KEY]: { [key]: { past: [] } } }; + const snapshot = undefined; + const actions = new NgUndoStateActions(key, settings); + const result = actions.insert(currentState, snapshot); + + + expect(result).toBe(currentState); + }); + + test('should return the currentState if the filter function returns false', () => { + const key = 'test'; + const settings = { + path: [], + filter: () => false, + limit: 5 + }; + const currentState = { [HISTORY_STATE_KEY]: { [key]: { past: [] } } }; + const snapshot = 'snapshot'; + const actions = new NgUndoStateActions(key, settings); + const result = actions.insert(currentState, snapshot); + + expect(result).toBe(currentState); + }); + + test('should insert the snapshot into the past array and update the state', () => { + const key = 'test'; + const settings = { + path: [], + filter: () => true, + limit: 5 + }; + const currentState = { [HISTORY_STATE_KEY]: { [key]: { past: [ 'past1', 'past2' ] } } }; + const snapshot = 'snapshot'; + const expectedState = { + [HISTORY_STATE_KEY]: { + [key]: { + past: [ 'past1', 'past2', 'snapshot' ], + future: [] + } + } + }; + + const actions = new NgUndoStateActions(key, settings); + const result = actions.insert(currentState, snapshot); + + expect(result).toEqual(expectedState); + }); + + test('should remove the oldest past snapshot if the past array exceeds the limit', () => { + const key = 'test'; + const settings = { + path: [], + filter: () => true, + limit: 2 + }; + const currentState = { + [HISTORY_STATE_KEY]: { + [key]: { past: [ 'past1', 'past2', 'past3' ] } + } + }; + const snapshot = 'snapshot'; + const expectedState = { + [HISTORY_STATE_KEY]: { + [key]: { + past: [ 'past2', 'past3', 'snapshot' ], + future: [] + } + } + }; + + const actions = new NgUndoStateActions(key, settings); + const result = actions.insert(currentState, snapshot); + + expect(result).toEqual(expectedState); + }); }); describe('undo', () => { diff --git a/projects/angular-redux2/undo/src/components/undo-state.component.ts b/projects/angular-redux2/undo/src/components/undo-state.component.ts index a383321..fe07d84 100644 --- a/projects/angular-redux2/undo/src/components/undo-state.component.ts +++ b/projects/angular-redux2/undo/src/components/undo-state.component.ts @@ -8,7 +8,13 @@ import { get, set } from '@angular-redux2/store'; * angular-redux2/undo */ -import { HISTORY_STATE_KEY, Settings } from '../interfaces/undo.interface'; +import { HISTORY_STATE_KEY } from '../interfaces/undo.interface'; + +/** + * angular-redux2/undo types + */ + +import type { Settings } from '../interfaces/undo.interface'; /** * Represents the actions for managing undo state. @@ -76,9 +82,12 @@ export class NgUndoStateActions { } const { state, undoState } = this.getStates(currentState); - undoState.future = []; + if (undoState.past.length >= this.settings.limit) { + undoState.past = undoState.past.slice(1); + } + return set(state, [ HISTORY_STATE_KEY, this.key, 'past' ], [ ...undoState.past, snapshot @@ -184,9 +193,8 @@ export class NgUndoStateActions { const snapshot = get(state, this.path); const activeSnapshot = undoState.future[index]; const future = undoState.future.slice(index + 1); - const past = undoState.past.concat([ snapshot ], undoState.future.slice(0, index)); - undoState.past = past; + undoState.past = undoState.past.concat([ snapshot ], undoState.future.slice(0, index)); undoState.future = future; return set(state, this.path, activeSnapshot); From c29bc90d813ebf19e7f35548724fe997755c1738 Mon Sep 17 00:00:00 2001 From: Garefild Date: Fri, 12 May 2023 21:03:43 +0300 Subject: [PATCH 5/7] add action to inset() for use in the filter settings. --- .../src/components/undo-state.component.spec.ts | 12 ++++++------ .../undo/src/components/undo-state.component.ts | 10 +++++----- .../undo/src/interfaces/undo.interface.ts | 2 +- .../undo/src/services/undo.service.spec.ts | 15 ++++++++------- .../undo/src/services/undo.service.ts | 7 ++++--- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts b/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts index 22ccb17..785851a 100644 --- a/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts +++ b/projects/angular-redux2/undo/src/components/undo-state.component.spec.ts @@ -14,7 +14,7 @@ describe('NgUndoStateActions', () => { }; const snapshot = 'new snapshot'; - const nextState = undoStateActions.insert(currentState, snapshot); + const nextState = undoStateActions.insert({}, currentState, snapshot); expect(nextState).not.toBe(currentState); expect(nextState.data).toBe(currentState.data); @@ -29,7 +29,7 @@ describe('NgUndoStateActions', () => { }; const snapshot = undefined; - const nextState = undoStateActions.insert(currentState, snapshot); + const nextState = undoStateActions.insert({}, currentState, snapshot); expect(nextState).toBe(currentState); // Ensure the current state is returned }); @@ -45,7 +45,7 @@ describe('NgUndoStateActions', () => { const currentState = { [HISTORY_STATE_KEY]: { [key]: { past: [] } } }; const snapshot = undefined; const actions = new NgUndoStateActions(key, settings); - const result = actions.insert(currentState, snapshot); + const result = actions.insert({}, currentState, snapshot); expect(result).toBe(currentState); @@ -61,7 +61,7 @@ describe('NgUndoStateActions', () => { const currentState = { [HISTORY_STATE_KEY]: { [key]: { past: [] } } }; const snapshot = 'snapshot'; const actions = new NgUndoStateActions(key, settings); - const result = actions.insert(currentState, snapshot); + const result = actions.insert({}, currentState, snapshot); expect(result).toBe(currentState); }); @@ -85,7 +85,7 @@ describe('NgUndoStateActions', () => { }; const actions = new NgUndoStateActions(key, settings); - const result = actions.insert(currentState, snapshot); + const result = actions.insert({}, currentState, snapshot); expect(result).toEqual(expectedState); }); @@ -113,7 +113,7 @@ describe('NgUndoStateActions', () => { }; const actions = new NgUndoStateActions(key, settings); - const result = actions.insert(currentState, snapshot); + const result = actions.insert({}, currentState, snapshot); expect(result).toEqual(expectedState); }); diff --git a/projects/angular-redux2/undo/src/components/undo-state.component.ts b/projects/angular-redux2/undo/src/components/undo-state.component.ts index fe07d84..44aaacd 100644 --- a/projects/angular-redux2/undo/src/components/undo-state.component.ts +++ b/projects/angular-redux2/undo/src/components/undo-state.component.ts @@ -31,12 +31,11 @@ export class NgUndoStateActions { protected key: string; /** - * - * @protected + * Represents the settings for an undo action. */ protected settings: { - filter: () => boolean; + filter: (action: any, currentState: any, snapshot: any) => boolean; path: Array limit: number; }; @@ -71,13 +70,14 @@ export class NgUndoStateActions { * It adds the given snapshot to the past states of the history. * If the snapshot is undefined, it returns the current state unchanged. * + * @param {NgUndoAction} action - The dispatched undo action object. * @param {any} currentState - The current state object. * @param {any} snapshot - The snapshot to insert into the history. * @returns {any} - The state object with the snapshot inserted into the history. */ - insert(currentState: any, snapshot: any): any { - if (snapshot === undefined || !this.settings.filter()) { + insert(action: any, currentState: any, snapshot: any): any { + if (snapshot === undefined || !this.settings.filter(action, currentState, snapshot)) { return currentState; } diff --git a/projects/angular-redux2/undo/src/interfaces/undo.interface.ts b/projects/angular-redux2/undo/src/interfaces/undo.interface.ts index e24d30e..988d614 100644 --- a/projects/angular-redux2/undo/src/interfaces/undo.interface.ts +++ b/projects/angular-redux2/undo/src/interfaces/undo.interface.ts @@ -112,7 +112,7 @@ export interface NgUndoAction { export interface StateWatchMap { [key: string]: { path: string; - filter?: () => boolean; + filter?: (action: any, currentState: any, snapshot: any) => boolean; limit?: number; } } diff --git a/projects/angular-redux2/undo/src/services/undo.service.spec.ts b/projects/angular-redux2/undo/src/services/undo.service.spec.ts index 362493c..ad9a449 100644 --- a/projects/angular-redux2/undo/src/services/undo.service.spec.ts +++ b/projects/angular-redux2/undo/src/services/undo.service.spec.ts @@ -4,7 +4,6 @@ import { ngUndoMiddleware, UndoService } from './undo.service'; import { UNDO_REDUCER_PREFIX, UndoActions } from '../interfaces/undo.interface'; -import { NgUndoStateActions } from '../components/undo-state.component'; jest.mock('@angular-redux2/store', () => ({ get: jest.fn() @@ -26,11 +25,15 @@ describe('UndoService', () => { }); describe('watcherState', () => { + const next = jest.fn(); + + afterEach(() => { + jest.resetAllMocks(); + }); + test('should call watcherAction and detectChange methods', () => { const state = { /* mock state object */ }; const action = { type: UNDO_REDUCER_PREFIX }; - const next = jest.fn(); - const undoService = new UndoService({}); (undoService as any).watcherAction = jest.fn().mockReturnValue(state); @@ -39,7 +42,7 @@ describe('UndoService', () => { const updatedState = undoService.watcherState(state, action, next); expect((undoService as any).watcherAction).toHaveBeenCalledWith(state, action); - expect((undoService as any).detectChange).toHaveBeenCalledWith(state, next(state, action)); + expect((undoService as any).detectChange).toHaveBeenCalledWith(action, state, next(state, action)); expect(updatedState).toBe(state); expect(next).toHaveBeenCalledWith(state, action); }); @@ -48,8 +51,6 @@ describe('UndoService', () => { // Mock input data const state = { /* mock state object */ }; const action = { type: 'SOME_OTHER_ACTION' }; - const next = jest.fn(); - const undoService = new UndoService({}); (undoService as any).watcherAction = jest.fn().mockReturnValue(state); @@ -58,7 +59,7 @@ describe('UndoService', () => { const updatedState = undoService.watcherState(state, action, next); expect((undoService as any).watcherAction).not.toHaveBeenCalled(); - expect((undoService as any).detectChange).toHaveBeenCalledWith(state, next(state, action)); + expect((undoService as any).detectChange).toHaveBeenCalledWith(action, state, next(state, action)); expect(updatedState).toBe(state); expect(next).toHaveBeenCalledWith(state, action); }); diff --git a/projects/angular-redux2/undo/src/services/undo.service.ts b/projects/angular-redux2/undo/src/services/undo.service.ts index 97ca542..0d93427 100644 --- a/projects/angular-redux2/undo/src/services/undo.service.ts +++ b/projects/angular-redux2/undo/src/services/undo.service.ts @@ -66,7 +66,7 @@ export class UndoService { state = this.watcherAction(state, action); } - return this.detectChange(state, next(state, action)); + return this.detectChange(action, state, next(state, action)); } /** @@ -108,12 +108,13 @@ export class UndoService { * Detects changes in the state and inserts snapshots into the undo history when necessary. * * @protected + * @param {any} action - The dispatched action object. * @param {any} state - The current state object. * @param {any} newState - The updated state object. * @returns {any} - The updated state with inserted snapshots. */ - protected detectChange(state: any, newState: any): any { + protected detectChange(action: any, state: any, newState: any): any { for (const propertyName in this.watchStateMap) { const undoAction = this.watchStateMap[propertyName]; @@ -121,7 +122,7 @@ export class UndoService { const sliceNewState = get(newState, undoAction.path); if (sliceNewState !== sliceState) { - newState = undoAction.insert(newState, sliceState); + newState = undoAction.insert(action, newState, sliceState); } } From c6324e82c035baf9267910fd8602b9d63009522f Mon Sep 17 00:00:00 2001 From: Garefild Date: Fri, 12 May 2023 21:11:02 +0300 Subject: [PATCH 6/7] README: update --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2af3f77..8d8daee 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ management using Redux. [![downloads per month](https://img.shields.io/npm/dm/@angular-redux2/undo.svg)](https://www.npmjs.com/package/@angular-redux2/undo) ## Installation + You can install angular-redux2/sync using npm: ```bash @@ -15,11 +16,13 @@ npm install @angular-redux2/undo ``` ## Usage -- Take me to the [API docs](https://angular-redux2.github.io/undo). + +> Take me to the [API docs](https://angular-redux2.github.io/undo). To use `@angular-redux2/undo` in your Angular application, follow these steps: Define a StateWatchMap object that maps the properties you want to track for undo/redo operations to their corresponding -state paths and configure the undo middleware in your Angular-Redux2/store setup by including it in the list of middleware: +state paths and configure the undo middleware in your Angular-Redux2/store setup by including it in the list of +middleware: ```typescript const middleware: Array = [ @@ -28,15 +31,26 @@ const middleware: Array = [ path: 'path.to.property1' }, propertyName2: { - path: 'path.to.property2' + path: 'path.to.property2', + limit: 5 }, }), ]; ngRedux.configureStore(rootReducer, {}, middleware, enhancer); ``` + +settings: + +- `path` (required): The path to the property in the state object using dot notation. +- `filter` (optional): A filter function that determines if the property should be watched for undo/redo. Return true to + include the property, and false to exclude it. If not specified, all properties are included. +- `limit` (optional): The maximum number of past snapshots to keep in the undo history. If the limit is reached, the + oldest snapshots are discarded. If not specified, no limit is applied. + Implement the undo/redo functionality in your Angular component or service. -You can use the `undo`, `redo`, `jump`, and `clear_history` methods provided by `NgUndoStateActions` to perform the corresponding actions: +You can use the `undo`, `redo`, `jump`, and `clear_history` methods provided by `NgUndoStateActions` to perform the +corresponding actions: ```typescript // Example component @@ -54,7 +68,8 @@ import { undo, redo, jump, clear_history } from '@angular-redux2/undo'; ` }) export class ExampleComponent { - constructor(private undoStateActions: NgUndoStateActions) {} + constructor(private undoStateActions: NgUndoStateActions) { + } @Dispatch onUndo() { @@ -77,3 +92,47 @@ export class ExampleComponent { } } ``` + +## State Watch Map + +The state watch map is an object that defines the paths to the state properties you want to track for undo. It has the +following structure: + +```typescript +export interface StateWatchMap { + [key: string]: { + path: string; + filter?: (action: any, currentState: any, snapshot: any) => boolean; + limit?: number; + } +} +``` + +- `key` (string): The unique identifier for the state property. +- `path` (string): The dot-separated path to the state property. +- `filter` (optional function): A filter function that determines if an action should be captured in the undo history + for the specific state property. + +## Custom Filters + +You can define custom filter functions to control which actions are captured in the undo history for each state +property. +The filter function takes three parameters: + +- `action`: The dispatched action object. +- `currentState`: The current store state object. +- `snapshot`: The snapshot to insert into the history. + +The filter function should return true if the action should be captured, or false otherwise. +Here's an example of a custom filter function that only captures actions with specific types: + +```typescript +const stateWatchMap: StateWatchMap = { + 'todos': { + path: 'todos', + filter: (action: any, currentState: any, snapshot: any): boolean => { + return action.type === 'ADD_TODO' || action.type === 'REMOVE_TODO'; + } + } +}; +``` From 5a86b571241c86530e069e6b0ade9cdcd9550a6e Mon Sep 17 00:00:00 2001 From: Garefild Date: Fri, 12 May 2023 21:11:31 +0300 Subject: [PATCH 7/7] docs: update api docs --- docs/assets/search.js | 2 +- docs/classes/UndoService.html | 19 ++-- docs/enums/UndoActions.html | 11 +-- docs/functions/clearHistory.html | 3 +- docs/functions/jump.html | 3 +- docs/functions/ngUndoMiddleware.html | 3 +- docs/functions/ngUndoState-1.html | 3 +- docs/functions/redo.html | 3 +- docs/functions/undo.html | 3 +- docs/index.html | 1 + docs/interfaces/NgUndoAction.html | 7 +- docs/interfaces/NgUndoState.html | 3 +- docs/interfaces/Settings.html | 115 ++++++++++++++++++++++++ docs/interfaces/StateWatchMap.html | 24 ++++- docs/interfaces/UndoState.html | 7 +- docs/modules.html | 2 + docs/variables/HISTORY_STATE_KEY.html | 3 +- docs/variables/UNDO_REDUCER_PREFIX.html | 3 +- 18 files changed, 185 insertions(+), 30 deletions(-) create mode 100644 docs/interfaces/Settings.html diff --git a/docs/assets/search.js b/docs/assets/search.js index fd67584..ddc7ae9 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1 +1 @@ -window.searchData = JSON.parse("{\"rows\":[{\"kind\":64,\"name\":\"ngUndoMiddleware\",\"url\":\"functions/ngUndoMiddleware.html\",\"classes\":\"\"},{\"kind\":128,\"name\":\"UndoService\",\"url\":\"classes/UndoService.html\",\"classes\":\"\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/UndoService.html#constructor\",\"classes\":\"\",\"parent\":\"UndoService\"},{\"kind\":1024,\"name\":\"watchStateMap\",\"url\":\"classes/UndoService.html#watchStateMap\",\"classes\":\"tsd-is-protected\",\"parent\":\"UndoService\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"classes/UndoService.html#watchStateMap.__type\",\"classes\":\"\",\"parent\":\"UndoService.watchStateMap\"},{\"kind\":2048,\"name\":\"watcherState\",\"url\":\"classes/UndoService.html#watcherState\",\"classes\":\"\",\"parent\":\"UndoService\"},{\"kind\":2048,\"name\":\"watcherAction\",\"url\":\"classes/UndoService.html#watcherAction\",\"classes\":\"tsd-is-protected\",\"parent\":\"UndoService\"},{\"kind\":2048,\"name\":\"detectChange\",\"url\":\"classes/UndoService.html#detectChange\",\"classes\":\"tsd-is-protected\",\"parent\":\"UndoService\"},{\"kind\":32,\"name\":\"HISTORY_STATE_KEY\",\"url\":\"variables/HISTORY_STATE_KEY.html\",\"classes\":\"\"},{\"kind\":32,\"name\":\"UNDO_REDUCER_PREFIX\",\"url\":\"variables/UNDO_REDUCER_PREFIX.html\",\"classes\":\"\"},{\"kind\":8,\"name\":\"UndoActions\",\"url\":\"enums/UndoActions.html\",\"classes\":\"\"},{\"kind\":16,\"name\":\"UNDO\",\"url\":\"enums/UndoActions.html#UNDO\",\"classes\":\"\",\"parent\":\"UndoActions\"},{\"kind\":16,\"name\":\"REDO\",\"url\":\"enums/UndoActions.html#REDO\",\"classes\":\"\",\"parent\":\"UndoActions\"},{\"kind\":16,\"name\":\"JUMP\",\"url\":\"enums/UndoActions.html#JUMP\",\"classes\":\"\",\"parent\":\"UndoActions\"},{\"kind\":16,\"name\":\"CLEAR_HISTORY\",\"url\":\"enums/UndoActions.html#CLEAR_HISTORY\",\"classes\":\"\",\"parent\":\"UndoActions\"},{\"kind\":256,\"name\":\"UndoState\",\"url\":\"interfaces/UndoState.html\",\"classes\":\"\"},{\"kind\":1024,\"name\":\"past\",\"url\":\"interfaces/UndoState.html#past\",\"classes\":\"\",\"parent\":\"UndoState\"},{\"kind\":1024,\"name\":\"future\",\"url\":\"interfaces/UndoState.html#future\",\"classes\":\"\",\"parent\":\"UndoState\"},{\"kind\":256,\"name\":\"NgUndoState\",\"url\":\"interfaces/NgUndoState.html\",\"classes\":\"\"},{\"kind\":256,\"name\":\"NgUndoAction\",\"url\":\"interfaces/NgUndoAction.html\",\"classes\":\"\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"interfaces/NgUndoAction.html#type-1\",\"classes\":\"\",\"parent\":\"NgUndoAction\"},{\"kind\":1024,\"name\":\"payload\",\"url\":\"interfaces/NgUndoAction.html#payload\",\"classes\":\"\",\"parent\":\"NgUndoAction\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"interfaces/NgUndoAction.html#payload.__type\",\"classes\":\"\",\"parent\":\"NgUndoAction.payload\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"interfaces/NgUndoAction.html#payload.__type.type\",\"classes\":\"\",\"parent\":\"NgUndoAction.payload.__type\"},{\"kind\":1024,\"name\":\"propertyName\",\"url\":\"interfaces/NgUndoAction.html#payload.__type.propertyName\",\"classes\":\"\",\"parent\":\"NgUndoAction.payload.__type\"},{\"kind\":1024,\"name\":\"index\",\"url\":\"interfaces/NgUndoAction.html#payload.__type.index\",\"classes\":\"\",\"parent\":\"NgUndoAction.payload.__type\"},{\"kind\":256,\"name\":\"StateWatchMap\",\"url\":\"interfaces/StateWatchMap.html\",\"classes\":\"\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"interfaces/StateWatchMap.html#__index.__type\",\"classes\":\"\",\"parent\":\"StateWatchMap.__index\"},{\"kind\":1024,\"name\":\"path\",\"url\":\"interfaces/StateWatchMap.html#__index.__type.path\",\"classes\":\"\",\"parent\":\"StateWatchMap.__index.__type\"},{\"kind\":64,\"name\":\"undo\",\"url\":\"functions/undo.html\",\"classes\":\"\"},{\"kind\":64,\"name\":\"redo\",\"url\":\"functions/redo.html\",\"classes\":\"\"},{\"kind\":64,\"name\":\"clearHistory\",\"url\":\"functions/clearHistory.html\",\"classes\":\"\"},{\"kind\":64,\"name\":\"jump\",\"url\":\"functions/jump.html\",\"classes\":\"\"},{\"kind\":64,\"name\":\"ngUndoState\",\"url\":\"functions/ngUndoState-1.html\",\"classes\":\"\"}],\"index\":{\"version\":\"2.3.9\",\"fields\":[\"name\",\"comment\"],\"fieldVectors\":[[\"name/0\",[0,31.499]],[\"comment/0\",[]],[\"name/1\",[1,31.499]],[\"comment/1\",[]],[\"name/2\",[2,31.499]],[\"comment/2\",[]],[\"name/3\",[3,31.499]],[\"comment/3\",[]],[\"name/4\",[4,23.026]],[\"comment/4\",[]],[\"name/5\",[5,31.499]],[\"comment/5\",[]],[\"name/6\",[6,31.499]],[\"comment/6\",[]],[\"name/7\",[7,31.499]],[\"comment/7\",[]],[\"name/8\",[8,31.499]],[\"comment/8\",[]],[\"name/9\",[9,31.499]],[\"comment/9\",[]],[\"name/10\",[10,31.499]],[\"comment/10\",[]],[\"name/11\",[11,26.391]],[\"comment/11\",[]],[\"name/12\",[12,26.391]],[\"comment/12\",[]],[\"name/13\",[13,26.391]],[\"comment/13\",[]],[\"name/14\",[14,31.499]],[\"comment/14\",[]],[\"name/15\",[15,31.499]],[\"comment/15\",[]],[\"name/16\",[16,31.499]],[\"comment/16\",[]],[\"name/17\",[17,31.499]],[\"comment/17\",[]],[\"name/18\",[18,26.391]],[\"comment/18\",[]],[\"name/19\",[19,31.499]],[\"comment/19\",[]],[\"name/20\",[20,26.391]],[\"comment/20\",[]],[\"name/21\",[21,31.499]],[\"comment/21\",[]],[\"name/22\",[4,23.026]],[\"comment/22\",[]],[\"name/23\",[20,26.391]],[\"comment/23\",[]],[\"name/24\",[22,31.499]],[\"comment/24\",[]],[\"name/25\",[23,31.499]],[\"comment/25\",[]],[\"name/26\",[24,31.499]],[\"comment/26\",[]],[\"name/27\",[4,23.026]],[\"comment/27\",[]],[\"name/28\",[25,31.499]],[\"comment/28\",[]],[\"name/29\",[11,26.391]],[\"comment/29\",[]],[\"name/30\",[12,26.391]],[\"comment/30\",[]],[\"name/31\",[26,31.499]],[\"comment/31\",[]],[\"name/32\",[13,26.391]],[\"comment/32\",[]],[\"name/33\",[18,26.391]],[\"comment/33\",[]]],\"invertedIndex\":[[\"__type\",{\"_index\":4,\"name\":{\"4\":{},\"22\":{},\"27\":{}},\"comment\":{}}],[\"clear_history\",{\"_index\":14,\"name\":{\"14\":{}},\"comment\":{}}],[\"clearhistory\",{\"_index\":26,\"name\":{\"31\":{}},\"comment\":{}}],[\"constructor\",{\"_index\":2,\"name\":{\"2\":{}},\"comment\":{}}],[\"detectchange\",{\"_index\":7,\"name\":{\"7\":{}},\"comment\":{}}],[\"future\",{\"_index\":17,\"name\":{\"17\":{}},\"comment\":{}}],[\"history_state_key\",{\"_index\":8,\"name\":{\"8\":{}},\"comment\":{}}],[\"index\",{\"_index\":23,\"name\":{\"25\":{}},\"comment\":{}}],[\"jump\",{\"_index\":13,\"name\":{\"13\":{},\"32\":{}},\"comment\":{}}],[\"ngundoaction\",{\"_index\":19,\"name\":{\"19\":{}},\"comment\":{}}],[\"ngundomiddleware\",{\"_index\":0,\"name\":{\"0\":{}},\"comment\":{}}],[\"ngundostate\",{\"_index\":18,\"name\":{\"18\":{},\"33\":{}},\"comment\":{}}],[\"past\",{\"_index\":16,\"name\":{\"16\":{}},\"comment\":{}}],[\"path\",{\"_index\":25,\"name\":{\"28\":{}},\"comment\":{}}],[\"payload\",{\"_index\":21,\"name\":{\"21\":{}},\"comment\":{}}],[\"propertyname\",{\"_index\":22,\"name\":{\"24\":{}},\"comment\":{}}],[\"redo\",{\"_index\":12,\"name\":{\"12\":{},\"30\":{}},\"comment\":{}}],[\"statewatchmap\",{\"_index\":24,\"name\":{\"26\":{}},\"comment\":{}}],[\"type\",{\"_index\":20,\"name\":{\"20\":{},\"23\":{}},\"comment\":{}}],[\"undo\",{\"_index\":11,\"name\":{\"11\":{},\"29\":{}},\"comment\":{}}],[\"undo_reducer_prefix\",{\"_index\":9,\"name\":{\"9\":{}},\"comment\":{}}],[\"undoactions\",{\"_index\":10,\"name\":{\"10\":{}},\"comment\":{}}],[\"undoservice\",{\"_index\":1,\"name\":{\"1\":{}},\"comment\":{}}],[\"undostate\",{\"_index\":15,\"name\":{\"15\":{}},\"comment\":{}}],[\"watcheraction\",{\"_index\":6,\"name\":{\"6\":{}},\"comment\":{}}],[\"watcherstate\",{\"_index\":5,\"name\":{\"5\":{}},\"comment\":{}}],[\"watchstatemap\",{\"_index\":3,\"name\":{\"3\":{}},\"comment\":{}}]],\"pipeline\":[]}}"); \ No newline at end of file +window.searchData = JSON.parse("{\"rows\":[{\"kind\":64,\"name\":\"ngUndoMiddleware\",\"url\":\"functions/ngUndoMiddleware.html\",\"classes\":\"\"},{\"kind\":128,\"name\":\"UndoService\",\"url\":\"classes/UndoService.html\",\"classes\":\"\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/UndoService.html#constructor\",\"classes\":\"\",\"parent\":\"UndoService\"},{\"kind\":1024,\"name\":\"watchStateMap\",\"url\":\"classes/UndoService.html#watchStateMap\",\"classes\":\"tsd-is-protected\",\"parent\":\"UndoService\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"classes/UndoService.html#watchStateMap.__type\",\"classes\":\"\",\"parent\":\"UndoService.watchStateMap\"},{\"kind\":2048,\"name\":\"watcherState\",\"url\":\"classes/UndoService.html#watcherState\",\"classes\":\"\",\"parent\":\"UndoService\"},{\"kind\":2048,\"name\":\"watcherAction\",\"url\":\"classes/UndoService.html#watcherAction\",\"classes\":\"tsd-is-protected\",\"parent\":\"UndoService\"},{\"kind\":2048,\"name\":\"detectChange\",\"url\":\"classes/UndoService.html#detectChange\",\"classes\":\"tsd-is-protected\",\"parent\":\"UndoService\"},{\"kind\":32,\"name\":\"HISTORY_STATE_KEY\",\"url\":\"variables/HISTORY_STATE_KEY.html\",\"classes\":\"\"},{\"kind\":32,\"name\":\"UNDO_REDUCER_PREFIX\",\"url\":\"variables/UNDO_REDUCER_PREFIX.html\",\"classes\":\"\"},{\"kind\":8,\"name\":\"UndoActions\",\"url\":\"enums/UndoActions.html\",\"classes\":\"\"},{\"kind\":16,\"name\":\"UNDO\",\"url\":\"enums/UndoActions.html#UNDO\",\"classes\":\"\",\"parent\":\"UndoActions\"},{\"kind\":16,\"name\":\"REDO\",\"url\":\"enums/UndoActions.html#REDO\",\"classes\":\"\",\"parent\":\"UndoActions\"},{\"kind\":16,\"name\":\"JUMP\",\"url\":\"enums/UndoActions.html#JUMP\",\"classes\":\"\",\"parent\":\"UndoActions\"},{\"kind\":16,\"name\":\"CLEAR_HISTORY\",\"url\":\"enums/UndoActions.html#CLEAR_HISTORY\",\"classes\":\"\",\"parent\":\"UndoActions\"},{\"kind\":256,\"name\":\"UndoState\",\"url\":\"interfaces/UndoState.html\",\"classes\":\"\"},{\"kind\":1024,\"name\":\"past\",\"url\":\"interfaces/UndoState.html#past\",\"classes\":\"\",\"parent\":\"UndoState\"},{\"kind\":1024,\"name\":\"future\",\"url\":\"interfaces/UndoState.html#future\",\"classes\":\"\",\"parent\":\"UndoState\"},{\"kind\":256,\"name\":\"NgUndoState\",\"url\":\"interfaces/NgUndoState.html\",\"classes\":\"\"},{\"kind\":256,\"name\":\"NgUndoAction\",\"url\":\"interfaces/NgUndoAction.html\",\"classes\":\"\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"interfaces/NgUndoAction.html#type-1\",\"classes\":\"\",\"parent\":\"NgUndoAction\"},{\"kind\":1024,\"name\":\"payload\",\"url\":\"interfaces/NgUndoAction.html#payload\",\"classes\":\"\",\"parent\":\"NgUndoAction\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"interfaces/NgUndoAction.html#payload.__type\",\"classes\":\"\",\"parent\":\"NgUndoAction.payload\"},{\"kind\":1024,\"name\":\"type\",\"url\":\"interfaces/NgUndoAction.html#payload.__type.type\",\"classes\":\"\",\"parent\":\"NgUndoAction.payload.__type\"},{\"kind\":1024,\"name\":\"propertyName\",\"url\":\"interfaces/NgUndoAction.html#payload.__type.propertyName\",\"classes\":\"\",\"parent\":\"NgUndoAction.payload.__type\"},{\"kind\":1024,\"name\":\"index\",\"url\":\"interfaces/NgUndoAction.html#payload.__type.index\",\"classes\":\"\",\"parent\":\"NgUndoAction.payload.__type\"},{\"kind\":256,\"name\":\"StateWatchMap\",\"url\":\"interfaces/StateWatchMap.html\",\"classes\":\"\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"interfaces/StateWatchMap.html#__index.__type\",\"classes\":\"\",\"parent\":\"StateWatchMap.__index\"},{\"kind\":1024,\"name\":\"path\",\"url\":\"interfaces/StateWatchMap.html#__index.__type.path\",\"classes\":\"\",\"parent\":\"StateWatchMap.__index.__type\"},{\"kind\":1024,\"name\":\"filter\",\"url\":\"interfaces/StateWatchMap.html#__index.__type.filter\",\"classes\":\"\",\"parent\":\"StateWatchMap.__index.__type\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"interfaces/StateWatchMap.html#__index.__type.filter.__type-1\",\"classes\":\"\",\"parent\":\"StateWatchMap.__index.__type.filter\"},{\"kind\":1024,\"name\":\"limit\",\"url\":\"interfaces/StateWatchMap.html#__index.__type.limit\",\"classes\":\"\",\"parent\":\"StateWatchMap.__index.__type\"},{\"kind\":256,\"name\":\"Settings\",\"url\":\"interfaces/Settings.html\",\"classes\":\"\"},{\"kind\":1024,\"name\":\"path\",\"url\":\"interfaces/Settings.html#path\",\"classes\":\"\",\"parent\":\"Settings\"},{\"kind\":1024,\"name\":\"filter\",\"url\":\"interfaces/Settings.html#filter\",\"classes\":\"\",\"parent\":\"Settings\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"interfaces/Settings.html#filter.__type\",\"classes\":\"\",\"parent\":\"Settings.filter\"},{\"kind\":1024,\"name\":\"limit\",\"url\":\"interfaces/Settings.html#limit\",\"classes\":\"\",\"parent\":\"Settings\"},{\"kind\":64,\"name\":\"undo\",\"url\":\"functions/undo.html\",\"classes\":\"\"},{\"kind\":64,\"name\":\"redo\",\"url\":\"functions/redo.html\",\"classes\":\"\"},{\"kind\":64,\"name\":\"clearHistory\",\"url\":\"functions/clearHistory.html\",\"classes\":\"\"},{\"kind\":64,\"name\":\"jump\",\"url\":\"functions/jump.html\",\"classes\":\"\"},{\"kind\":64,\"name\":\"ngUndoState\",\"url\":\"functions/ngUndoState-1.html\",\"classes\":\"\"}],\"index\":{\"version\":\"2.3.9\",\"fields\":[\"name\",\"comment\"],\"fieldVectors\":[[\"name/0\",[0,33.557]],[\"comment/0\",[]],[\"name/1\",[1,33.557]],[\"comment/1\",[]],[\"name/2\",[2,33.557]],[\"comment/2\",[]],[\"name/3\",[3,33.557]],[\"comment/3\",[]],[\"name/4\",[4,20.565]],[\"comment/4\",[]],[\"name/5\",[5,33.557]],[\"comment/5\",[]],[\"name/6\",[6,33.557]],[\"comment/6\",[]],[\"name/7\",[7,33.557]],[\"comment/7\",[]],[\"name/8\",[8,33.557]],[\"comment/8\",[]],[\"name/9\",[9,33.557]],[\"comment/9\",[]],[\"name/10\",[10,33.557]],[\"comment/10\",[]],[\"name/11\",[11,28.449]],[\"comment/11\",[]],[\"name/12\",[12,28.449]],[\"comment/12\",[]],[\"name/13\",[13,28.449]],[\"comment/13\",[]],[\"name/14\",[14,33.557]],[\"comment/14\",[]],[\"name/15\",[15,33.557]],[\"comment/15\",[]],[\"name/16\",[16,33.557]],[\"comment/16\",[]],[\"name/17\",[17,33.557]],[\"comment/17\",[]],[\"name/18\",[18,28.449]],[\"comment/18\",[]],[\"name/19\",[19,33.557]],[\"comment/19\",[]],[\"name/20\",[20,28.449]],[\"comment/20\",[]],[\"name/21\",[21,33.557]],[\"comment/21\",[]],[\"name/22\",[4,20.565]],[\"comment/22\",[]],[\"name/23\",[20,28.449]],[\"comment/23\",[]],[\"name/24\",[22,33.557]],[\"comment/24\",[]],[\"name/25\",[23,33.557]],[\"comment/25\",[]],[\"name/26\",[24,33.557]],[\"comment/26\",[]],[\"name/27\",[4,20.565]],[\"comment/27\",[]],[\"name/28\",[25,28.449]],[\"comment/28\",[]],[\"name/29\",[26,28.449]],[\"comment/29\",[]],[\"name/30\",[4,20.565]],[\"comment/30\",[]],[\"name/31\",[27,28.449]],[\"comment/31\",[]],[\"name/32\",[28,33.557]],[\"comment/32\",[]],[\"name/33\",[25,28.449]],[\"comment/33\",[]],[\"name/34\",[26,28.449]],[\"comment/34\",[]],[\"name/35\",[4,20.565]],[\"comment/35\",[]],[\"name/36\",[27,28.449]],[\"comment/36\",[]],[\"name/37\",[11,28.449]],[\"comment/37\",[]],[\"name/38\",[12,28.449]],[\"comment/38\",[]],[\"name/39\",[29,33.557]],[\"comment/39\",[]],[\"name/40\",[13,28.449]],[\"comment/40\",[]],[\"name/41\",[18,28.449]],[\"comment/41\",[]]],\"invertedIndex\":[[\"__type\",{\"_index\":4,\"name\":{\"4\":{},\"22\":{},\"27\":{},\"30\":{},\"35\":{}},\"comment\":{}}],[\"clear_history\",{\"_index\":14,\"name\":{\"14\":{}},\"comment\":{}}],[\"clearhistory\",{\"_index\":29,\"name\":{\"39\":{}},\"comment\":{}}],[\"constructor\",{\"_index\":2,\"name\":{\"2\":{}},\"comment\":{}}],[\"detectchange\",{\"_index\":7,\"name\":{\"7\":{}},\"comment\":{}}],[\"filter\",{\"_index\":26,\"name\":{\"29\":{},\"34\":{}},\"comment\":{}}],[\"future\",{\"_index\":17,\"name\":{\"17\":{}},\"comment\":{}}],[\"history_state_key\",{\"_index\":8,\"name\":{\"8\":{}},\"comment\":{}}],[\"index\",{\"_index\":23,\"name\":{\"25\":{}},\"comment\":{}}],[\"jump\",{\"_index\":13,\"name\":{\"13\":{},\"40\":{}},\"comment\":{}}],[\"limit\",{\"_index\":27,\"name\":{\"31\":{},\"36\":{}},\"comment\":{}}],[\"ngundoaction\",{\"_index\":19,\"name\":{\"19\":{}},\"comment\":{}}],[\"ngundomiddleware\",{\"_index\":0,\"name\":{\"0\":{}},\"comment\":{}}],[\"ngundostate\",{\"_index\":18,\"name\":{\"18\":{},\"41\":{}},\"comment\":{}}],[\"past\",{\"_index\":16,\"name\":{\"16\":{}},\"comment\":{}}],[\"path\",{\"_index\":25,\"name\":{\"28\":{},\"33\":{}},\"comment\":{}}],[\"payload\",{\"_index\":21,\"name\":{\"21\":{}},\"comment\":{}}],[\"propertyname\",{\"_index\":22,\"name\":{\"24\":{}},\"comment\":{}}],[\"redo\",{\"_index\":12,\"name\":{\"12\":{},\"38\":{}},\"comment\":{}}],[\"settings\",{\"_index\":28,\"name\":{\"32\":{}},\"comment\":{}}],[\"statewatchmap\",{\"_index\":24,\"name\":{\"26\":{}},\"comment\":{}}],[\"type\",{\"_index\":20,\"name\":{\"20\":{},\"23\":{}},\"comment\":{}}],[\"undo\",{\"_index\":11,\"name\":{\"11\":{},\"37\":{}},\"comment\":{}}],[\"undo_reducer_prefix\",{\"_index\":9,\"name\":{\"9\":{}},\"comment\":{}}],[\"undoactions\",{\"_index\":10,\"name\":{\"10\":{}},\"comment\":{}}],[\"undoservice\",{\"_index\":1,\"name\":{\"1\":{}},\"comment\":{}}],[\"undostate\",{\"_index\":15,\"name\":{\"15\":{}},\"comment\":{}}],[\"watcheraction\",{\"_index\":6,\"name\":{\"6\":{}},\"comment\":{}}],[\"watcherstate\",{\"_index\":5,\"name\":{\"5\":{}},\"comment\":{}}],[\"watchstatemap\",{\"_index\":3,\"name\":{\"3\":{}},\"comment\":{}}]],\"pipeline\":[]}}"); \ No newline at end of file diff --git a/docs/classes/UndoService.html b/docs/classes/UndoService.html index 4bbdeea..59bbd30 100644 --- a/docs/classes/UndoService.html +++ b/docs/classes/UndoService.html @@ -20,7 +20,7 @@

Hierarchy

  • UndoService
+
  • Defined in services/undo.service.ts:26
  • @@ -58,7 +58,7 @@
    stateWatchMap: Returns UndoService
    +
  • Defined in services/undo.service.ts:46
  • Properties

    @@ -72,13 +72,13 @@

    Type declaration

  • [key: string]: NgUndoStateActions
  • +
  • Defined in services/undo.service.ts:35
  • Methods

      - +
    • Protected

      Detects changes in the state and inserts snapshots into the undo history when necessary.

      @@ -86,6 +86,10 @@
      • +
        action: any
        +

        The dispatched action object.

        +
      • +
      • state: any

        The current state object.

      • @@ -98,7 +102,7 @@

        Returns any

    +
  • Defined in services/undo.service.ts:117
  • +
  • Defined in services/undo.service.ts:81
  • +
  • Defined in services/undo.service.ts:64
  • +
  • Defined in interfaces/undo.interface.ts:35
  • @@ -42,22 +42,22 @@

    Enumeration Members

    CLEAR_HISTORY: "clean_history"
    +
  • Defined in interfaces/undo.interface.ts:39
  • JUMP: "jump"
    +
  • Defined in interfaces/undo.interface.ts:38
  • REDO: "redo"
    +
  • Defined in interfaces/undo.interface.ts:37
  • UNDO: "undo"
    +
  • Defined in interfaces/undo.interface.ts:36
  • +
  • Defined in interfaces/undo.interface.ts:5