@ngrx-traits/common 12.1.2 → 13.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/crud-entities/crud-entities.model.d.ts +1 -3
- package/entities-pagination/entities-pagination.model.d.ts +8 -11
- package/entities-pagination/entities-pagination.model.internal.d.ts +9 -1
- package/esm2020/async-action/async-action.model.mjs +2 -0
- package/esm2020/async-action/async-action.trait.mjs +110 -0
- package/esm2020/async-action/index.mjs +3 -0
- package/esm2020/crud-entities/crud-entities.model.mjs +8 -0
- package/esm2020/crud-entities/crud-entities.trait.actions.mjs +20 -0
- package/esm2020/crud-entities/crud-entities.trait.mjs +57 -0
- package/esm2020/crud-entities/crud-entities.trait.mutators.mjs +121 -0
- package/esm2020/crud-entities/crud-entities.trait.reducer.mjs +17 -0
- package/esm2020/crud-entities/crud-entities.trait.selectors.mjs +54 -0
- package/esm2020/crud-entities/index.mjs +3 -0
- package/esm2020/entities-pagination/entities-pagination.model.internal.mjs +2 -0
- package/esm2020/entities-pagination/entities-pagination.model.mjs +2 -0
- package/esm2020/entities-pagination/entities-pagination.trait.actions.mjs +20 -0
- package/esm2020/entities-pagination/entities-pagination.trait.effects.mjs +62 -0
- package/esm2020/entities-pagination/entities-pagination.trait.mjs +94 -0
- package/esm2020/entities-pagination/entities-pagination.trait.mutators.mjs +55 -0
- package/esm2020/entities-pagination/entities-pagination.trait.reducer.mjs +87 -0
- package/esm2020/entities-pagination/entities-pagination.trait.selectors.mjs +84 -0
- package/esm2020/entities-pagination/index.mjs +3 -0
- package/esm2020/filter-entities/filter-entities.model.internal.mjs +2 -0
- package/esm2020/filter-entities/filter-entities.model.mjs +2 -0
- package/esm2020/filter-entities/filter-entities.trait.actions.mjs +16 -0
- package/esm2020/filter-entities/filter-entities.trait.effect.mjs +59 -0
- package/esm2020/filter-entities/filter-entities.trait.mjs +73 -0
- package/esm2020/filter-entities/filter-entities.trait.mutators.mjs +10 -0
- package/esm2020/filter-entities/filter-entities.trait.reducer.mjs +11 -0
- package/esm2020/filter-entities/filter-entities.trait.selectors.mjs +9 -0
- package/esm2020/filter-entities/index.mjs +3 -0
- package/esm2020/index.mjs +12 -0
- package/esm2020/load-entities/index.mjs +3 -0
- package/esm2020/load-entities/load-entities.model.mjs +2 -0
- package/esm2020/load-entities/load-entities.mutators.mjs +7 -0
- package/esm2020/load-entities/load-entities.trait.actions.mjs +10 -0
- package/esm2020/load-entities/load-entities.trait.mjs +62 -0
- package/esm2020/load-entities/load-entities.trait.reducer.mjs +27 -0
- package/esm2020/load-entities/load-entities.trait.selectors.mjs +38 -0
- package/esm2020/load-entities/load-entities.utils.mjs +10 -0
- package/esm2020/load-entity/index.mjs +3 -0
- package/esm2020/load-entity/load-entity.model.mjs +2 -0
- package/esm2020/load-entity/load-entity.traits.mjs +74 -0
- package/esm2020/ngrx-traits-common.mjs +5 -0
- package/esm2020/public_api.mjs +2 -0
- package/esm2020/reset/index.mjs +2 -0
- package/esm2020/reset/reset.trait.mjs +39 -0
- package/esm2020/select-entities/index.mjs +4 -0
- package/esm2020/select-entities/select-entities.model.mjs +2 -0
- package/esm2020/select-entities/select-entities.trait.actions.mjs +11 -0
- package/esm2020/select-entities/select-entities.trait.mjs +54 -0
- package/esm2020/select-entities/select-entities.trait.mutators.mjs +27 -0
- package/esm2020/select-entities/select-entities.trait.reducer.mjs +42 -0
- package/esm2020/select-entities/select-entities.trait.selectors.mjs +28 -0
- package/esm2020/select-entities/select-entities.utils.mjs +30 -0
- package/esm2020/select-entity/index.mjs +3 -0
- package/esm2020/select-entity/select-entity.model.mjs +2 -0
- package/esm2020/select-entity/select-entity.trait.actions.mjs +9 -0
- package/esm2020/select-entity/select-entity.trait.mjs +51 -0
- package/esm2020/select-entity/select-entity.trait.mutators.mjs +26 -0
- package/esm2020/select-entity/select-entity.trait.reducer.mjs +35 -0
- package/esm2020/select-entity/select-entity.trait.selectors.mjs +13 -0
- package/esm2020/set-entity/index.mjs +3 -0
- package/esm2020/set-entity/set-entity.model.mjs +2 -0
- package/esm2020/set-entity/set-entity.trait.mjs +58 -0
- package/esm2020/sort-entities/index.mjs +4 -0
- package/esm2020/sort-entities/sort-entities.model.mjs +2 -0
- package/esm2020/sort-entities/sort-entities.trait.actions.mjs +8 -0
- package/esm2020/sort-entities/sort-entities.trait.effect.mjs +28 -0
- package/esm2020/sort-entities/sort-entities.trait.mjs +59 -0
- package/esm2020/sort-entities/sort-entities.trait.mutators.mjs +17 -0
- package/esm2020/sort-entities/sort-entities.trait.reducer.mjs +28 -0
- package/esm2020/sort-entities/sort-entities.trait.selectors.mjs +9 -0
- package/esm2020/sort-entities/sort-entities.utils.mjs +63 -0
- package/fesm2015/{ngrx-traits-common.js → ngrx-traits-common.mjs} +57 -77
- package/fesm2015/ngrx-traits-common.mjs.map +1 -0
- package/fesm2020/ngrx-traits-common.mjs +1748 -0
- package/fesm2020/ngrx-traits-common.mjs.map +1 -0
- package/load-entity/load-entity.traits.d.ts +1 -1
- package/package.json +27 -15
- package/reset/reset.trait.d.ts +3 -4
- package/set-entity/set-entity.trait.d.ts +1 -1
- package/bundles/ngrx-traits-common.umd.js +0 -2194
- package/bundles/ngrx-traits-common.umd.js.map +0 -1
- package/esm2015/async-action/async-action.model.js +0 -2
- package/esm2015/async-action/async-action.model.js.map +0 -1
- package/esm2015/async-action/async-action.trait.js +0 -101
- package/esm2015/async-action/async-action.trait.js.map +0 -1
- package/esm2015/async-action/index.js +0 -3
- package/esm2015/async-action/index.js.map +0 -1
- package/esm2015/crud-entities/crud-entities.model.js +0 -8
- package/esm2015/crud-entities/crud-entities.model.js.map +0 -1
- package/esm2015/crud-entities/crud-entities.trait.actions.js +0 -20
- package/esm2015/crud-entities/crud-entities.trait.actions.js.map +0 -1
- package/esm2015/crud-entities/crud-entities.trait.js +0 -57
- package/esm2015/crud-entities/crud-entities.trait.js.map +0 -1
- package/esm2015/crud-entities/crud-entities.trait.mutators.js +0 -101
- package/esm2015/crud-entities/crud-entities.trait.mutators.js.map +0 -1
- package/esm2015/crud-entities/crud-entities.trait.reducer.js +0 -15
- package/esm2015/crud-entities/crud-entities.trait.reducer.js.map +0 -1
- package/esm2015/crud-entities/crud-entities.trait.selectors.js +0 -70
- package/esm2015/crud-entities/crud-entities.trait.selectors.js.map +0 -1
- package/esm2015/crud-entities/index.js +0 -3
- package/esm2015/crud-entities/index.js.map +0 -1
- package/esm2015/entities-pagination/entities-pagination.model.internal.js +0 -2
- package/esm2015/entities-pagination/entities-pagination.model.internal.js.map +0 -1
- package/esm2015/entities-pagination/entities-pagination.model.js +0 -2
- package/esm2015/entities-pagination/entities-pagination.model.js.map +0 -1
- package/esm2015/entities-pagination/entities-pagination.trait.actions.js +0 -20
- package/esm2015/entities-pagination/entities-pagination.trait.actions.js.map +0 -1
- package/esm2015/entities-pagination/entities-pagination.trait.effects.js +0 -54
- package/esm2015/entities-pagination/entities-pagination.trait.effects.js.map +0 -1
- package/esm2015/entities-pagination/entities-pagination.trait.js +0 -94
- package/esm2015/entities-pagination/entities-pagination.trait.js.map +0 -1
- package/esm2015/entities-pagination/entities-pagination.trait.mutators.js +0 -23
- package/esm2015/entities-pagination/entities-pagination.trait.mutators.js.map +0 -1
- package/esm2015/entities-pagination/entities-pagination.trait.reducer.js +0 -33
- package/esm2015/entities-pagination/entities-pagination.trait.reducer.js.map +0 -1
- package/esm2015/entities-pagination/entities-pagination.trait.selectors.js +0 -65
- package/esm2015/entities-pagination/entities-pagination.trait.selectors.js.map +0 -1
- package/esm2015/entities-pagination/index.js +0 -3
- package/esm2015/entities-pagination/index.js.map +0 -1
- package/esm2015/filter-entities/filter-entities.model.internal.js +0 -2
- package/esm2015/filter-entities/filter-entities.model.internal.js.map +0 -1
- package/esm2015/filter-entities/filter-entities.model.js +0 -2
- package/esm2015/filter-entities/filter-entities.model.js.map +0 -1
- package/esm2015/filter-entities/filter-entities.trait.actions.js +0 -16
- package/esm2015/filter-entities/filter-entities.trait.actions.js.map +0 -1
- package/esm2015/filter-entities/filter-entities.trait.effect.js +0 -56
- package/esm2015/filter-entities/filter-entities.trait.effect.js.map +0 -1
- package/esm2015/filter-entities/filter-entities.trait.js +0 -73
- package/esm2015/filter-entities/filter-entities.trait.js.map +0 -1
- package/esm2015/filter-entities/filter-entities.trait.mutators.js +0 -7
- package/esm2015/filter-entities/filter-entities.trait.mutators.js.map +0 -1
- package/esm2015/filter-entities/filter-entities.trait.reducer.js +0 -9
- package/esm2015/filter-entities/filter-entities.trait.reducer.js.map +0 -1
- package/esm2015/filter-entities/filter-entities.trait.selectors.js +0 -9
- package/esm2015/filter-entities/filter-entities.trait.selectors.js.map +0 -1
- package/esm2015/filter-entities/index.js +0 -3
- package/esm2015/filter-entities/index.js.map +0 -1
- package/esm2015/index.js +0 -12
- package/esm2015/index.js.map +0 -1
- package/esm2015/load-entities/index.js +0 -3
- package/esm2015/load-entities/index.js.map +0 -1
- package/esm2015/load-entities/load-entities.model.js +0 -2
- package/esm2015/load-entities/load-entities.model.js.map +0 -1
- package/esm2015/load-entities/load-entities.mutators.js +0 -8
- package/esm2015/load-entities/load-entities.mutators.js.map +0 -1
- package/esm2015/load-entities/load-entities.trait.actions.js +0 -10
- package/esm2015/load-entities/load-entities.trait.actions.js.map +0 -1
- package/esm2015/load-entities/load-entities.trait.js +0 -62
- package/esm2015/load-entities/load-entities.trait.js.map +0 -1
- package/esm2015/load-entities/load-entities.trait.reducer.js +0 -12
- package/esm2015/load-entities/load-entities.trait.reducer.js.map +0 -1
- package/esm2015/load-entities/load-entities.trait.selectors.js +0 -33
- package/esm2015/load-entities/load-entities.trait.selectors.js.map +0 -1
- package/esm2015/load-entities/load-entities.utils.js +0 -10
- package/esm2015/load-entities/load-entities.utils.js.map +0 -1
- package/esm2015/load-entity/index.js +0 -3
- package/esm2015/load-entity/index.js.map +0 -1
- package/esm2015/load-entity/load-entity.model.js +0 -2
- package/esm2015/load-entity/load-entity.model.js.map +0 -1
- package/esm2015/load-entity/load-entity.traits.js +0 -71
- package/esm2015/load-entity/load-entity.traits.js.map +0 -1
- package/esm2015/ngrx-traits-common.js +0 -5
- package/esm2015/ngrx-traits-common.js.map +0 -1
- package/esm2015/public_api.js +0 -2
- package/esm2015/public_api.js.map +0 -1
- package/esm2015/reset/index.js +0 -2
- package/esm2015/reset/index.js.map +0 -1
- package/esm2015/reset/reset.trait.js +0 -69
- package/esm2015/reset/reset.trait.js.map +0 -1
- package/esm2015/select-entities/index.js +0 -4
- package/esm2015/select-entities/index.js.map +0 -1
- package/esm2015/select-entities/select-entities.model.js +0 -2
- package/esm2015/select-entities/select-entities.model.js.map +0 -1
- package/esm2015/select-entities/select-entities.trait.actions.js +0 -11
- package/esm2015/select-entities/select-entities.trait.actions.js.map +0 -1
- package/esm2015/select-entities/select-entities.trait.js +0 -54
- package/esm2015/select-entities/select-entities.trait.js.map +0 -1
- package/esm2015/select-entities/select-entities.trait.mutators.js +0 -21
- package/esm2015/select-entities/select-entities.trait.mutators.js.map +0 -1
- package/esm2015/select-entities/select-entities.trait.reducer.js +0 -40
- package/esm2015/select-entities/select-entities.trait.reducer.js.map +0 -1
- package/esm2015/select-entities/select-entities.trait.selectors.js +0 -28
- package/esm2015/select-entities/select-entities.trait.selectors.js.map +0 -1
- package/esm2015/select-entities/select-entities.utils.js +0 -25
- package/esm2015/select-entities/select-entities.utils.js.map +0 -1
- package/esm2015/select-entity/index.js +0 -3
- package/esm2015/select-entity/index.js.map +0 -1
- package/esm2015/select-entity/select-entity.model.js +0 -2
- package/esm2015/select-entity/select-entity.model.js.map +0 -1
- package/esm2015/select-entity/select-entity.trait.actions.js +0 -9
- package/esm2015/select-entity/select-entity.trait.actions.js.map +0 -1
- package/esm2015/select-entity/select-entity.trait.js +0 -51
- package/esm2015/select-entity/select-entity.trait.js.map +0 -1
- package/esm2015/select-entity/select-entity.trait.mutators.js +0 -17
- package/esm2015/select-entity/select-entity.trait.mutators.js.map +0 -1
- package/esm2015/select-entity/select-entity.trait.reducer.js +0 -26
- package/esm2015/select-entity/select-entity.trait.reducer.js.map +0 -1
- package/esm2015/select-entity/select-entity.trait.selectors.js +0 -13
- package/esm2015/select-entity/select-entity.trait.selectors.js.map +0 -1
- package/esm2015/set-entity/index.js +0 -3
- package/esm2015/set-entity/index.js.map +0 -1
- package/esm2015/set-entity/set-entity.model.js +0 -2
- package/esm2015/set-entity/set-entity.model.js.map +0 -1
- package/esm2015/set-entity/set-entity.trait.js +0 -55
- package/esm2015/set-entity/set-entity.trait.js.map +0 -1
- package/esm2015/sort-entities/index.js +0 -4
- package/esm2015/sort-entities/index.js.map +0 -1
- package/esm2015/sort-entities/sort-entities.model.js +0 -2
- package/esm2015/sort-entities/sort-entities.model.js.map +0 -1
- package/esm2015/sort-entities/sort-entities.trait.actions.js +0 -8
- package/esm2015/sort-entities/sort-entities.trait.actions.js.map +0 -1
- package/esm2015/sort-entities/sort-entities.trait.effect.js +0 -28
- package/esm2015/sort-entities/sort-entities.trait.effect.js.map +0 -1
- package/esm2015/sort-entities/sort-entities.trait.js +0 -59
- package/esm2015/sort-entities/sort-entities.trait.js.map +0 -1
- package/esm2015/sort-entities/sort-entities.trait.mutators.js +0 -13
- package/esm2015/sort-entities/sort-entities.trait.mutators.js.map +0 -1
- package/esm2015/sort-entities/sort-entities.trait.reducer.js +0 -22
- package/esm2015/sort-entities/sort-entities.trait.reducer.js.map +0 -1
- package/esm2015/sort-entities/sort-entities.trait.selectors.js +0 -10
- package/esm2015/sort-entities/sort-entities.trait.selectors.js.map +0 -1
- package/esm2015/sort-entities/sort-entities.utils.js +0 -63
- package/esm2015/sort-entities/sort-entities.utils.js.map +0 -1
- package/fesm2015/ngrx-traits-common.js.map +0 -1
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { insertIf } from '@ngrx-traits/core';
|
|
2
|
-
import { createReducer, on } from '@ngrx/store';
|
|
3
|
-
export function createSelectEntitiesInitialState(previousInitialState) {
|
|
4
|
-
return Object.assign(Object.assign({}, previousInitialState), { selectedIds: {} });
|
|
5
|
-
}
|
|
6
|
-
export function createSelectEntitiesTraitReducer(initialState, allActions, allMutators, allConfigs) {
|
|
7
|
-
var _a, _b;
|
|
8
|
-
const { adapter } = allConfigs.loadEntities;
|
|
9
|
-
const sortRemote = (_a = allConfigs.sort) === null || _a === void 0 ? void 0 : _a.remote;
|
|
10
|
-
const paginationCacheType = (_b = allConfigs.pagination) === null || _b === void 0 ? void 0 : _b.cacheType;
|
|
11
|
-
function updateSelectedIdsChanged(state, updates) {
|
|
12
|
-
const changedIds = updates.reduce((acc, updated) => {
|
|
13
|
-
const id = adapter.selectId(updated.changes);
|
|
14
|
-
if (id && id !== updated.id && state.selectedIds[updated.id] != null) {
|
|
15
|
-
acc.push(updated);
|
|
16
|
-
return acc;
|
|
17
|
-
}
|
|
18
|
-
return acc;
|
|
19
|
-
}, []);
|
|
20
|
-
if (changedIds.length) {
|
|
21
|
-
const selectedIds = Object.assign({}, state.selectedIds);
|
|
22
|
-
changedIds.forEach((updated) => {
|
|
23
|
-
const id = adapter.selectId(updated.changes);
|
|
24
|
-
const value = selectedIds[updated.id];
|
|
25
|
-
delete selectedIds[updated.id];
|
|
26
|
-
selectedIds[id] = value;
|
|
27
|
-
});
|
|
28
|
-
return Object.assign(Object.assign({}, state), { selectedIds });
|
|
29
|
-
}
|
|
30
|
-
return state;
|
|
31
|
-
}
|
|
32
|
-
return createReducer(initialState, on(allActions.selectEntities, (state, { id }) => allMutators.selectEntities(id, state)), on(allActions.deselectEntities, (state, { id }) => allMutators.deselectEntities(id, state)), on(allActions.toggleSelectEntities, (state, { id }) => allMutators.toggleSelectEntities(id, state)), on(allActions.toggleSelectAllEntities, (state) => allMutators.toggleSelectAllEntities(state)), ...insertIf(allActions.removeEntities, () => on(allActions.removeEntities, (state, { keys }) => {
|
|
33
|
-
const selectedIds = Object.assign({}, state.selectedIds);
|
|
34
|
-
keys.forEach((v) => {
|
|
35
|
-
delete selectedIds[v];
|
|
36
|
-
});
|
|
37
|
-
return Object.assign(Object.assign({}, state), { selectedIds });
|
|
38
|
-
})), ...insertIf(allActions.updateEntities, () => on(allActions.updateEntities, (state, { updates }) => updateSelectedIdsChanged(state, updates))), on(allActions.clearEntitiesSelection, (state) => allMutators.clearEntitiesSelection(state)), ...insertIf(allActions.removeAllEntities, () => on(allActions.removeAllEntities, (state) => allMutators.clearEntitiesSelection(state))), ...insertIf(sortRemote, () => on(allActions.sortEntities, (state) => allMutators.clearEntitiesSelection(state))), ...insertIf(allActions.filterEntities, () => on(allActions.filterEntities, (state) => allMutators.clearEntitiesSelection(state))), ...insertIf(!allActions.loadEntitiesPageSuccess, () => on(allActions.loadEntitiesSuccess, (state) => allMutators.clearEntitiesSelection(state))), ...insertIf(!!allActions.loadEntitiesPageSuccess && paginationCacheType === 'partial', () => on(allActions.loadEntitiesPageSuccess, (state) => allMutators.clearEntitiesSelection(state))));
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=select-entities.trait.reducer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-entities.trait.reducer.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/select-entities/select-entities.trait.reducer.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n LoadEntitiesActions,\n LoadEntitiesKeyedConfig,\n LoadEntitiesState,\n} from '../load-entities/load-entities.model';\nimport {\n SortEntitiesActions,\n SortEntitiesKeyedConfig,\n} from '../sort-entities/sort-entities.model';\nimport {\n SelectEntitiesMutators,\n SelectEntitiesActions,\n SelectEntitiesState,\n} from './select-entities.model';\nimport { CrudEntitiesActions } from '../crud-entities/crud-entities.model';\nimport { Update } from '@ngrx/entity/src/models';\nimport { insertIf } from '@ngrx-traits/core';\nimport { createReducer, on } from '@ngrx/store';\nimport {\n EntitiesPaginationActions,\n EntitiesPaginationKeyedConfig,\n} from '../entities-pagination/entities-pagination.model';\nimport { FilterEntitiesActions } from '../filter-entities';\n\nexport function createSelectEntitiesInitialState<Entity>(\n previousInitialState: any\n): LoadEntitiesState<Entity> & SelectEntitiesState {\n return {\n ...previousInitialState,\n selectedIds: {},\n };\n}\n\nexport function createSelectEntitiesTraitReducer<\n Entity,\n S extends LoadEntitiesState<Entity> & SelectEntitiesState\n>(\n initialState: S,\n allActions: SelectEntitiesActions &\n CrudEntitiesActions<Entity> &\n SortEntitiesActions<Entity> &\n LoadEntitiesActions<Entity> &\n FilterEntitiesActions<any> &\n EntitiesPaginationActions,\n allMutators: SelectEntitiesMutators<Entity>,\n allConfigs: LoadEntitiesKeyedConfig<Entity> &\n EntitiesPaginationKeyedConfig &\n SortEntitiesKeyedConfig<Entity>\n) {\n const { adapter } = allConfigs.loadEntities!;\n const sortRemote = allConfigs.sort?.remote;\n const paginationCacheType = allConfigs.pagination?.cacheType;\n\n function updateSelectedIdsChanged<\n S extends LoadEntitiesState<Entity> & SelectEntitiesState\n >(state: S, updates: Update<Entity>[]) {\n const changedIds = updates.reduce((acc, updated) => {\n const id = adapter.selectId(updated.changes as Entity);\n if (id && id !== updated.id && state.selectedIds[updated.id] != null) {\n acc.push(updated);\n return acc;\n }\n return acc;\n }, [] as Update<Entity>[]);\n if (changedIds.length) {\n const selectedIds = { ...state.selectedIds };\n changedIds.forEach((updated) => {\n const id = adapter.selectId(updated.changes as Entity);\n const value = selectedIds[updated.id];\n delete selectedIds[updated.id];\n selectedIds[id] = value;\n });\n return { ...state, selectedIds };\n }\n\n return state;\n }\n\n return createReducer(\n initialState,\n on(allActions.selectEntities, (state, { id }) =>\n allMutators.selectEntities(id, state)\n ),\n on(allActions.deselectEntities, (state, { id }) =>\n allMutators.deselectEntities(id, state)\n ),\n on(allActions.toggleSelectEntities, (state, { id }) =>\n allMutators.toggleSelectEntities(id, state)\n ),\n on(allActions.toggleSelectAllEntities, (state) =>\n allMutators.toggleSelectAllEntities(state)\n ),\n ...insertIf<S>(allActions.removeEntities, () =>\n on(allActions.removeEntities, (state, { keys }) => {\n const selectedIds = { ...state.selectedIds };\n keys.forEach((v: string | number) => {\n delete selectedIds[v];\n });\n return { ...state, selectedIds };\n })\n ),\n ...insertIf<S>(allActions.updateEntities, () =>\n on(allActions.updateEntities, (state, { updates }) =>\n updateSelectedIdsChanged(state, updates)\n )\n ),\n on(allActions.clearEntitiesSelection, (state) =>\n allMutators.clearEntitiesSelection(state)\n ),\n ...insertIf<S>(allActions.removeAllEntities, () =>\n on(allActions.removeAllEntities, (state) =>\n allMutators.clearEntitiesSelection(state)\n )\n ),\n ...insertIf<S>(sortRemote, () =>\n on(allActions.sortEntities, (state) =>\n allMutators.clearEntitiesSelection(state)\n )\n ),\n ...insertIf<S>(allActions.filterEntities, () =>\n on(allActions.filterEntities, (state) =>\n allMutators.clearEntitiesSelection(state)\n )\n ),\n ...insertIf<S>(!allActions.loadEntitiesPageSuccess, () =>\n on(allActions.loadEntitiesSuccess, (state) =>\n allMutators.clearEntitiesSelection(state)\n )\n ),\n ...insertIf<S>(\n !!allActions.loadEntitiesPageSuccess && paginationCacheType === 'partial',\n () =>\n on(allActions.loadEntitiesPageSuccess, (state) =>\n allMutators.clearEntitiesSelection(state)\n )\n )\n );\n}\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createSelector } from '@ngrx/store';
|
|
2
|
-
import { selectTotalSelectedEntities } from './select-entities.utils';
|
|
3
|
-
export function createSelectEntitiesTraitSelectors(previousSelectors) {
|
|
4
|
-
const { selectEntitiesMap, selectEntitiesTotal } = previousSelectors;
|
|
5
|
-
function selectEntitiesIdsSelectedMap(state) {
|
|
6
|
-
return state.selectedIds;
|
|
7
|
-
}
|
|
8
|
-
const selectEntitiesIdsSelectedList = createSelector(selectEntitiesIdsSelectedMap, (ids) => Object.keys(ids));
|
|
9
|
-
const selectEntitiesSelectedMap = createSelector(selectEntitiesIdsSelectedList, selectEntitiesMap, (selectedIds, entities) => selectedIds.reduce((acum, id) => {
|
|
10
|
-
acum[id] = entities[id];
|
|
11
|
-
return acum;
|
|
12
|
-
}, {}));
|
|
13
|
-
const selectEntitiesSelectedList = createSelector(selectEntitiesIdsSelectedList, selectEntitiesMap, (selectedIds, entities) => selectedIds.map((id) => entities[id]));
|
|
14
|
-
const isAllEntitiesSelected = createSelector((state) => selectEntitiesTotal(state), selectTotalSelectedEntities, (total, totalSelected) => totalSelected > 0 && totalSelected === total
|
|
15
|
-
? 'all'
|
|
16
|
-
: totalSelected === 0
|
|
17
|
-
? 'none'
|
|
18
|
-
: 'some');
|
|
19
|
-
return {
|
|
20
|
-
selectEntitiesIdsSelectedMap,
|
|
21
|
-
selectEntitiesIdsSelectedList,
|
|
22
|
-
selectEntitiesSelectedMap,
|
|
23
|
-
selectEntitiesSelectedList,
|
|
24
|
-
selectTotalSelectedEntities,
|
|
25
|
-
isAllEntitiesSelected,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=select-entities.trait.selectors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-entities.trait.selectors.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/select-entities/select-entities.trait.selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAQtE,MAAM,UAAU,kCAAkC,CAChD,iBAAgD;IAEhD,MAAM,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,GAAG,iBAAiB,CAAC;IAErE,SAAS,4BAA4B,CACnC,KAAsD;QAEtD,OAAO,KAAK,CAAC,WAAW,CAAC;IAC3B,CAAC;IACD,MAAM,6BAA6B,GAAG,cAAc,CAClD,4BAA4B,EAC5B,CAAC,GAAwB,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAC/C,CAAC;IACF,MAAM,yBAAyB,GAAG,cAAc,CAC9C,6BAA6B,EAC7B,iBAAiB,EACjB,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,CACxB,WAAW,CAAC,MAAM,CAAC,CAAC,IAA0C,EAAE,EAAE,EAAE,EAAE;QACpE,IAAI,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,EAAE,CAAC,CACT,CAAC;IACF,MAAM,0BAA0B,GAAG,cAAc,CAC/C,6BAA6B,EAC7B,iBAAiB,EACjB,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAE,CAAC,CAClE,CAAC;IAEF,MAAM,qBAAqB,GAAG,cAAc,CAC1C,CAAC,KAAsD,EAAE,EAAE,CACzD,mBAAmB,CAAC,KAAK,CAAC,EAC5B,2BAA2B,EAC3B,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,CACvB,aAAa,GAAG,CAAC,IAAI,aAAa,KAAK,KAAK;QAC1C,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,aAAa,KAAK,CAAC;YACrB,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,MAAM,CACb,CAAC;IAEF,OAAO;QACL,4BAA4B;QAC5B,6BAA6B;QAC7B,yBAAyB;QACzB,0BAA0B;QAC1B,2BAA2B;QAC3B,qBAAqB;KACtB,CAAC;AACJ,CAAC","sourcesContent":["import { createSelector } from '@ngrx/store';\nimport { selectTotalSelectedEntities } from './select-entities.utils';\nimport {\n SelectEntitiesSelectors,\n SelectEntitiesState,\n} from './select-entities.model';\nimport { LoadEntitiesSelectors, LoadEntitiesState } from '../load-entities';\nimport { Dictionary } from '@ngrx/entity/src/models';\n\nexport function createSelectEntitiesTraitSelectors<Entity>(\n previousSelectors: LoadEntitiesSelectors<Entity>\n): SelectEntitiesSelectors<Entity> {\n const { selectEntitiesMap, selectEntitiesTotal } = previousSelectors;\n\n function selectEntitiesIdsSelectedMap(\n state: LoadEntitiesState<Entity> & SelectEntitiesState\n ) {\n return state.selectedIds;\n }\n const selectEntitiesIdsSelectedList = createSelector(\n selectEntitiesIdsSelectedMap,\n (ids: Dictionary<boolean>) => Object.keys(ids)\n );\n const selectEntitiesSelectedMap = createSelector(\n selectEntitiesIdsSelectedList,\n selectEntitiesMap,\n (selectedIds, entities) =>\n selectedIds.reduce((acum: { [id: string]: Entity | undefined }, id) => {\n acum[id] = entities[id];\n return acum;\n }, {})\n );\n const selectEntitiesSelectedList = createSelector(\n selectEntitiesIdsSelectedList,\n selectEntitiesMap,\n (selectedIds, entities) => selectedIds.map((id) => entities[id]!)\n );\n\n const isAllEntitiesSelected = createSelector(\n (state: LoadEntitiesState<Entity> & SelectEntitiesState) =>\n selectEntitiesTotal(state),\n selectTotalSelectedEntities,\n (total, totalSelected) =>\n totalSelected > 0 && totalSelected === total\n ? 'all'\n : totalSelected === 0\n ? 'none'\n : 'some'\n );\n\n return {\n selectEntitiesIdsSelectedMap,\n selectEntitiesIdsSelectedList,\n selectEntitiesSelectedMap,\n selectEntitiesSelectedList,\n selectTotalSelectedEntities,\n isAllEntitiesSelected,\n };\n}\n"]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { __rest } from "tslib";
|
|
2
|
-
export function deselectEntities(id, state) {
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4
|
-
const _a = state.selectedIds, _b = id, _value = _a[_b], selectedIds = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
5
|
-
return Object.assign(Object.assign({}, state), { selectedIds: selectedIds });
|
|
6
|
-
}
|
|
7
|
-
export function selectEntities(id, state) {
|
|
8
|
-
return Object.assign(Object.assign({}, state), { selectedIds: Object.assign(Object.assign({}, state.selectedIds), { [id]: true }) });
|
|
9
|
-
}
|
|
10
|
-
export function toggleSelectEntities(id, state) {
|
|
11
|
-
const selected = state.selectedIds[id];
|
|
12
|
-
if (selected) {
|
|
13
|
-
return deselectEntities(id, state);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
return selectEntities(id, state);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export function clearEntitiesSelection(state) {
|
|
20
|
-
return Object.assign(Object.assign({}, state), { selectedIds: {} });
|
|
21
|
-
}
|
|
22
|
-
export function selectTotalSelectedEntities(state) {
|
|
23
|
-
return Object.keys(state.selectedIds).length;
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=select-entities.utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-entities.utils.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/select-entities/select-entities.utils.ts"],"names":[],"mappings":";AAGA,MAAM,UAAU,gBAAgB,CAC9B,EAAmB,EACnB,KAAQ;IAER,6DAA6D;IAC7D,MAAyC,KAAA,KAAK,CAAC,WAAW,EAAlD,KAAC,EAAG,EAAE,MAAM,SAAA,EAAK,WAAW,cAA9B,uCAAgC,CAAoB,CAAC;IAC3D,uCACK,KAAK,KACR,WAAW,EAAE,WAAW,IACxB;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,EAAmB,EACnB,KAAQ;IAER,uCACK,KAAK,KACR,WAAW,kCAAO,KAAK,CAAC,WAAW,KAAE,CAAC,EAAE,CAAC,EAAE,IAAI,OAC/C;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,EAAmB,EACnB,KAAQ;IAER,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACvC,IAAI,QAAQ,EAAE;QACZ,OAAO,gBAAgB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;KACpC;SAAM;QACL,OAAO,cAAc,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;KAClC;AACH,CAAC;AACD,MAAM,UAAU,sBAAsB,CACpC,KAAQ;IAER,uCAAY,KAAK,KAAE,WAAW,EAAE,EAAE,IAAG;AACvC,CAAC;AAED,MAAM,UAAU,2BAA2B,CAGzC,KAAQ;IACR,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC;AAC/C,CAAC","sourcesContent":["import { SelectEntitiesState } from './select-entities.model';\nimport { LoadEntitiesState } from '../load-entities';\n\nexport function deselectEntities<S extends SelectEntitiesState>(\n id: number | string,\n state: S\n): S {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { [id]: _value, ...selectedIds } = state.selectedIds;\n return {\n ...state,\n selectedIds: selectedIds,\n };\n}\n\nexport function selectEntities<S extends SelectEntitiesState>(\n id: number | string,\n state: S\n): S {\n return {\n ...state,\n selectedIds: { ...state.selectedIds, [id]: true },\n };\n}\n\nexport function toggleSelectEntities<S extends SelectEntitiesState>(\n id: number | string,\n state: S\n): S {\n const selected = state.selectedIds[id];\n if (selected) {\n return deselectEntities(id, state);\n } else {\n return selectEntities(id, state);\n }\n}\nexport function clearEntitiesSelection<S extends SelectEntitiesState>(\n state: S\n): S {\n return { ...state, selectedIds: {} };\n}\n\nexport function selectTotalSelectedEntities<\n Entity,\n S extends LoadEntitiesState<Entity> & SelectEntitiesState\n>(state: S): number {\n return Object.keys(state.selectedIds).length;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/select-entity/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './select-entity.trait';\nexport * from './select-entity.model';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-entity.model.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/select-entity/select-entity.model.ts"],"names":[],"mappings":"AAmDA,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC","sourcesContent":["import { ActionCreator, TypedAction } from '@ngrx/store/src/models';\nimport { KeyedConfig } from '@ngrx-traits/core';\nimport { LoadEntitiesState } from '../load-entities/load-entities.model';\n\nexport interface SelectEntityState {\n selectedId?: number | string;\n}\n\nexport type SelectEntityActions = {\n selectEntity: ActionCreator<\n string,\n (props: {\n id: number | string;\n }) => { id: number | string } & TypedAction<string>\n >;\n deselectEntity: ActionCreator<string, () => TypedAction<string>>;\n toggleSelectEntity: ActionCreator<\n string,\n (props: {\n id: number | string;\n }) => { id: number | string } & TypedAction<string>\n >;\n};\n\nexport type SelectEntitySelectors<T> = {\n selectEntityIdSelected: (\n state: LoadEntitiesState<T> & SelectEntityState\n ) => string | number | undefined;\n selectEntitySelected: (\n state: LoadEntitiesState<T> & SelectEntityState\n ) => T | undefined;\n};\n\nexport type SelectEntityMutators<T> = {\n selectEntity<S extends LoadEntitiesState<T> & SelectEntityState>(\n id: string | number,\n state: S\n ): S;\n deselectEntity<S extends LoadEntitiesState<T> & SelectEntityState>(\n state: S\n ): S;\n toggleSelectEntity<S extends LoadEntitiesState<T> & SelectEntityState>(\n id: string | number,\n state: S\n ): S;\n};\n\nexport interface SelectEntityConfig {\n selectedId?: string | number;\n}\n\nexport const selectEntityTraitKey = 'singleSelection';\nexport type SelectEntityKeyedConfig = KeyedConfig<\n typeof selectEntityTraitKey,\n SelectEntityConfig\n>;\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { createAction, props } from '@ngrx/store';
|
|
2
|
-
export function createSelectEntityTraitActions(actionsGroupKey, entityName) {
|
|
3
|
-
return {
|
|
4
|
-
selectEntity: createAction(`${actionsGroupKey} Select ${entityName}`, props()),
|
|
5
|
-
deselectEntity: createAction(`${actionsGroupKey} Deselect ${entityName}`),
|
|
6
|
-
toggleSelectEntity: createAction(`${actionsGroupKey} Toggle Select ${entityName}`, props()),
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=select-entity.trait.actions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-entity.trait.actions.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/select-entity/select-entity.trait.actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,UAAU,8BAA8B,CAC5C,eAAuB,EACvB,UAAkB;IAElB,OAAO;QACL,YAAY,EAAE,YAAY,CACxB,GAAG,eAAe,WAAW,UAAU,EAAE,EACzC,KAAK,EAA2B,CACjC;QACD,cAAc,EAAE,YAAY,CAAC,GAAG,eAAe,aAAa,UAAU,EAAE,CAAC;QACzE,kBAAkB,EAAE,YAAY,CAC9B,GAAG,eAAe,kBAAkB,UAAU,EAAE,EAChD,KAAK,EAA2B,CACjC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { createAction, props } from '@ngrx/store';\nimport { SelectEntityActions } from './select-entity.model';\n\nexport function createSelectEntityTraitActions(\n actionsGroupKey: string,\n entityName: string\n): SelectEntityActions {\n return {\n selectEntity: createAction(\n `${actionsGroupKey} Select ${entityName}`,\n props<{ id: string | number }>()\n ),\n deselectEntity: createAction(`${actionsGroupKey} Deselect ${entityName}`),\n toggleSelectEntity: createAction(\n `${actionsGroupKey} Toggle Select ${entityName}`,\n props<{ id: string | number }>()\n ),\n };\n}\n"]}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { createTraitFactory, } from '@ngrx-traits/core';
|
|
2
|
-
import { createSelectEntityTraitActions } from './select-entity.trait.actions';
|
|
3
|
-
import { createSelectEntityTraitSelectors } from './select-entity.trait.selectors';
|
|
4
|
-
import { createSelectEntityInitialState, createSelectEntityTraitReducer, } from './select-entity.trait.reducer';
|
|
5
|
-
import { createSelectEntityTraitMutators } from './select-entity.trait.mutators';
|
|
6
|
-
import { loadEntitiesTraitKey, } from '../load-entities/load-entities.model';
|
|
7
|
-
/**
|
|
8
|
-
* Generates ngrx code to add single selection to a list
|
|
9
|
-
* @param config
|
|
10
|
-
* @param config.selectedId - Default selected id
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* // The following trait config
|
|
14
|
-
*
|
|
15
|
-
* export interface TestState
|
|
16
|
-
* extends EntityAndStatusState<Todo>,SelectEntityState{}
|
|
17
|
-
*
|
|
18
|
-
* const traits = createEntityFeatureFactory(
|
|
19
|
-
* addLoadEntitiesTrait<Todo>(),
|
|
20
|
-
* addSelectEntityTrait<Todo>()
|
|
21
|
-
* )({
|
|
22
|
-
* actionsGroupKey: '[Todos]',
|
|
23
|
-
* featureSelector: createFeatureSelector<TestState>>(
|
|
24
|
-
* 'todos',
|
|
25
|
-
* ),
|
|
26
|
-
* });
|
|
27
|
-
*
|
|
28
|
-
* // adds following props to the state:
|
|
29
|
-
* // selectedId?: number | string;
|
|
30
|
-
*
|
|
31
|
-
* // generated actions
|
|
32
|
-
* traits.actions.selectTodo({id})
|
|
33
|
-
* traits.actions.deselectTodo()
|
|
34
|
-
* traits.actions.toggleSelectTodo({id})
|
|
35
|
-
* //generated selectors
|
|
36
|
-
* traits.selectors.selectTodoIdSelected()
|
|
37
|
-
* traits.selectors.selectTodoSelected()
|
|
38
|
-
*/
|
|
39
|
-
export function addSelectEntityTrait(config) {
|
|
40
|
-
return createTraitFactory({
|
|
41
|
-
key: 'singleSelection',
|
|
42
|
-
depends: [loadEntitiesTraitKey],
|
|
43
|
-
config,
|
|
44
|
-
actions: ({ actionsGroupKey, entityName }) => createSelectEntityTraitActions(actionsGroupKey, entityName),
|
|
45
|
-
selectors: () => createSelectEntityTraitSelectors(),
|
|
46
|
-
mutators: () => createSelectEntityTraitMutators(),
|
|
47
|
-
initialState: ({ previousInitialState, allConfigs, }) => createSelectEntityInitialState(previousInitialState, allConfigs),
|
|
48
|
-
reducer: ({ initialState, allActions, allMutators, allConfigs }) => createSelectEntityTraitReducer(initialState, allActions, allMutators, allConfigs),
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=select-entity.trait.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-entity.trait.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/select-entity/select-entity.trait.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAGnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC;AACnF,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AACjF,OAAO,EAGL,oBAAoB,GACrB,MAAM,sCAAsC,CAAC;AAiB9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,oBAAoB,CAAS,MAA2B;IACtE,OAAO,kBAAkB,CAAC;QACxB,GAAG,EAAE,iBAAiB;QACtB,OAAO,EAAE,CAAC,oBAAoB,CAAC;QAC/B,MAAM;QACN,OAAO,EAAE,CAAC,EAAE,eAAe,EAAE,UAAU,EAA6B,EAAE,EAAE,CACtE,8BAA8B,CAAC,eAAe,EAAE,UAAU,CAAC;QAC7D,SAAS,EAAE,GAAG,EAAE,CAAC,gCAAgC,EAAU;QAC3D,QAAQ,EAAE,GAAG,EAAE,CAAC,+BAA+B,EAAE;QACjD,YAAY,EAAE,CAAC,EACb,oBAAoB,EACpB,UAAU,GACqB,EAAE,EAAE,CACnC,8BAA8B,CAC5B,oBAAoB,EACpB,UAAqC,CACtC;QACH,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE,EAAE,CACjE,8BAA8B,CAC5B,YAAY,EACZ,UAK6B,EAC7B,WAAW,EACX,UAGiC,CAClC;KACJ,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n createTraitFactory,\n TraitActionsFactoryConfig,\n TraitInitialStateFactoryConfig,\n} from '@ngrx-traits/core';\n\nimport { createSelectEntityTraitActions } from './select-entity.trait.actions';\nimport { createSelectEntityTraitSelectors } from './select-entity.trait.selectors';\nimport {\n createSelectEntityInitialState,\n createSelectEntityTraitReducer,\n} from './select-entity.trait.reducer';\nimport { createSelectEntityTraitMutators } from './select-entity.trait.mutators';\nimport {\n LoadEntitiesActions,\n LoadEntitiesKeyedConfig,\n loadEntitiesTraitKey,\n} from '../load-entities/load-entities.model';\nimport {\n SortEntitiesActions,\n SortEntitiesKeyedConfig,\n} from '../sort-entities/sort-entities.model';\nimport {\n SelectEntityActions,\n SelectEntityConfig,\n SelectEntityKeyedConfig,\n} from './select-entity.model';\nimport { CrudEntitiesActions } from '../crud-entities/crud-entities.model';\nimport {\n EntitiesPaginationActions,\n EntitiesPaginationKeyedConfig,\n} from '../entities-pagination/entities-pagination.model';\nimport { FilterEntitiesActions } from '../filter-entities';\n\n/**\n * Generates ngrx code to add single selection to a list\n * @param config\n * @param config.selectedId - Default selected id\n *\n * @example\n * // The following trait config\n *\n * export interface TestState\n * extends EntityAndStatusState<Todo>,SelectEntityState{}\n *\n * const traits = createEntityFeatureFactory(\n * addLoadEntitiesTrait<Todo>(),\n * addSelectEntityTrait<Todo>()\n * )({\n * actionsGroupKey: '[Todos]',\n * featureSelector: createFeatureSelector<TestState>>(\n * 'todos',\n * ),\n * });\n *\n * // adds following props to the state:\n * // selectedId?: number | string;\n *\n * // generated actions\n * traits.actions.selectTodo({id})\n * traits.actions.deselectTodo()\n * traits.actions.toggleSelectTodo({id})\n * //generated selectors\n * traits.selectors.selectTodoIdSelected()\n * traits.selectors.selectTodoSelected()\n */\nexport function addSelectEntityTrait<Entity>(config?: SelectEntityConfig) {\n return createTraitFactory({\n key: 'singleSelection',\n depends: [loadEntitiesTraitKey],\n config,\n actions: ({ actionsGroupKey, entityName }: TraitActionsFactoryConfig) =>\n createSelectEntityTraitActions(actionsGroupKey, entityName),\n selectors: () => createSelectEntityTraitSelectors<Entity>(),\n mutators: () => createSelectEntityTraitMutators(),\n initialState: ({\n previousInitialState,\n allConfigs,\n }: TraitInitialStateFactoryConfig) =>\n createSelectEntityInitialState<Entity>(\n previousInitialState,\n allConfigs as SelectEntityKeyedConfig\n ),\n reducer: ({ initialState, allActions, allMutators, allConfigs }) =>\n createSelectEntityTraitReducer(\n initialState,\n allActions as SelectEntityActions &\n CrudEntitiesActions<Entity> &\n SortEntitiesActions<Entity> &\n EntitiesPaginationActions &\n FilterEntitiesActions<any> &\n LoadEntitiesActions<Entity>,\n allMutators,\n allConfigs as SelectEntityKeyedConfig &\n LoadEntitiesKeyedConfig<Entity> &\n EntitiesPaginationKeyedConfig &\n SortEntitiesKeyedConfig<Entity>\n ),\n });\n}\n"]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function createSelectEntityTraitMutators() {
|
|
2
|
-
function selectEntity(id, state) {
|
|
3
|
-
return Object.assign(Object.assign({}, state), { selectedId: id });
|
|
4
|
-
}
|
|
5
|
-
function deselectEntity(state) {
|
|
6
|
-
return Object.assign(Object.assign({}, state), { selectedId: undefined });
|
|
7
|
-
}
|
|
8
|
-
function toggleSelectEntity(id, state) {
|
|
9
|
-
return Object.assign(Object.assign({}, state), { selectedId: state.selectedId === id ? undefined : id });
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
selectEntity,
|
|
13
|
-
deselectEntity,
|
|
14
|
-
toggleSelectEntity,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=select-entity.trait.mutators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-entity.trait.mutators.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/select-entity/select-entity.trait.mutators.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,+BAA+B;IAG7C,SAAS,YAAY,CAEnB,EAAmB,EAAE,KAAQ;QAC7B,uCACK,KAAK,KACR,UAAU,EAAE,EAAE,IACd;IACJ,CAAC;IACD,SAAS,cAAc,CAErB,KAAQ;QACR,uCACK,KAAK,KACR,UAAU,EAAE,SAAS,IACrB;IACJ,CAAC;IACD,SAAS,kBAAkB,CAEzB,EAAmB,EAAE,KAAQ;QAC7B,uCACK,KAAK,KACR,UAAU,EAAE,KAAK,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IACpD;IACJ,CAAC;IAED,OAAO;QACL,YAAY;QACZ,cAAc;QACd,kBAAkB;KACnB,CAAC;AACJ,CAAC","sourcesContent":["import { SelectEntityMutators, SelectEntityState } from './select-entity.model';\nimport { LoadEntitiesState } from '../load-entities';\n\nexport function createSelectEntityTraitMutators<\n Entity\n>(): SelectEntityMutators<Entity> {\n function selectEntity<\n S extends LoadEntitiesState<Entity> & SelectEntityState\n >(id: string | number, state: S) {\n return {\n ...state,\n selectedId: id,\n };\n }\n function deselectEntity<\n S extends LoadEntitiesState<Entity> & SelectEntityState\n >(state: S) {\n return {\n ...state,\n selectedId: undefined,\n };\n }\n function toggleSelectEntity<\n S extends LoadEntitiesState<Entity> & SelectEntityState\n >(id: string | number, state: S) {\n return {\n ...state,\n selectedId: state.selectedId === id ? undefined : id,\n };\n }\n\n return {\n selectEntity,\n deselectEntity,\n toggleSelectEntity,\n };\n}\n"]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createReducer, on } from '@ngrx/store';
|
|
2
|
-
import { insertIf } from '@ngrx-traits/core';
|
|
3
|
-
export function createSelectEntityInitialState(previousInitialState, allConfigs) {
|
|
4
|
-
var _a;
|
|
5
|
-
const selectedId = (_a = allConfigs.singleSelection) === null || _a === void 0 ? void 0 : _a.selectedId;
|
|
6
|
-
return Object.assign(Object.assign({}, previousInitialState), { selectedId });
|
|
7
|
-
}
|
|
8
|
-
export function createSelectEntityTraitReducer(initialState, allActions, allMutators, allConfigs) {
|
|
9
|
-
var _a, _b;
|
|
10
|
-
const { adapter } = allConfigs.loadEntities;
|
|
11
|
-
const sortRemote = (_a = allConfigs.sort) === null || _a === void 0 ? void 0 : _a.remote;
|
|
12
|
-
const paginationCacheType = (_b = allConfigs.pagination) === null || _b === void 0 ? void 0 : _b.cacheType;
|
|
13
|
-
return createReducer(initialState, on(allActions.selectEntity, (state, { id }) => allMutators.selectEntity(id, state)), on(allActions.deselectEntity, (state) => allMutators.deselectEntity(state)), on(allActions.toggleSelectEntity, (state, { id }) => allMutators.toggleSelectEntity(id, state)), ...insertIf(allActions.removeAllEntities, () => on(allActions.removeAllEntities, (state) => allMutators.deselectEntity(state))), ...insertIf(sortRemote, () => on(allActions.sortEntities, (state) => allMutators.deselectEntity(state))), ...insertIf(allActions.filterEntities, () => on(allActions.filterEntities, (state) => allMutators.deselectEntity(state))), ...insertIf(!allActions.loadEntitiesPageSuccess, () => on(allActions.loadEntitiesSuccess, (state) => allMutators.deselectEntity(state))), ...insertIf(!!allActions.loadEntitiesPageSuccess && paginationCacheType === 'partial', () => on(allActions.loadEntitiesPageSuccess, (state) => allMutators.deselectEntity(state))), ...insertIf(allActions.removeEntities, () => on(allActions.removeEntities, (state, { keys }) => {
|
|
14
|
-
const shouldDeselect = keys.some((v) => v === state.selectedId);
|
|
15
|
-
return shouldDeselect
|
|
16
|
-
? Object.assign(Object.assign({}, state), { selectedId: undefined }) : state;
|
|
17
|
-
})), ...insertIf(allActions.updateEntities, () => on(allActions.updateEntities, (state, { updates }) => {
|
|
18
|
-
const change = updates.find((updated) => {
|
|
19
|
-
const id = adapter.selectId(updated.changes);
|
|
20
|
-
return id && id !== updated.id && state.selectedId === updated.id;
|
|
21
|
-
});
|
|
22
|
-
return change
|
|
23
|
-
? Object.assign(Object.assign({}, state), { selectedId: adapter.selectId(change.changes) }) : state;
|
|
24
|
-
})));
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=select-entity.trait.reducer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-entity.trait.reducer.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/select-entity/select-entity.trait.reducer.ts"],"names":[],"mappings":"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","sourcesContent":["import { createReducer, on } from '@ngrx/store';\nimport {\n LoadEntitiesActions,\n LoadEntitiesKeyedConfig,\n LoadEntitiesState,\n} from '../load-entities/load-entities.model';\nimport {\n SortEntitiesActions,\n SortEntitiesKeyedConfig,\n} from '../sort-entities/sort-entities.model';\nimport {\n SelectEntityActions,\n SelectEntityKeyedConfig,\n SelectEntityMutators,\n SelectEntityState,\n} from './select-entity.model';\nimport { CrudEntitiesActions } from '../crud-entities/crud-entities.model';\nimport { insertIf } from '@ngrx-traits/core';\nimport {\n EntitiesPaginationActions,\n EntitiesPaginationKeyedConfig,\n} from '../entities-pagination/entities-pagination.model';\nimport { FilterEntitiesActions } from '../filter-entities';\nimport { createSelectEntityTraitActions } from './select-entity.trait.actions';\n\nexport function createSelectEntityInitialState<Entity>(\n previousInitialState: any,\n allConfigs: SelectEntityKeyedConfig\n): LoadEntitiesState<Entity> & SelectEntityState {\n const selectedId = allConfigs.singleSelection?.selectedId;\n return {\n ...previousInitialState,\n selectedId,\n };\n}\nexport function createSelectEntityTraitReducer<\n Entity,\n S extends LoadEntitiesState<Entity> & SelectEntityState\n>(\n initialState: S,\n allActions: SelectEntityActions &\n CrudEntitiesActions<Entity> &\n SortEntitiesActions<Entity> &\n EntitiesPaginationActions &\n FilterEntitiesActions<any> &\n LoadEntitiesActions<Entity>,\n allMutators: SelectEntityMutators<Entity>,\n allConfigs: SelectEntityKeyedConfig &\n LoadEntitiesKeyedConfig<Entity> &\n EntitiesPaginationKeyedConfig &\n SortEntitiesKeyedConfig<Entity>\n) {\n const { adapter } = allConfigs.loadEntities!;\n\n const sortRemote = allConfigs.sort?.remote;\n const paginationCacheType = allConfigs.pagination?.cacheType;\n\n return createReducer(\n initialState,\n on(allActions.selectEntity, (state, { id }) =>\n allMutators.selectEntity(id, state)\n ),\n on(allActions.deselectEntity, (state) => allMutators.deselectEntity(state)),\n on(allActions.toggleSelectEntity, (state, { id }) =>\n allMutators.toggleSelectEntity(id, state)\n ),\n ...insertIf<S>(allActions.removeAllEntities, () =>\n on(allActions.removeAllEntities, (state) =>\n allMutators.deselectEntity(state)\n )\n ),\n ...insertIf<S>(sortRemote, () =>\n on(allActions.sortEntities, (state) => allMutators.deselectEntity(state))\n ),\n ...insertIf<S>(allActions.filterEntities, () =>\n on(allActions.filterEntities, (state) =>\n allMutators.deselectEntity(state)\n )\n ),\n ...insertIf<S>(!allActions.loadEntitiesPageSuccess, () =>\n on(allActions.loadEntitiesSuccess, (state) =>\n allMutators.deselectEntity(state)\n )\n ),\n ...insertIf<S>(\n !!allActions.loadEntitiesPageSuccess && paginationCacheType === 'partial',\n () =>\n on(allActions.loadEntitiesPageSuccess, (state) =>\n allMutators.deselectEntity(state)\n )\n ),\n ...insertIf<S>(allActions.removeEntities, () =>\n on(allActions.removeEntities, (state, { keys }) => {\n const shouldDeselect = keys.some(\n (v: string | number) => v === state.selectedId\n );\n return shouldDeselect\n ? {\n ...state,\n selectedId: undefined,\n }\n : state;\n })\n ),\n ...insertIf<S>(allActions.updateEntities, () =>\n on(allActions.updateEntities, (state, { updates }) => {\n const change = updates.find((updated) => {\n const id = adapter.selectId(updated.changes as Entity);\n return id && id !== updated.id && state.selectedId === updated.id;\n });\n return change\n ? {\n ...state,\n selectedId: adapter.selectId(change.changes as Entity),\n }\n : state;\n })\n )\n );\n}\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function createSelectEntityTraitSelectors() {
|
|
2
|
-
function selectEntityIdSelected(state) {
|
|
3
|
-
return state.selectedId;
|
|
4
|
-
}
|
|
5
|
-
function selectEntitySelected(state) {
|
|
6
|
-
return (state.selectedId && state.entities[state.selectedId]) || undefined;
|
|
7
|
-
}
|
|
8
|
-
return {
|
|
9
|
-
selectEntityIdSelected,
|
|
10
|
-
selectEntitySelected,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=select-entity.trait.selectors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-entity.trait.selectors.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/select-entity/select-entity.trait.selectors.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,gCAAgC;IAG9C,SAAS,sBAAsB,CAAC,KAAwB;QACtD,OAAO,KAAK,CAAC,UAAU,CAAC;IAC1B,CAAC;IACD,SAAS,oBAAoB,CAC3B,KAAoD;QAEpD,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,SAAS,CAAC;IAC7E,CAAC;IAED,OAAO;QACL,sBAAsB;QACtB,oBAAoB;KACrB,CAAC;AACJ,CAAC","sourcesContent":["import {\n SelectEntitySelectors,\n SelectEntityState,\n} from './select-entity.model';\nimport { LoadEntitiesState } from '../load-entities';\n\nexport function createSelectEntityTraitSelectors<\n Entity\n>(): SelectEntitySelectors<Entity> {\n function selectEntityIdSelected(state: SelectEntityState) {\n return state.selectedId;\n }\n function selectEntitySelected<Entity>(\n state: LoadEntitiesState<Entity> & SelectEntityState\n ) {\n return (state.selectedId && state.entities[state.selectedId]) || undefined;\n }\n\n return {\n selectEntityIdSelected,\n selectEntitySelected,\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/set-entity/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from './set-entity.model';\nexport * from './set-entity.trait';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"set-entity.model.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/set-entity/set-entity.model.ts"],"names":[],"mappings":"","sourcesContent":["import { PostfixProps, PrefixProps, TraitActions } from '@ngrx-traits/core';\n\nimport { ActionCreator, TypedAction } from '@ngrx/store/src/models';\n\ntype SetActions<T> = {\n /**\n * set entity in the store\n */\n set: ActionCreator<string, (props: T) => TypedAction<string>>;\n};\nexport type SetEntityActions<Entity, J extends string> = PostfixProps<\n SetActions<Entity>,\n J\n>;\n\nexport type SetEntityState<Entity, J extends string> = {\n [key in `${J}`]?: Entity;\n};\n\nexport type SetEntitySelectors<Entity, J extends string> = PostfixProps<\n {\n select: (state: SetEntityState<Entity, J>) => Entity;\n },\n J\n>;\n"]}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { capitalize, createTraitFactory, } from '@ngrx-traits/core';
|
|
2
|
-
import { createAction, createReducer, on } from '@ngrx/store';
|
|
3
|
-
/**
|
|
4
|
-
* Generates ngrx code needed to set and entity in the store state
|
|
5
|
-
* @param entityName - Entity name, should be in camel case
|
|
6
|
-
* @param options.actionProps - param for the main request action,
|
|
7
|
-
* use the props() function for its value
|
|
8
|
-
* @returns the trait factory
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* const traits = createEntityFeatureFactory(
|
|
12
|
-
* addSetEntityTraits({
|
|
13
|
-
* entityName: 'client',
|
|
14
|
-
* actionProps: props<{ client: Client }
|
|
15
|
-
* }),
|
|
16
|
-
* )({
|
|
17
|
-
* actionsGroupKey: 'Client',
|
|
18
|
-
* featureSelector: createFeatureSelector<
|
|
19
|
-
* SetEntityState<Client, 'client'>
|
|
20
|
-
* >('client'),
|
|
21
|
-
* });
|
|
22
|
-
* // adds following props to the state:
|
|
23
|
-
* // client?: Client;
|
|
24
|
-
*
|
|
25
|
-
* // generated actions
|
|
26
|
-
* traits.actions.setClient({client: {id:123, name: 'gabs'}});
|
|
27
|
-
* //generated selectors
|
|
28
|
-
* traits.selectors.selectClient()
|
|
29
|
-
*/
|
|
30
|
-
export function addSetEntityTrait({ entityName, actionProps, }) {
|
|
31
|
-
const capitalizedName = capitalize(entityName);
|
|
32
|
-
return createTraitFactory({
|
|
33
|
-
key: `load${capitalizedName}`,
|
|
34
|
-
config: { entityName, actionProps },
|
|
35
|
-
actions: ({ actionsGroupKey }) => {
|
|
36
|
-
const setEntity = createAction(`${actionsGroupKey} Set ${capitalizedName}`, actionProps);
|
|
37
|
-
return {
|
|
38
|
-
[`set${capitalizedName}`]: setEntity,
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
selectors: () => {
|
|
42
|
-
function selectEntity(state) {
|
|
43
|
-
return state[`${entityName}`];
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
[`select${capitalizedName}`]: selectEntity,
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
initialState: ({ previousInitialState }) => previousInitialState,
|
|
50
|
-
reducer: ({ initialState, allActions }) => {
|
|
51
|
-
return createReducer(initialState, on(allActions[`set${capitalizedName}`], (state, action) => (Object.assign(Object.assign({}, state), { [entityName]: action[entityName] }))));
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=set-entity.trait.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"set-entity.trait.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/set-entity/set-entity.trait.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,kBAAkB,GAEnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAY9D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,iBAAiB,CAK/B,EACA,UAAU,EACV,WAAW,GAIZ;IACC,MAAM,eAAe,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IAE/C,OAAO,kBAAkB,CAAC;QACxB,GAAG,EAAE,OAAO,eAAe,EAAE;QAC7B,MAAM,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;QACnC,OAAO,EAAE,CAAC,EAAE,eAAe,EAA6B,EAAE,EAAE;YAC1D,MAAM,SAAS,GAAG,YAAY,CAC5B,GAAG,eAAe,QAAQ,eAAe,EAAE,EAC3C,WAAkB,CACnB,CAAC;YAEF,OAAO;gBACL,CAAC,MAAM,eAAe,EAAE,CAAC,EAAE,SAAS;aACL,CAAC;QACpC,CAAC;QACD,SAAS,EAAE,GAAG,EAAE;YACd,SAAS,YAAY,CAAC,KAAY;gBAChC,OAAQ,KAAa,CAAC,GAAG,UAAU,EAAE,CAAW,CAAC;YACnD,CAAC;YAED,OAAO;gBACL,CAAC,SAAS,eAAe,EAAE,CAAC,EAAE,YAAY;aACV,CAAC;QACrC,CAAC;QACD,YAAY,EAAE,CAAC,EAAE,oBAAoB,EAAkC,EAAE,EAAE,CACzE,oBAA6B;QAC/B,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,EAAE;YACxC,OAAO,aAAa,CAClB,YAAY,EACZ,EAAE,CACC,UAAkB,CAAC,MAAM,eAAe,EAAE,CAAC,EAC5C,CAAC,KAAU,EAAE,MAAW,EAAE,EAAE,CAAC,iCACxB,KAAK,KACR,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,IAChC,CACH,CACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n capitalize,\n createTraitFactory,\n TraitActionsFactoryConfig,\n} from '@ngrx-traits/core';\nimport { createAction, createReducer, on } from '@ngrx/store';\n\nimport {\n SetEntityActions,\n SetEntitySelectors,\n SetEntityState,\n} from './set-entity.model';\nimport { TraitInitialStateFactoryConfig } from '@ngrx-traits/core';\nimport { ActionCreatorProps } from '@ngrx/store/src/models';\n\ntype RecordEntity<T> = T extends Record<string, infer J> ? J : never;\n\n/**\n * Generates ngrx code needed to set and entity in the store state\n * @param entityName - Entity name, should be in camel case\n * @param options.actionProps - param for the main request action,\n * use the props() function for its value\n * @returns the trait factory\n *\n * @example\n * const traits = createEntityFeatureFactory(\n * addSetEntityTraits({\n * entityName: 'client',\n * actionProps: props<{ client: Client }\n * }),\n * )({\n * actionsGroupKey: 'Client',\n * featureSelector: createFeatureSelector<\n * SetEntityState<Client, 'client'>\n * >('client'),\n * });\n * // adds following props to the state:\n * // client?: Client;\n *\n * // generated actions\n * traits.actions.setClient({client: {id:123, name: 'gabs'}});\n * //generated selectors\n * traits.selectors.selectClient()\n */\nexport function addSetEntityTrait<\n J extends string,\n Payload extends Record<J, any> | undefined = undefined,\n Entity = RecordEntity<Payload>,\n State = SetEntityState<Entity, J>\n>({\n entityName,\n actionProps,\n}: {\n entityName: J;\n actionProps?: ActionCreatorProps<Payload>;\n}) {\n const capitalizedName = capitalize(entityName);\n\n return createTraitFactory({\n key: `load${capitalizedName}`,\n config: { entityName, actionProps },\n actions: ({ actionsGroupKey }: TraitActionsFactoryConfig) => {\n const setEntity = createAction(\n `${actionsGroupKey} Set ${capitalizedName}`,\n actionProps as any\n );\n\n return {\n [`set${capitalizedName}`]: setEntity,\n } as SetEntityActions<Payload, J>;\n },\n selectors: () => {\n function selectEntity(state: State) {\n return (state as any)[`${entityName}`] as Entity;\n }\n\n return {\n [`select${capitalizedName}`]: selectEntity,\n } as SetEntitySelectors<Entity, J>;\n },\n initialState: ({ previousInitialState }: TraitInitialStateFactoryConfig) =>\n previousInitialState as State,\n reducer: ({ initialState, allActions }) => {\n return createReducer(\n initialState,\n on(\n (allActions as any)[`set${capitalizedName}`],\n (state: any, action: any) => ({\n ...state,\n [entityName]: action[entityName],\n })\n )\n );\n },\n });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/sort-entities/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './sort-entities.model';\nexport * from './sort-entities.trait';\nexport * from './sort-entities.utils';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sort-entities.model.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/sort-entities/sort-entities.model.ts"],"names":[],"mappings":"AA6CA,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC","sourcesContent":["import { LoadEntitiesState } from '../load-entities/load-entities.model';\n\nimport { ActionCreator, TypedAction } from '@ngrx/store/src/models';\nimport { KeyedConfig } from '@ngrx-traits/core';\n\nexport declare type SortDirection = 'asc' | 'desc' | '';\n\nexport interface Sort<T> {\n /** The id of the column being sorted. */\n active: keyof T;\n /** The sort direction. */\n direction: SortDirection;\n}\n\nexport interface SortEntitiesState<T> {\n sort: {\n current: Sort<T>;\n default: Sort<T>;\n };\n}\n\nexport type SortEntitiesActions<T> = {\n sortEntities: ActionCreator<\n string,\n (props: Sort<T>) => Sort<T> & TypedAction<string>\n >;\n /**\n * Sets the default sort back\n */\n resetEntitiesSort: ActionCreator<string, () => TypedAction<string>>;\n};\n\nexport type SortEntitiesSelectors<T> = {\n selectEntitiesSort: (\n state: LoadEntitiesState<T> & SortEntitiesState<T>\n ) => Sort<T>;\n};\n\nexport type SortEntitiesMutators<T> = {\n sortEntities<S extends LoadEntitiesState<T> & SortEntitiesState<T>>(\n { active, direction }: Sort<T>,\n state: S\n ): S;\n};\n\nexport const sortTraitKey = 'sort';\n\nexport interface SortEntitiesConfig<T> {\n defaultSort: Sort<T>;\n remote: boolean;\n}\n\nexport type SortEntitiesKeyedConfig<T> = KeyedConfig<\n typeof sortTraitKey,\n SortEntitiesConfig<T>\n>;\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createAction, props } from '@ngrx/store';
|
|
2
|
-
export function createSortTraitActions(actionsGroupKey, entitiesName) {
|
|
3
|
-
return {
|
|
4
|
-
sortEntities: createAction(`${actionsGroupKey} Sort ${entitiesName}`, props()),
|
|
5
|
-
resetEntitiesSort: createAction(`${actionsGroupKey} Reset ${entitiesName} Sort`),
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=sort-entities.trait.actions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sort-entities.trait.actions.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/sort-entities/sort-entities.trait.actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,UAAU,sBAAsB,CACpC,eAAuB,EACvB,YAAoB;IAEpB,OAAO;QACL,YAAY,EAAE,YAAY,CACxB,GAAG,eAAe,SAAS,YAAY,EAAE,EACzC,KAAK,EAAgB,CACtB;QACD,iBAAiB,EAAE,YAAY,CAC7B,GAAG,eAAe,UAAU,YAAY,OAAO,CAChD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { createAction, props } from '@ngrx/store';\nimport { Sort, SortEntitiesActions } from './sort-entities.model';\n\nexport function createSortTraitActions<Entity>(\n actionsGroupKey: string,\n entitiesName: string\n): SortEntitiesActions<Entity> {\n return {\n sortEntities: createAction(\n `${actionsGroupKey} Sort ${entitiesName}`,\n props<Sort<Entity>>()\n ),\n resetEntitiesSort: createAction(\n `${actionsGroupKey} Reset ${entitiesName} Sort`\n ),\n };\n}\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { TraitEffect } from '@ngrx-traits/core';
|
|
3
|
-
import { createEffect, ofType } from '@ngrx/effects';
|
|
4
|
-
import { concatMap } from 'rxjs/operators';
|
|
5
|
-
import * as i0 from "@angular/core";
|
|
6
|
-
export function createSortTraitEffect(allActions, allConfigs) {
|
|
7
|
-
const { remote } = allConfigs.sort;
|
|
8
|
-
class SortEffect extends TraitEffect {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(...arguments);
|
|
11
|
-
this.remoteSort$ = createEffect(() => {
|
|
12
|
-
return this.actions$.pipe(ofType(allActions.sortEntities, allActions.resetEntitiesSort), concatMap(() => allActions.loadEntitiesFirstPage
|
|
13
|
-
? [
|
|
14
|
-
allActions.clearEntitiesPagesCache(),
|
|
15
|
-
allActions.loadEntitiesFirstPage(),
|
|
16
|
-
]
|
|
17
|
-
: [allActions.loadEntities()]));
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
SortEffect.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SortEffect, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
22
|
-
SortEffect.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SortEffect });
|
|
23
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: SortEffect, decorators: [{
|
|
24
|
-
type: Injectable
|
|
25
|
-
}] });
|
|
26
|
-
return remote ? [SortEffect] : [];
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=sort-entities.trait.effect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sort-entities.trait.effect.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/sort-entities/sort-entities.trait.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;;AAY3C,MAAM,UAAU,qBAAqB,CACnC,UAE2B,EAC3B,UAA6E;IAE7E,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,IAAK,CAAC;IAEpC,MACM,UAAW,SAAQ,WAAW;QADpC;;YAEE,gBAAW,GAAG,YAAY,CAAC,GAAG,EAAE;gBAC9B,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CACvB,MAAM,CAAC,UAAU,CAAC,YAAY,EAAE,UAAU,CAAC,iBAAiB,CAAC,EAC7D,SAAS,CAAC,GAAG,EAAE,CACb,UAAU,CAAC,qBAAqB;oBAC9B,CAAC,CAAC;wBACE,UAAU,CAAC,uBAAuB,EAAE;wBACpC,UAAU,CAAC,qBAAqB,EAAE;qBACnC;oBACH,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,CAChC,CACF,CAAC;YACJ,CAAC,CAAC,CAAC;SACJ;;4GAdK,UAAU;gHAAV,UAAU;gGAAV,UAAU;sBADf,UAAU;;IAgBX,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;CACnC","sourcesContent":["import { Injectable } from '@angular/core';\nimport { TraitEffect } from '@ngrx-traits/core';\nimport { createEffect, ofType } from '@ngrx/effects';\nimport { concatMap } from 'rxjs/operators';\nimport { Type } from '@ngrx-traits/core';\nimport {\n LoadEntitiesActions,\n LoadEntitiesKeyedConfig,\n} from '../load-entities/load-entities.model';\nimport {\n SortEntitiesActions,\n SortEntitiesKeyedConfig,\n} from './sort-entities.model';\nimport { EntitiesPaginationActions } from '../entities-pagination/entities-pagination.model';\n\nexport function createSortTraitEffect<Entity>(\n allActions: LoadEntitiesActions<Entity> &\n SortEntitiesActions<Entity> &\n EntitiesPaginationActions,\n allConfigs: LoadEntitiesKeyedConfig<Entity> & SortEntitiesKeyedConfig<Entity>\n): Type<TraitEffect>[] {\n const { remote } = allConfigs.sort!;\n\n @Injectable()\n class SortEffect extends TraitEffect {\n remoteSort$ = createEffect(() => {\n return this.actions$.pipe(\n ofType(allActions.sortEntities, allActions.resetEntitiesSort),\n concatMap(() =>\n allActions.loadEntitiesFirstPage\n ? [\n allActions.clearEntitiesPagesCache(),\n allActions.loadEntitiesFirstPage(),\n ]\n : [allActions.loadEntities()]\n )\n );\n });\n }\n return remote ? [SortEffect] : [];\n}\n"]}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { createSortTraitMutators } from './sort-entities.trait.mutators';
|
|
2
|
-
import { createSortInitialState, createSortTraitReducer, } from './sort-entities.trait.reducer';
|
|
3
|
-
import { createSortTraitSelectors } from './sort-entities.trait.selectors';
|
|
4
|
-
import { createSortTraitEffect } from './sort-entities.trait.effect';
|
|
5
|
-
import { sortTraitKey, } from './sort-entities.model';
|
|
6
|
-
import { loadEntitiesTraitKey, } from '../load-entities/load-entities.model';
|
|
7
|
-
import { createTraitFactory } from '@ngrx-traits/core';
|
|
8
|
-
import { createSortTraitActions } from './sort-entities.trait.actions';
|
|
9
|
-
/**
|
|
10
|
-
* Generates ngrx code to sort locally or remotely a list of entities
|
|
11
|
-
* @param config
|
|
12
|
-
* @param config.defaultSort - Required field, Default entity prop for the sort
|
|
13
|
-
* @param config.remote - Required field, default to false, when true disables local
|
|
14
|
-
* sorting and every sort action call will now trigger a loadEntities action and the backend
|
|
15
|
-
* should sort the data, use selectSort in the effect that call backend to get the requested sort,
|
|
16
|
-
* when false all sorting is done in memory when the sort action is fired
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* // The following trait config
|
|
20
|
-
* export interface TestState
|
|
21
|
-
* extends EntityAndStatusState<Todo>, SortState<Todo>{}
|
|
22
|
-
*
|
|
23
|
-
* const traits = createEntityFeatureFactory(
|
|
24
|
-
* addLoadEntitiesTrait<Todo>(),
|
|
25
|
-
* addSortEntitiesTrait<Todo>({
|
|
26
|
-
* defaultSort: {active:'id', direction:'asc'}
|
|
27
|
-
* })
|
|
28
|
-
* )({
|
|
29
|
-
* actionsGroupKey: '[Todos]',
|
|
30
|
-
* featureSelector: createFeatureSelector<TestState>>(
|
|
31
|
-
* 'todos',
|
|
32
|
-
* ),
|
|
33
|
-
* });
|
|
34
|
-
* // adds following props to the state:
|
|
35
|
-
* // sort: {
|
|
36
|
-
* // current: Sort<Todo>;
|
|
37
|
-
* // default: Sort<Todo>;
|
|
38
|
-
* // }
|
|
39
|
-
*
|
|
40
|
-
* // generated actions
|
|
41
|
-
* traits.actions.sortTodos({active:'id', direction:'desc'})
|
|
42
|
-
* traits.actions.resetTodosSort()
|
|
43
|
-
* //generated selectors
|
|
44
|
-
* traits.selectors.selectTodosSort()
|
|
45
|
-
*/
|
|
46
|
-
export function addSortEntitiesTrait({ remote, defaultSort, }) {
|
|
47
|
-
return createTraitFactory({
|
|
48
|
-
key: sortTraitKey,
|
|
49
|
-
depends: [loadEntitiesTraitKey],
|
|
50
|
-
config: { remote, defaultSort },
|
|
51
|
-
actions: ({ actionsGroupKey, entitiesName }) => createSortTraitActions(actionsGroupKey, entitiesName),
|
|
52
|
-
selectors: () => createSortTraitSelectors(),
|
|
53
|
-
mutators: ({ allSelectors, allConfigs }) => createSortTraitMutators(allSelectors, allConfigs),
|
|
54
|
-
initialState: ({ previousInitialState, allConfigs, }) => createSortInitialState(previousInitialState, allConfigs),
|
|
55
|
-
reducer: ({ initialState, allActions, allMutators, allConfigs }) => createSortTraitReducer(initialState, allActions, allMutators, allConfigs),
|
|
56
|
-
effects: ({ allActions, allConfigs }) => createSortTraitEffect(allActions, allConfigs),
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=sort-entities.trait.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sort-entities.trait.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/sort-entities/sort-entities.trait.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EACL,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAKL,YAAY,GACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAIL,oBAAoB,GACrB,MAAM,sCAAsC,CAAC;AAK9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAOvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,oBAAoB,CAAS,EAC3C,MAAM,EACN,WAAW,GACgB;IAC3B,OAAO,kBAAkB,CAAC;QACxB,GAAG,EAAE,YAAY;QACjB,OAAO,EAAE,CAAC,oBAAoB,CAAC;QAC/B,MAAM,EAAE,EAAE,MAAM,EAAE,WAAW,EAAgC;QAC7D,OAAO,EAAE,CAAC,EAAE,eAAe,EAAE,YAAY,EAA6B,EAAE,EAAE,CACxE,sBAAsB,CAAS,eAAe,EAAE,YAAY,CAAC;QAC/D,SAAS,EAAE,GAAG,EAAE,CAAC,wBAAwB,EAAU;QACnD,QAAQ,EAAE,CAAC,EAAE,YAAY,EAAE,UAAU,EAAmC,EAAE,EAAE,CAC1E,uBAAuB,CACrB,YAC+B,EAC/B,UAAU,CACX;QACH,YAAY,EAAE,CAAC,EACb,oBAAoB,EACpB,UAAU,GACqB,EAAE,EAAE,CACnC,sBAAsB,CAAS,oBAAoB,EAAE,UAAU,CAAC;QAClE,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE,EAAE,CACjE,sBAAsB,CACpB,YAAY,EACZ,UAAuE,EACvE,WAAW,EACX,UAEiC,CAClC;QACH,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,CACtC,qBAAqB,CACnB,UAE2B,EAC3B,UACiC,CAClC;KACJ,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { createSortTraitMutators } from './sort-entities.trait.mutators';\nimport {\n createSortInitialState,\n createSortTraitReducer,\n} from './sort-entities.trait.reducer';\nimport { createSortTraitSelectors } from './sort-entities.trait.selectors';\nimport { createSortTraitEffect } from './sort-entities.trait.effect';\nimport {\n SortEntitiesActions,\n SortEntitiesConfig,\n SortEntitiesKeyedConfig,\n SortEntitiesSelectors,\n sortTraitKey,\n} from './sort-entities.model';\nimport {\n LoadEntitiesActions,\n LoadEntitiesKeyedConfig,\n LoadEntitiesSelectors,\n loadEntitiesTraitKey,\n} from '../load-entities/load-entities.model';\nimport {\n EntitiesPaginationActions,\n EntitiesPaginationKeyedConfig,\n} from '../entities-pagination/entities-pagination.model';\nimport { createTraitFactory } from '@ngrx-traits/core';\nimport { createSortTraitActions } from './sort-entities.trait.actions';\nimport {\n TraitActionsFactoryConfig,\n TraitInitialStateFactoryConfig,\n TraitStateMutatorsFactoryConfig,\n} from '@ngrx-traits/core';\n\n/**\n * Generates ngrx code to sort locally or remotely a list of entities\n * @param config\n * @param config.defaultSort - Required field, Default entity prop for the sort\n * @param config.remote - Required field, default to false, when true disables local\n * sorting and every sort action call will now trigger a loadEntities action and the backend\n * should sort the data, use selectSort in the effect that call backend to get the requested sort,\n * when false all sorting is done in memory when the sort action is fired\n *\n * @example\n * // The following trait config\n * export interface TestState\n * extends EntityAndStatusState<Todo>, SortState<Todo>{}\n *\n * const traits = createEntityFeatureFactory(\n * addLoadEntitiesTrait<Todo>(),\n * addSortEntitiesTrait<Todo>({\n * defaultSort: {active:'id', direction:'asc'}\n * })\n * )({\n * actionsGroupKey: '[Todos]',\n * featureSelector: createFeatureSelector<TestState>>(\n * 'todos',\n * ),\n * });\n * // adds following props to the state:\n * // sort: {\n * // current: Sort<Todo>;\n * // default: Sort<Todo>;\n * // }\n *\n * // generated actions\n * traits.actions.sortTodos({active:'id', direction:'desc'})\n * traits.actions.resetTodosSort()\n * //generated selectors\n * traits.selectors.selectTodosSort()\n */\nexport function addSortEntitiesTrait<Entity>({\n remote,\n defaultSort,\n}: SortEntitiesConfig<Entity>) {\n return createTraitFactory({\n key: sortTraitKey,\n depends: [loadEntitiesTraitKey],\n config: { remote, defaultSort } as SortEntitiesConfig<Entity>,\n actions: ({ actionsGroupKey, entitiesName }: TraitActionsFactoryConfig) =>\n createSortTraitActions<Entity>(actionsGroupKey, entitiesName),\n selectors: () => createSortTraitSelectors<Entity>(),\n mutators: ({ allSelectors, allConfigs }: TraitStateMutatorsFactoryConfig) =>\n createSortTraitMutators<Entity>(\n allSelectors as SortEntitiesSelectors<Entity> &\n LoadEntitiesSelectors<Entity>,\n allConfigs\n ),\n initialState: ({\n previousInitialState,\n allConfigs,\n }: TraitInitialStateFactoryConfig) =>\n createSortInitialState<Entity>(previousInitialState, allConfigs),\n reducer: ({ initialState, allActions, allMutators, allConfigs }) =>\n createSortTraitReducer<Entity>(\n initialState,\n allActions as SortEntitiesActions<Entity> & LoadEntitiesActions<Entity>,\n allMutators,\n allConfigs as LoadEntitiesKeyedConfig<Entity> &\n EntitiesPaginationKeyedConfig &\n SortEntitiesKeyedConfig<Entity>\n ),\n effects: ({ allActions, allConfigs }) =>\n createSortTraitEffect(\n allActions as LoadEntitiesActions<Entity> &\n SortEntitiesActions<Entity> &\n EntitiesPaginationActions,\n allConfigs as LoadEntitiesKeyedConfig<Entity> &\n SortEntitiesKeyedConfig<Entity>\n ),\n });\n}\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { sortData } from './sort-entities.utils';
|
|
2
|
-
export function createSortTraitMutators({ selectEntitiesList }, allConfigs) {
|
|
3
|
-
function sortEntities({ active, direction }, state) {
|
|
4
|
-
const { adapter } = allConfigs.loadEntities;
|
|
5
|
-
const entities = selectEntitiesList(state);
|
|
6
|
-
const sortedIds = sortData(entities, { active, direction }).map((v) => adapter.selectId(v));
|
|
7
|
-
return Object.assign(Object.assign({}, state), { ids: sortedIds, sort: Object.assign(Object.assign({}, state.sort), { current: { active, direction } }) });
|
|
8
|
-
}
|
|
9
|
-
return {
|
|
10
|
-
sortEntities,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=sort-entities.trait.mutators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sort-entities.trait.mutators.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/sort-entities/sort-entities.trait.mutators.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,MAAM,UAAU,uBAAuB,CACrC,EAAE,kBAAkB,EAAiC,EACrD,UAA2C;IAE3C,SAAS,YAAY,CAEnB,EAAE,MAAM,EAAE,SAAS,EAAgB,EAAE,KAAQ;QAC7C,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,YAAa,CAAC;QAC7C,MAAM,QAAQ,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC3C,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACpE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CACpB,CAAC;QACF,uCACK,KAAK,KACR,GAAG,EAAE,SAAS,EACd,IAAI,kCAAO,KAAK,CAAC,IAAI,KAAE,OAAO,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,OACrD;IACJ,CAAC;IACD,OAAO;QACL,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import {\n LoadEntitiesKeyedConfig,\n LoadEntitiesSelectors,\n LoadEntitiesState,\n} from '../load-entities/load-entities.model';\nimport {\n Sort,\n SortEntitiesMutators,\n SortEntitiesState,\n} from './sort-entities.model';\nimport { sortData } from './sort-entities.utils';\n\nexport function createSortTraitMutators<Entity>(\n { selectEntitiesList }: LoadEntitiesSelectors<Entity>,\n allConfigs: LoadEntitiesKeyedConfig<Entity>\n): SortEntitiesMutators<Entity> {\n function sortEntities<\n S extends LoadEntitiesState<Entity> & SortEntitiesState<Entity>\n >({ active, direction }: Sort<Entity>, state: S) {\n const { adapter } = allConfigs.loadEntities!;\n const entities = selectEntitiesList(state);\n const sortedIds = sortData(entities, { active, direction }).map((v) =>\n adapter.selectId(v)\n );\n return {\n ...state,\n ids: sortedIds,\n sort: { ...state.sort, current: { active, direction } },\n };\n }\n return {\n sortEntities,\n };\n}\n"]}
|