diff --git a/CHANGELOG.md b/CHANGELOG.md index cfd8d98..4b470ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 1.1.1 (2020-02-05) + +- Allow to select children +- Allow to resolve several contexts at once + # 1.1.0 (2020-01-28) - Tile support diff --git a/projects/ngx-state-traverser/package.json b/projects/ngx-state-traverser/package.json index 0c28316..136ef06 100644 --- a/projects/ngx-state-traverser/package.json +++ b/projects/ngx-state-traverser/package.json @@ -1,6 +1,6 @@ { "name": "@guillotinaweb/ngx-state-traverser", - "version": "1.1.0", + "version": "1.1.1", "license": "MIT", "author": { "name": "Eric Brehault", diff --git a/projects/ngx-state-traverser/src/lib/actions.ts b/projects/ngx-state-traverser/src/lib/actions.ts index cf64dc4..5cfb08c 100644 --- a/projects/ngx-state-traverser/src/lib/actions.ts +++ b/projects/ngx-state-traverser/src/lib/actions.ts @@ -7,6 +7,7 @@ export namespace TraverserActions { Traverse = '[Traversal] Traverse', ResolveContext = '[Traversal] Resolve context', Resolve = '[Traversal] Resolve', + ResolveMany = '[Traversal] Resolve many', CleanTraverserResources = '[Traversal] Clean resources', UpdateTraverserResource = '[Traversal] Update resources', LoadTile = '[Traversal] Load tile', @@ -28,6 +29,11 @@ export namespace TraverserActions { constructor(readonly payload: {path: string, object: any}) {} } + export class ResolveMany implements Action { + readonly type = Types.ResolveMany; + constructor(readonly payload: {path: string, object: any}[]) {} + } + export class CleanTraverserResources implements Action { readonly type = Types.CleanTraverserResources; constructor(readonly payload: string[]) {} @@ -52,6 +58,7 @@ export namespace TraverserActions { | Traverse | ResolveContext | Resolve + | ResolveMany | CleanTraverserResources | UpdateTraverserResource | LoadTile diff --git a/projects/ngx-state-traverser/src/lib/reducer.ts b/projects/ngx-state-traverser/src/lib/reducer.ts index 75b2d3e..abb48c4 100644 --- a/projects/ngx-state-traverser/src/lib/reducer.ts +++ b/projects/ngx-state-traverser/src/lib/reducer.ts @@ -60,6 +60,23 @@ export function reducer(state = initialState, action: TraverserActions.Actions): }, }; } + case TraverserActions.Types.ResolveMany: { + const collection = action.payload.reduce((all, current) => { + let path = current.path; + if (!!path && path.endsWith('/')) { + path = path.slice(0, -1); + } + all[path] = current.object; + return all; + }, {}); + return { + ...state, + collection: { + ...state.collection, + ...collection, + }, + }; + } case TraverserActions.Types.CleanTraverserResources: { const exactPathes = action.payload.filter(path => !path.endsWith('*')); const startPathes = action.payload.filter(path => path.endsWith('*')).map(path => path.slice(0, -1)); diff --git a/projects/ngx-state-traverser/src/lib/selector.ts b/projects/ngx-state-traverser/src/lib/selector.ts index 6e66886..cb17a16 100644 --- a/projects/ngx-state-traverser/src/lib/selector.ts +++ b/projects/ngx-state-traverser/src/lib/selector.ts @@ -104,6 +104,21 @@ export namespace TraverserSelectors { } ); + export const getContextChildren = createSelector( + traversalSelector, + getContextPath, + ( + state: TraversingState, + contextPath: string, + ): { [key: string]: any }[] => Object.entries(state.collection).reduce((children, [id, obj]) => { + const parentPath = id.substring(0, id.lastIndexOf('/')); + if (parentPath === contextPath) { + children.push(obj); + } + return children; + }, [] as { [key: string]: any }[]) + ); + export const getAncestors = createSelector( traversalSelector, (state: TraversingState, path: string): ContextOrMissing[] => {