- Akita now complied with
target: ES2020
. - Remove coupling to Angular by removing the
ngOnDestroy
method from the store. If you're using a store inside a component's provider, you need to call it manually:
@Injectable()
class TodosStore extends Store {
ngOnDestroy() {
this.destroy();
}
}
- All Angular packages peer dependency is Angular v13.
- Remove the
effects
package in favor of ngneat/effects
- Upgrade to TS v4 and support tslib v2.0
- New effects package
- Updated
QueryEntity
typing ofselect
/get
methods to respectundefined
entity values. - Remove deprecated array utils functions.
- Remove deprecated
exclude
option from persist state. Useinclude
with a callback option. - The
upsert
operator ofEntityStore
now accepts an explicit entity initialization callback that'll be used as the initial value of the entity if it doesn't exist. ( this isn't a breaking change )
store.upsert(
[2, 3],
(entity) => ({ isOpen: !(entity?.isOpen ?? true) }),
(id, newState) => ({ id, ...newState, enabled: true })
);
- The
runStoreAction
is rewritten as well to support type safe entity operations:
// Before
runStoreAction('books', StoreActions.UpsertEntities, {
payload: {
data: { title: 'New Title' },
entityIds: [2, 3],
},
});
// After
runEntityStoreAction(BooksStore, EntityStoreAction.UpsertEntities, (upsert) => upsert([2, 3], { title: 'New Title' }, (id, newState) => ({ id, ...newState, price: 0 })));
It also takes the store name as string.
- A new select option for the
persistState
plugin.
Most of the breaking changes in this version are related to types changes.
- EntityStore and QueryEntity now don't require the second generic entity type:
// Before
export interface ProductsState extends EntityState<Product> {}
@StoreConfig({ name: 'products' })
export class ProductsStore extends EntityStore<ProductsState, Product> {
constructor() { super();
}
export class ProductsQuery extends QueryEntity<ProductsState, Product> {
constructor(protected store: ProductsStore) {
super(store);
}
}
// After
export interface ProductsState extends EntityState<Product> {}
@StoreConfig({ name: 'products' })
export class ProductsStore extends EntityStore<ProductsState> {
constructor() { super();
}
export class ProductsQuery extends QueryEntity<ProductsState> {
constructor(protected store: ProductsStore) {
super(store);
}
}
For now, we keep a deprecated generic, so it will not break any existing code, but please, don't use it anymore.
- Removed the unused error state type -
EntityState<Product, StateErrorType>
. - Custom ID type location is changed:
// Before:
export interface ProductsState extends EntityState<Product> {}
@StoreConfig({ name: 'products' })
export class ProductsStore extends EntityStore<ProductsState, Product, string> {
constructor() { super();
}
// After
export interface ProductsState extends EntityState<Product, string> {}
@StoreConfig({ name: 'products' })
export class ProductsStore extends EntityStore<ProductsState> {
constructor() { super();
}
- Removed deprecated
selectUpdatedEntityIds
method in favor ofselectEntityAction
. - Removed deprecated
waitForTransaction
method in favor ofauditTime
. - The default entity id type changed from
ID
which wasnumber | string
toany
. We now recommend to strict your type in the secondEntityState
generic parameter.
Entity plugins now require one generic, which is the store's type instead of the entity type.
new EntityDirtyCheckPlugin<WidgetsState>
new EntityStateHistoryPlugin<WidgetsState>
new PaginatorPlugin<WidgetsState>
- Firebase integration.
- In dev mode, you can now use
window.$$stores
andwindow.$$queries
to obtain a reference to the stores or the queries. - persistState plugin performance optimization option.
- persistState plugin custom hooks support.
- Add a
replace
method to EntityStore. - PaginatorPlugin add a
refreshCurrentPage
method. - HistoryPlugin add a custom clear function.
- selectEntity now support predicate function -
query.selectEntity(e => e.title === 'title')
. - Add Entity Actions API.
StoreConfig
can take a custom deep freeze function.
EntityStore.set()
- removeoptions
param, i.eentityClass
..- Remove
EntityStore.createOrReplace()
in favor ofEntityStore.upsert()
. - Remove
EntityStore.updateRoot()
in favor ofEntityStore.update()
. - Remove
EntityStore.updateAll()
in favor ofEntityStore.update(null, newState)
, Store.setState
is internal and changed to_setState()
- use only theupdate()
method.- Remove
mapWorker
. - Remove array helpers.
- Remove
decrement
andincrement
functions. - Remove
Query.selectOnce
- useselect().pipe(take(1))
. - Remove deprecated
Query.getSnapshot()
. - Remove
noop
- use theof()
observable. - Remove
isPristine
andisDirty
in favor of newcaching
functionality. - The
action
decorator takes the action name instead of an object. - Remove
EntityStore.isEmpty
in favor ofEntityStore.hasEntity()
.
- Update typescript to v3.2.
- Remove the
getInitialActiveState()
function. - Entity dirty check plugin: remove deprecated
isSomeDirty
andsomeDirty
.
- Deprecate
getSnapshot()
in favor ofgetValue()
. - Remove redundant
options
param fromselectMulti
, - When using the
active
functionality always add the initialactive
state. For single:
export interface State extends EntityState<Widget>, ActiveState {}
const initialState = {
active: null,
};
@StoreConfig({ name: 'widgets' })
export class WidgetsStore extends EntityStore<WidgetsState, Widget> {
constructor() {
super(initialState);
}
}
And for multi:
export interface State extends EntityState<Widget>, MultiActiveState {}
const initialState = {
active: [],
};
@StoreConfig({ name: 'widgets' })
export class WidgetsStore extends EntityStore<WidgetsState, Widget> {
constructor() {
super(initialState);
}
}
- Add support for multiple active entities 🎉
filterNil
operator strongly typedselectFirst
andselectLast
selectors