Angular Undo Redo History Store | ng-hub-ui-history
Angular undo and redo history store with Signals-friendly APIs, transactions, limits and reactive form support.
API reference
Here's the full contract for history: everything you can bind, listen to, project and theme, gathered in one place. Wire up what you need and style what you want — it's standalone and signal-friendly.
Inputs
Dial history in with 4 inputs. Bind them like any Angular @Input.
| Name | Type | Default | Description |
|---|---|---|---|
createHistoryStore(config) | HistoryStoreConfig<T, K> | — | Creates a signal-based store with optional limits and custom diff/patch functions. |
registerObject(id, initialState)Required | (id: K, initialState: T) => void | — | Registers object base state and starts linear history for that key. |
commit(id, newState, options?)Required | (id: K, state: T, options?: { label?: string }) => boolean | — | Stores diff patch, invalidates redo branch if pointer was not at tail. |
watchForm(id, form, options?) | (id: K, form: FormGroup, options?: WatchFormOptions) => () => void | — | Automatically commits form value changes and returns unsubscribe callback. |
Outputs
React to what history does — 1 events to hook your logic onto.
| Name | Type | Description |
|---|---|---|
states | Signal<Map<K, T>> | Reactive signal map with current immutable snapshots per object id. |
Methods
Drive history from code — 16 methods on its programmatic surface.
| Name | Signature | Returns | Description |
|---|---|---|---|
createHistoryStore | createHistoryStore<T, K>(config?: HistoryStoreConfig<T, K>): HistoryStore<T, K> | HistoryStore<T, K> | Factory that creates a signal-based history store tracking multiple objects by id. Accepts optional retention limits (maxEntries, default 100; maxBytes, default 512000), a keySelector, and custom diff/patch strategies. |
HistoryStore.states | states: Signal<Map<K, T>> | Signal<Map<K, T>> | Computed signal exposing a map of the current immutable state snapshots keyed by object id. |
HistoryStore.registerObject | registerObject(id: K, initialState: T): void | — | Registers a tracked object with its initial state and starts a fresh, empty history timeline for that id. |
HistoryStore.registerFromObject | registerFromObject(initialState: T): K | K | Registers a tracked object deriving its id from the configured keySelector and returns that id. Throws when no keySelector was configured. |
HistoryStore.commit | commit(id: K, newState: T, options?: HistoryCommitOptions): boolean | boolean | Commits a new state snapshot for a registered id, storing forward and backward patches and discarding any redo entries ahead of the pointer. Returns false when the new state produces no changes. Inside an open transaction it only updates the current state without creating an entry. |
HistoryStore.commitFromObject | commitFromObject(newState: T, options?: HistoryCommitOptions): boolean | boolean | Commits a new state deriving the id from the configured keySelector. Throws when no keySelector was configured. |
HistoryStore.undo | undo(id: K): boolean | boolean | Reverts one history step by applying the entry's backward patch. Returns false when there is nothing to undo. |
HistoryStore.redo | redo(id: K): boolean | boolean | Re-applies one history step by applying the entry's forward patch. Returns false when there is nothing to redo. |
HistoryStore.canUndo | canUndo(id: K): boolean | boolean | Returns whether undo is currently possible for the given object id. |
HistoryStore.canRedo | canRedo(id: K): boolean | boolean | Returns whether redo is currently possible for the given object id. |
HistoryStore.getState | getState(id: K): T | undefined | T | undefined | Returns a deep clone of the current state for the given id, or undefined when the id is not registered. |
HistoryStore.history | history(id: K): HistoryMetadata | HistoryMetadata | Returns readonly metadata for the object's history: the pointer, entry count, approximate retained bytes, and per-entry label, timestamp, and bytes. |
HistoryStore.beginTransaction | beginTransaction(id: K, label?: string): void | — | Starts a transaction so subsequent commits are collapsed into a single consolidated history entry. Throws when a transaction is already open for the id. |
HistoryStore.endTransaction | endTransaction(id: K): boolean | boolean | Ends the open transaction, committing one consolidated entry from the transaction start state to the current state. Returns false when no transaction was open or no changes were made. |
HistoryStore.watchForm | watchForm(id: K, form: FormGroup, options?: WatchFormOptions): () => void | () => void | Subscribes to a FormGroup's valueChanges and automatically commits each emission, optionally skipping the initial one. Returns an unsubscribe callback. |
HistoryStore.clearHistory | clearHistory(id: K): void | — | Clears all history entries for the given id, keeping the current state as the new base snapshot and discarding any open transaction. |
Templates
No templates documented yet.