mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
chore(schema): add getById
This commit is contained in:
parent
15eacf26d5
commit
1825f8bd9b
2 changed files with 11 additions and 0 deletions
|
|
@ -1,8 +1,10 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {select, Store} from '@ngrx/store';
|
||||
import {take} from 'rxjs/operators';
|
||||
import {
|
||||
initial<%= classify(name)%>State,
|
||||
selectAll<%= classify(name)%>s,
|
||||
select<%= classify(name)%>ById,
|
||||
} from './store/<%= camelize(name)%>.reducer';
|
||||
import {Add<%= classify(name)%>, Delete<%= classify(name)%>, Load<%= classify(name)%>State, Update<%= classify(name)%>} from './store/<%= dasherize(name)%>.actions';
|
||||
import {Observable} from 'rxjs';
|
||||
|
|
@ -26,6 +28,10 @@ export class <%= classify(name)%>Service {
|
|||
this.loadState(ls<%= classify(name)%>State || initial<%= classify(name)%>State);
|
||||
}
|
||||
|
||||
get<%= classify(name)%>ById(id: string): Observable<<%= classify(name)%>> {
|
||||
return this._store$.pipe(select(select<%= classify(name)%>ById, {id}), take(1));
|
||||
}
|
||||
|
||||
loadState(state: <%= classify(name)%>State) {
|
||||
this._store$.dispatch(new Load<%= classify(name)%>State({state}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ export const adapter: EntityAdapter<<%= classify(name)%>> = createEntityAdapter<
|
|||
export const select<%= classify(name)%>FeatureState = createFeatureSelector<<%= classify(name)%>State>(<%= underscore(name).toUpperCase()%>_FEATURE_NAME);
|
||||
export const {selectIds, selectEntities, selectAll, selectTotal} = adapter.getSelectors();
|
||||
export const selectAll<%= classify(name)%>s = createSelector(select<%= classify(name)%>FeatureState, selectAll);
|
||||
export const select<%= classify(name)%>ById = createSelector(
|
||||
select<%= classify(name)%>FeatureState,
|
||||
(state, props: { id: string }) => state.entities[props.id]
|
||||
);
|
||||
|
||||
|
||||
export const initial<%= classify(name)%>State: <%= classify(name)%>State = adapter.getInitialState({
|
||||
// additional entity state properties
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue