@ngrx-traits/common 12.0.0 → 12.1.0
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/bundles/ngrx-traits-common.umd.js +3 -3
- package/bundles/ngrx-traits-common.umd.js.map +1 -1
- package/entities-pagination/entities-pagination.trait.d.ts +1 -1
- package/esm2015/entities-pagination/entities-pagination.trait.js +2 -2
- package/esm2015/entities-pagination/entities-pagination.trait.js.map +1 -1
- package/esm2015/filter-entities/filter-entities.trait.js +1 -1
- package/esm2015/filter-entities/filter-entities.trait.js.map +1 -1
- package/fesm2015/ngrx-traits-common.js +3 -3
- package/fesm2015/ngrx-traits-common.js.map +1 -1
- package/filter-entities/filter-entities.trait.d.ts +1 -1
- package/package.json +2 -2
|
@@ -11,7 +11,7 @@ import { EntitiesPaginationConfig, EntitiesPaginationSelectors } from './entitie
|
|
|
11
11
|
* To make the pagination experience smoother the loadEntities to get new pages is done when the current page is change to
|
|
12
12
|
* the last cached page.
|
|
13
13
|
* @param config
|
|
14
|
-
* @param config.cacheType - Default to '
|
|
14
|
+
* @param config.cacheType - Default to 'partial', change the cache mode
|
|
15
15
|
* @param config.pageSize - Default to 20, number of entities on each page
|
|
16
16
|
* @param config.currentPage - Default to 0, starting page
|
|
17
17
|
* @param config.pagesToCache - Default to 3, used in partial and grow cache mode, is the number of
|
|
@@ -18,7 +18,7 @@ import { createPaginationTraitMutators } from './entities-pagination.trait.mutat
|
|
|
18
18
|
* To make the pagination experience smoother the loadEntities to get new pages is done when the current page is change to
|
|
19
19
|
* the last cached page.
|
|
20
20
|
* @param config
|
|
21
|
-
* @param config.cacheType - Default to '
|
|
21
|
+
* @param config.cacheType - Default to 'partial', change the cache mode
|
|
22
22
|
* @param config.pageSize - Default to 20, number of entities on each page
|
|
23
23
|
* @param config.currentPage - Default to 0, starting page
|
|
24
24
|
* @param config.pagesToCache - Default to 3, used in partial and grow cache mode, is the number of
|
|
@@ -59,7 +59,7 @@ import { createPaginationTraitMutators } from './entities-pagination.trait.mutat
|
|
|
59
59
|
* traits.selectors.selectTodosPagedRequest()// use in effects to get paging parameter
|
|
60
60
|
* traits.selectors.selectTodosPageInfo()
|
|
61
61
|
*/
|
|
62
|
-
export function addEntitiesPaginationTrait({ cacheType = '
|
|
62
|
+
export function addEntitiesPaginationTrait({ cacheType = 'partial', pageSize = 20, currentPage = 0, pagesToCache = 3, } = {}) {
|
|
63
63
|
return createTraitFactory({
|
|
64
64
|
key: entitiesPaginationTraitKey,
|
|
65
65
|
depends: [loadEntitiesTraitKey],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities-pagination.trait.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/entities-pagination/entities-pagination.trait.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,0BAA0B,GAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAC;AACvF,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AAKnF,OAAO,EAKL,oBAAoB,GACrB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,sCAAsC,CAAC;AAQrF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,MAAM,UAAU,0BAA0B,CAAS,EACjD,SAAS,GAAG,
|
|
1
|
+
{"version":3,"file":"entities-pagination.trait.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/entities-pagination/entities-pagination.trait.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,0BAA0B,GAC3B,MAAM,6BAA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CAC5C;QACH,OAAO,EAAE,CAAC,EACR,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,WAAW,EACX,UAAU,GACX,EAAE,EAAE,CACH,4BAA4B,CAC1B,YAAY,EACZ,UAG6B,EAC7B,YAC+B,EAC/B,WAC8B,EAC9B,UAE+B,CAChC;QACH,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,EAAE,CACxC,4BAA4B,CAC1B,UAG6B,EAC7B,YAC+B,CAChC;KACJ,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n EntitiesPaginationConfig,\n EntitiesPaginationKeyedConfig,\n EntitiesPaginationMutators,\n EntitiesPaginationSelectors,\n entitiesPaginationTraitKey,\n} from './entities-pagination.model';\nimport { createPaginationTraitSelectors } from './entities-pagination.trait.selectors';\nimport { createPaginationTraitActions } from './entities-pagination.trait.actions';\nimport {\n FilterEntitiesActions,\n FilterEntitiesKeyedConfig,\n} from '../filter-entities/filter-entities.model';\nimport {\n LoadEntitiesActions,\n LoadEntitiesKeyedConfig,\n LoadEntitiesMutators,\n LoadEntitiesSelectors,\n loadEntitiesTraitKey,\n} from '../load-entities/load-entities.model';\nimport {\n createPaginationInitialState,\n createPaginationTraitReducer,\n} from './entities-pagination.trait.reducer';\nimport { createPaginationTraitEffects } from './entities-pagination.trait.effects';\nimport { createTraitFactory } from '@ngrx-traits/core';\nimport { CrudEntitiesActions } from '../crud-entities/crud-entities.model';\nimport { createPaginationTraitMutators } from './entities-pagination.trait.mutators';\nimport { ƟPaginationActions } from './entities-pagination.model.internal';\nimport {\n TraitActionsFactoryConfig,\n TraitInitialStateFactoryConfig,\n TraitSelectorsFactoryConfig,\n} from '@ngrx-traits/core';\n\n/**\n * Generates ngrx code to paginate an list of entities, this has 3 cache `cacheType`\n * - 'full': The full result is cache in memory and split in pages to render, useful\n * for small result but not so small that requires been render in pages\n * - 'partial': Backend returns partial results because is are to big, this has a cache a few pages forward\n * to avoid calling the backend on each page, the cache is clean when a new loadEntities is required\n * - 'grow': Similar to partial that the backend returns partial result, but in this case the cache grows,\n * after each loadEntities the cache is appended to the previous cache, this mode is ideal for infinite scrolls,\n * where you will only call loadNextPage.\n * To make the pagination experience smoother the loadEntities to get new pages is done when the current page is change to\n * the last cached page.\n * @param config\n * @param config.cacheType - Default to 'partial', change the cache mode\n * @param config.pageSize - Default to 20, number of entities on each page\n * @param config.currentPage - Default to 0, starting page\n * @param config.pagesToCache - Default to 3, used in partial and grow cache mode, is the number of\n * extra pages kept in cache to avoid calling the backend on each page\n *\n * @example\n * // The following trait config\n *\n * export interface TestState\n * extends EntityAndStatusState<Todo>,SingleSelectionState{}\n *\n * const traits = createEntityFeatureFactory(\n * addLoadEntitiesTrait<Todo>(),\n * addEntitiesPaginationTrait<Todo>()\n * )({\n * actionsGroupKey: '[Todos]',\n * featureSelector: createFeatureSelector<TestState>>(\n * 'todos',\n * ),\n * });\n * // will generate the following actions and selectors, plus the ones generated by other traits\n * traits.actions.loadTodosPage({index})\n * traits.actions.loadTodosPageSuccess()\n * traits.actions.loadTodosPageFail()\n * traits.actions.loadTodosNextPage()\n * traits.actions.loadTodosPreviousPage()\n * traits.actions.loadTodosFirstPage()\n * traits.actions.loadTodosLastPage()\n * traits.actions.clearTodosPagesCache()\n *\n * // page param is optional and defaults to current page\n * traits.selectors.isTodosPageInCache({page})\n * traits.selectors.selectPageTodosList({page})\n * traits.selectors.isLoadingTodosPage({page})\n * // prefer isLoadingTodosPage over isLoadingTodos which will return true even\n * // if the page loading is not the current one\n * traits.selectors.selectTodosPage({page})\n * traits.selectors.selectTodosPagedRequest()// use in effects to get paging parameter\n * traits.selectors.selectTodosPageInfo()\n */\nexport function addEntitiesPaginationTrait<Entity>({\n cacheType = 'partial',\n pageSize = 20,\n currentPage = 0,\n pagesToCache = 3,\n}: EntitiesPaginationConfig = {}) {\n return createTraitFactory({\n key: entitiesPaginationTraitKey,\n depends: [loadEntitiesTraitKey],\n config: {\n cacheType,\n pageSize,\n currentPage,\n pagesToCache,\n } as EntitiesPaginationConfig,\n actions: ({ actionsGroupKey, entitiesName }: TraitActionsFactoryConfig) =>\n createPaginationTraitActions(actionsGroupKey, entitiesName),\n selectors: ({\n previousSelectors,\n allConfigs,\n }: TraitSelectorsFactoryConfig) =>\n createPaginationTraitSelectors<Entity>(\n previousSelectors as LoadEntitiesSelectors<Entity>,\n allConfigs as EntitiesPaginationKeyedConfig &\n FilterEntitiesKeyedConfig<Entity, unknown>\n ),\n mutators: ({ allSelectors, allConfigs }) =>\n createPaginationTraitMutators<Entity>(\n allSelectors as EntitiesPaginationSelectors<Entity> &\n LoadEntitiesSelectors<Entity>,\n allConfigs as EntitiesPaginationKeyedConfig &\n LoadEntitiesKeyedConfig<Entity>\n ),\n initialState: ({\n previousInitialState,\n allConfigs,\n }: TraitInitialStateFactoryConfig) =>\n createPaginationInitialState<Entity>(\n previousInitialState,\n allConfigs as EntitiesPaginationKeyedConfig\n ),\n reducer: ({\n initialState,\n allActions,\n allSelectors,\n allMutators,\n allConfigs,\n }) =>\n createPaginationTraitReducer(\n initialState,\n allActions as ƟPaginationActions &\n FilterEntitiesActions<Entity> &\n LoadEntitiesActions<Entity> &\n CrudEntitiesActions<Entity>,\n allSelectors as EntitiesPaginationSelectors<Entity> &\n LoadEntitiesSelectors<Entity>,\n allMutators as EntitiesPaginationMutators<Entity> &\n LoadEntitiesMutators<Entity>,\n allConfigs as FilterEntitiesKeyedConfig<Entity, unknown> &\n LoadEntitiesKeyedConfig<Entity> &\n EntitiesPaginationKeyedConfig\n ),\n effects: ({ allActions, allSelectors }) =>\n createPaginationTraitEffects(\n allActions as ƟPaginationActions &\n FilterEntitiesActions<Entity> &\n LoadEntitiesActions<Entity> &\n CrudEntitiesActions<Entity>,\n allSelectors as EntitiesPaginationSelectors<Entity> &\n LoadEntitiesSelectors<Entity>\n ),\n });\n}\n"]}
|
|
@@ -33,7 +33,7 @@ import { createFilterTraitActions } from './filter-entities.trait.actions';
|
|
|
33
33
|
* addLoadEntitiesTrait<Todo>(),
|
|
34
34
|
* //addFilterEntitiesTrait<Todo,TodoFilter>() // no params uses remote filtering
|
|
35
35
|
* addFilterEntitiesTrait<Todo,TodoFilter>({filterFn: (filter, entity) => // local filtering
|
|
36
|
-
* filter
|
|
36
|
+
* !filter.content || !!entity.content?.includes(filter.content.toLowerCase())
|
|
37
37
|
* // or use the following function to switch between remote search and local
|
|
38
38
|
* // depending on which properties have changed in the filter
|
|
39
39
|
* // isRemoteFilter: (previous, current) => previous?.someRemoteParam !== current?.someRemoteParam,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-entities.trait.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/filter-entities/filter-entities.trait.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,GAC3B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAIL,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAGL,oBAAoB,GACrB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAO3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,sBAAsB,CAAY,EAChD,mBAAmB,GAAG,GAAG,EACzB,aAAa,EACb,QAAQ,EACR,cAAc,MACqB,EAAE;IACrC,OAAO,kBAAkB,CAAC;QACxB,GAAG,EAAE,sBAAsB;QAC3B,OAAO,EAAE,CAAC,0BAA0B,EAAE,oBAAoB,CAAC;QAC3D,MAAM,EAAE;YACN,mBAAmB;YACnB,aAAa;YACb,QAAQ;YACR,cAAc;SACoB;QACpC,OAAO,EAAE,CAAC,EAAE,eAAe,EAAE,YAAY,EAA6B,EAAE,EAAE,CACxE,wBAAwB,CAAI,eAAe,EAAE,YAAY,CAAC;QAC5D,SAAS,EAAE,GAAG,EAAE,CAAC,0BAA0B,EAAa;QACxD,QAAQ,EAAE,GAAG,EAAE,CAAC,yBAAyB,EAAa;QACtD,YAAY,EAAE,CAAC,EACb,oBAAoB,EACpB,UAAU,GACqB,EAAE,EAAE,CACnC,wBAAwB,CACtB,oBAAoB,EACpB,UAAkD,CACnD;QACH,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,EAAE,CACrD,wBAAwB,CACtB,YAAY,EACZ,UAAqE,EACrE,WAAW,CACZ;QACH,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,EAAE,CACpD,wBAAwB,CACtB,UAE2B,EAC3B,YAC+B,EAC/B,UAAU,CACX;KACJ,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n EntitiesPaginationActions,\n entitiesPaginationTraitKey,\n} from '../entities-pagination/entities-pagination.model';\nimport { createFilterTraitEffects } from './filter-entities.trait.effect';\nimport {\n createFilterInitialState,\n createFilterTraitReducer,\n} from './filter-entities.trait.reducer';\nimport {\n FilterEntitiesConfig,\n FilterEntitiesKeyedConfig,\n FilterEntitiesSelectors,\n filterEntitiesTraitKey,\n} from './filter-entities.model';\nimport { createFilterTraitSelectors } from './filter-entities.trait.selectors';\nimport {\n LoadEntitiesActions,\n LoadEntitiesSelectors,\n loadEntitiesTraitKey,\n} from '../load-entities/load-entities.model';\nimport { createFilterTraitMutators } from './filter-entities.trait.mutators';\nimport { createTraitFactory } from '@ngrx-traits/core';\nimport { createFilterTraitActions } from './filter-entities.trait.actions';\nimport { ƟFilterEntitiesActions } from './filter-entities.model.internal';\nimport {\n TraitActionsFactoryConfig,\n TraitInitialStateFactoryConfig,\n} from '@ngrx-traits/core';\n\n/**\n * Generates the ngrx code needed to filter a list of entities locally or remotely, adds a filter\n * action and a selectFilter selector, the filter action is debounced and the filter will only\n * call the loadEntities action if the params have changed, so there is no need to implement that in\n * the components. The filter action has a `forceLoad` param which can\n * be use to skip that restriction for one call or setting the `defaultDebounceTime` to 0 for all calls.\n * Calling the filter action will also replace the `filters` param in the store, if the `patch` param is set\n * the filters are merged with the previous value in the store.\n * @param traitConfig - Config object fot the trait factory\n * @param traitConfig.defaultFilter - Initial value for the filter\n * @param traitConfig.filterFn - Function to filter entities in memory, if not present then its expected\n * is filtered by the backend unless isRemoteFilter is defned\n * @param traitConfig.defaultDebounceTime - Value in milliseconds. Default to 400ms\n * @param traitConfig.isRemoteFilter - Function to when it returns true it fires loadEntities so a remote\n * backend filtering can run, otherwise it uses filterFn to do a local filtering\n *\n * @example\n * // The following trait config\n *\n * export interface TestState\n * extends EntityAndStatusState<Todo>,FilterState<TodoFilter>{}\n *\n * const traits = createEntityFeatureFactory(\n * addLoadEntitiesTrait<Todo>(),\n * //addFilterEntitiesTrait<Todo,TodoFilter>() // no params uses remote filtering\n * addFilterEntitiesTrait<Todo,TodoFilter>({filterFn: (filter, entity) => // local filtering\n * filter
|
|
1
|
+
{"version":3,"file":"filter-entities.trait.js","sourceRoot":"","sources":["../../../../../../libs/ngrx-traits/common/src/lib/filter-entities/filter-entities.trait.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,GAC3B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAIL,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAG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ities-pagination/entities-pagination.model';\nimport { createFilterTraitEffects } from './filter-entities.trait.effect';\nimport {\n createFilterInitialState,\n createFilterTraitReducer,\n} from './filter-entities.trait.reducer';\nimport {\n FilterEntitiesConfig,\n FilterEntitiesKeyedConfig,\n FilterEntitiesSelectors,\n filterEntitiesTraitKey,\n} from './filter-entities.model';\nimport { createFilterTraitSelectors } from './filter-entities.trait.selectors';\nimport {\n LoadEntitiesActions,\n LoadEntitiesSelectors,\n loadEntitiesTraitKey,\n} from '../load-entities/load-entities.model';\nimport { createFilterTraitMutators } from './filter-entities.trait.mutators';\nimport { createTraitFactory } from '@ngrx-traits/core';\nimport { createFilterTraitActions } from './filter-entities.trait.actions';\nimport { ƟFilterEntitiesActions } from './filter-entities.model.internal';\nimport {\n TraitActionsFactoryConfig,\n TraitInitialStateFactoryConfig,\n} from '@ngrx-traits/core';\n\n/**\n * Generates the ngrx code needed to filter a list of entities locally or remotely, adds a filter\n * action and a selectFilter selector, the filter action is debounced and the filter will only\n * call the loadEntities action if the params have changed, so there is no need to implement that in\n * the components. The filter action has a `forceLoad` param which can\n * be use to skip that restriction for one call or setting the `defaultDebounceTime` to 0 for all calls.\n * Calling the filter action will also replace the `filters` param in the store, if the `patch` param is set\n * the filters are merged with the previous value in the store.\n * @param traitConfig - Config object fot the trait factory\n * @param traitConfig.defaultFilter - Initial value for the filter\n * @param traitConfig.filterFn - Function to filter entities in memory, if not present then its expected\n * is filtered by the backend unless isRemoteFilter is defned\n * @param traitConfig.defaultDebounceTime - Value in milliseconds. Default to 400ms\n * @param traitConfig.isRemoteFilter - Function to when it returns true it fires loadEntities so a remote\n * backend filtering can run, otherwise it uses filterFn to do a local filtering\n *\n * @example\n * // The following trait config\n *\n * export interface TestState\n * extends EntityAndStatusState<Todo>,FilterState<TodoFilter>{}\n *\n * const traits = createEntityFeatureFactory(\n * addLoadEntitiesTrait<Todo>(),\n * //addFilterEntitiesTrait<Todo,TodoFilter>() // no params uses remote filtering\n * addFilterEntitiesTrait<Todo,TodoFilter>({filterFn: (filter, entity) => // local filtering\n * !filter.content || !!entity.content?.includes(filter.content.toLowerCase())\n * // or use the following function to switch between remote search and local\n * // depending on which properties have changed in the filter\n * // isRemoteFilter: (previous, current) => previous?.someRemoteParam !== current?.someRemoteParam,\n * )({\n * actionsGroupKey: '[Todos]',\n * featureSelector: createFeatureSelector<TestState>>(\n * 'todos',\n * ),\n * });\n * // will generate the following actions and selectors, plus the ones generated by other traits\n * traits.actions.filterTodos()\n * traits.selectors.selectTodosFilter()\n */\nexport function addFilterEntitiesTrait<Entity, F>({\n defaultDebounceTime = 400,\n defaultFilter,\n filterFn,\n isRemoteFilter,\n}: FilterEntitiesConfig<Entity, F> = {}) {\n return createTraitFactory({\n key: filterEntitiesTraitKey,\n depends: [entitiesPaginationTraitKey, loadEntitiesTraitKey],\n config: {\n defaultDebounceTime,\n defaultFilter,\n filterFn,\n isRemoteFilter,\n } as FilterEntitiesConfig<Entity, F>,\n actions: ({ actionsGroupKey, entitiesName }: TraitActionsFactoryConfig) =>\n createFilterTraitActions<F>(actionsGroupKey, entitiesName),\n selectors: () => createFilterTraitSelectors<Entity, F>(),\n mutators: () => createFilterTraitMutators<Entity, F>(),\n initialState: ({\n previousInitialState,\n allConfigs,\n }: TraitInitialStateFactoryConfig) =>\n createFilterInitialState<Entity, F>(\n previousInitialState,\n allConfigs as FilterEntitiesKeyedConfig<Entity, F>\n ),\n reducer: ({ initialState, allActions, allMutators }) =>\n createFilterTraitReducer(\n initialState,\n allActions as ƟFilterEntitiesActions<F> & LoadEntitiesActions<Entity>,\n allMutators\n ),\n effects: ({ allActions, allSelectors, allConfigs }) =>\n createFilterTraitEffects(\n allActions as ƟFilterEntitiesActions<F> &\n LoadEntitiesActions<Entity> &\n EntitiesPaginationActions,\n allSelectors as FilterEntitiesSelectors<Entity, F> &\n LoadEntitiesSelectors<Entity>,\n allConfigs\n ),\n });\n}\n"]}
|
|
@@ -248,7 +248,7 @@ function createFilterTraitActions(actionsGroupKey, entitiesName) {
|
|
|
248
248
|
* addLoadEntitiesTrait<Todo>(),
|
|
249
249
|
* //addFilterEntitiesTrait<Todo,TodoFilter>() // no params uses remote filtering
|
|
250
250
|
* addFilterEntitiesTrait<Todo,TodoFilter>({filterFn: (filter, entity) => // local filtering
|
|
251
|
-
* filter
|
|
251
|
+
* !filter.content || !!entity.content?.includes(filter.content.toLowerCase())
|
|
252
252
|
* // or use the following function to switch between remote search and local
|
|
253
253
|
* // depending on which properties have changed in the filter
|
|
254
254
|
* // isRemoteFilter: (previous, current) => previous?.someRemoteParam !== current?.someRemoteParam,
|
|
@@ -479,7 +479,7 @@ function createPaginationTraitMutators(allSelectors, allConfigs) {
|
|
|
479
479
|
* To make the pagination experience smoother the loadEntities to get new pages is done when the current page is change to
|
|
480
480
|
* the last cached page.
|
|
481
481
|
* @param config
|
|
482
|
-
* @param config.cacheType - Default to '
|
|
482
|
+
* @param config.cacheType - Default to 'partial', change the cache mode
|
|
483
483
|
* @param config.pageSize - Default to 20, number of entities on each page
|
|
484
484
|
* @param config.currentPage - Default to 0, starting page
|
|
485
485
|
* @param config.pagesToCache - Default to 3, used in partial and grow cache mode, is the number of
|
|
@@ -520,7 +520,7 @@ function createPaginationTraitMutators(allSelectors, allConfigs) {
|
|
|
520
520
|
* traits.selectors.selectTodosPagedRequest()// use in effects to get paging parameter
|
|
521
521
|
* traits.selectors.selectTodosPageInfo()
|
|
522
522
|
*/
|
|
523
|
-
function addEntitiesPaginationTrait({ cacheType = '
|
|
523
|
+
function addEntitiesPaginationTrait({ cacheType = 'partial', pageSize = 20, currentPage = 0, pagesToCache = 3, } = {}) {
|
|
524
524
|
return createTraitFactory({
|
|
525
525
|
key: entitiesPaginationTraitKey,
|
|
526
526
|
depends: [loadEntitiesTraitKey],
|