@ngneat/elf-state-history
Advanced tools
Comparing version 1.2.2 to 1.3.0
@@ -5,2 +5,11 @@ # Changelog | ||
# [1.3.0](https://github.com/ngneat/elf/compare/state-history-1.2.2...state-history-1.3.0) (2022-09-30) | ||
### Features | ||
* **state-history:** expose methods for retrieving future and past ([#341](https://github.com/ngneat/elf/issues/341)) ([6dc1a9f](https://github.com/ngneat/elf/commit/6dc1a9f1b8067b87286df1db3270d5b063440d18)) | ||
## [1.2.2](https://github.com/ngneat/elf/compare/state-history-1.2.1...state-history-1.2.2) (2022-09-09) | ||
@@ -7,0 +16,0 @@ |
32
index.js
@@ -36,2 +36,10 @@ import { isFunction, coerceArray, filterNil, isUndefined } from '@ngneat/elf'; | ||
getPast() { | ||
return this.history.past; | ||
} | ||
getFuture() { | ||
return this.history.future; | ||
} | ||
activate() { | ||
@@ -252,2 +260,26 @@ this.subscription = this.store.pipe(filter(() => !(this.skipUpdate || this.paused))).subscribe(present => { | ||
getEntitiesPast(options = { | ||
showIfEmpty: false | ||
}) { | ||
const pastByIds = {}; | ||
this.entitiesHistory.forEach((history, id) => { | ||
if (options.showIfEmpty || history.past.length) { | ||
pastByIds[id] = history.past; | ||
} | ||
}); | ||
return pastByIds; | ||
} | ||
getEntitiesFuture(options = { | ||
showIfEmpty: false | ||
}) { | ||
const futureByIds = {}; | ||
this.entitiesHistory.forEach((history, id) => { | ||
if (options.showIfEmpty || history.future.length) { | ||
futureByIds[id] = history.future; | ||
} | ||
}); | ||
return futureByIds; | ||
} | ||
undo(ids) { | ||
@@ -254,0 +286,0 @@ const entities = []; |
import { Store, OrArray, StoreValue } from '@ngneat/elf'; | ||
import { EntitiesState, getIdType, EntitiesRef, getEntityType, DefaultEntitiesRef } from '@ngneat/elf-entities'; | ||
export interface EntitiesTimelineOptions { | ||
showIfEmpty: boolean; | ||
} | ||
export interface EntitiesStateHistoryOptions<T extends Store<any, StoreValue<any> & EntitiesState<E>>, E extends EntitiesRef, S extends StoreValue<T> = StoreValue<T>> { | ||
@@ -27,2 +30,4 @@ maxAge: number; | ||
hasFuture(id: getIdType<S, E>): boolean; | ||
getEntitiesPast(options?: EntitiesTimelineOptions): Record<getIdType<EntitiesState<E>, E>, Array<getEntityType<EntitiesState<E>, E>>>; | ||
getEntitiesFuture(options?: EntitiesTimelineOptions): Record<getIdType<EntitiesState<E>, E>, Array<getEntityType<EntitiesState<E>, E>>>; | ||
undo(ids?: OrArray<getIdType<S, E>>): void; | ||
@@ -29,0 +34,0 @@ redo(ids?: OrArray<getIdType<S, E>>): void; |
@@ -26,2 +26,4 @@ import { Store, StoreValue } from '@ngneat/elf'; | ||
get hasFuture(): boolean; | ||
getPast(): History<State>['past']; | ||
getFuture(): History<State>['future']; | ||
activate(): void; | ||
@@ -28,0 +30,0 @@ undo(): void; |
{ | ||
"name": "@ngneat/elf-state-history", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "State history management for elf store", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37769
1127