mirror of https://github.com/abpframework/abp.git
7 changed files with 72 additions and 6 deletions
@ -1,5 +1,6 @@ |
|||||
export * from './config.actions'; |
export * from './config.actions'; |
||||
export * from './loader.actions'; |
export * from './loader.actions'; |
||||
export * from './profile.actions'; |
export * from './profile.actions'; |
||||
|
export * from './replaceable-components.actions'; |
||||
export * from './rest.actions'; |
export * from './rest.actions'; |
||||
export * from './session.actions'; |
export * from './session.actions'; |
||||
@ -0,0 +1,6 @@ |
|||||
|
import { ReplaceableComponents } from '../models/replaceable-components'; |
||||
|
|
||||
|
export class AddReplaceableComponent { |
||||
|
static readonly type = '[ReplaceableComponents] Add'; |
||||
|
constructor(public payload: ReplaceableComponents.Data | ReplaceableComponents.Data[]) {} |
||||
|
} |
||||
@ -1,6 +1,7 @@ |
|||||
export * from './application-configuration'; |
export * from './application-configuration'; |
||||
export * from './common'; |
export * from './common'; |
||||
export * from './config'; |
export * from './config'; |
||||
export * from './rest'; |
|
||||
export * from './session'; |
|
||||
export * from './profile'; |
export * from './profile'; |
||||
|
export * from './replaceable-components'; |
||||
|
export * from './rest'; |
||||
|
export * from './session'; |
||||
@ -0,0 +1,12 @@ |
|||||
|
import { Type } from '@angular/core'; |
||||
|
|
||||
|
export namespace ReplaceableComponents { |
||||
|
export interface State { |
||||
|
replaceableComponents: Data[]; |
||||
|
} |
||||
|
|
||||
|
export interface Data { |
||||
|
component: Type<any>; |
||||
|
key: string; |
||||
|
} |
||||
|
} |
||||
@ -1,3 +1,4 @@ |
|||||
export * from './profile.state'; |
export * from "./replaceable-components.state"; |
||||
export * from './config.state'; |
export * from './config.state'; |
||||
export * from './session.state'; |
export * from './profile.state'; |
||||
|
export * from './session.state'; |
||||
@ -0,0 +1,44 @@ |
|||||
|
import { State, Action, StateContext, Selector, createSelector } from '@ngxs/store'; |
||||
|
import { AddReplaceableComponent } from '../actions/replaceable-components.actions'; |
||||
|
import { ReplaceableComponents } from '../models/replaceable-components'; |
||||
|
import snq from 'snq'; |
||||
|
|
||||
|
@State<ReplaceableComponents.State>({ |
||||
|
name: 'ReplaceableComponentsState', |
||||
|
defaults: { replaceableComponents: [] } as ReplaceableComponents.State, |
||||
|
}) |
||||
|
export class ReplaceableComponentsState { |
||||
|
@Selector() |
||||
|
static getAll({ |
||||
|
replaceableComponents, |
||||
|
}: ReplaceableComponents.State): ReplaceableComponents.Data[] { |
||||
|
return replaceableComponents || []; |
||||
|
} |
||||
|
|
||||
|
static getOne(key: string) { |
||||
|
const selector = createSelector( |
||||
|
[ReplaceableComponentsState], |
||||
|
({ replaceableComponents }: ReplaceableComponents.State) => { |
||||
|
return snq(() => replaceableComponents.find(component => component.key === key)); |
||||
|
}, |
||||
|
); |
||||
|
|
||||
|
return selector; |
||||
|
} |
||||
|
|
||||
|
@Action(AddReplaceableComponent) |
||||
|
replaceableComponentsAction( |
||||
|
{ getState, patchState }: StateContext<ReplaceableComponents.State>, |
||||
|
{ payload }: AddReplaceableComponent, |
||||
|
) { |
||||
|
if (!Array.isArray(payload)) { |
||||
|
payload = [payload]; |
||||
|
} |
||||
|
|
||||
|
const { replaceableComponents } = getState(); |
||||
|
|
||||
|
patchState({ |
||||
|
replaceableComponents: [...replaceableComponents, ...payload], |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue