mirror of https://github.com/abpframework/abp.git
6 changed files with 2 additions and 151 deletions
@ -1,5 +1,4 @@ |
|||||
export { SetEnvironment, GetAppConfiguration } from './config.actions'; |
export { GetAppConfiguration, SetEnvironment } 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'; |
||||
|
|||||
@ -1,13 +0,0 @@ |
|||||
import { ReplaceableComponents } from '../models/replaceable-components'; |
|
||||
|
|
||||
// tslint:disable: max-line-length
|
|
||||
/** |
|
||||
* @deprecated To be deleted in v4.0. Use ReplaceableComponentsService instead. See the doc (https://docs.abp.io/en/abp/latest/UI/Angular/Component-Replacement)
|
|
||||
*/ |
|
||||
export class AddReplaceableComponent { |
|
||||
static readonly type = '[ReplaceableComponents] Add'; |
|
||||
constructor( |
|
||||
public payload: ReplaceableComponents.ReplaceableComponent, |
|
||||
public reload?: boolean, |
|
||||
) {} |
|
||||
} |
|
||||
@ -1,3 +1,2 @@ |
|||||
export * from './replaceable-components.state'; |
|
||||
export * from './config.state'; |
export * from './config.state'; |
||||
export * from './profile.state'; |
export * from './profile.state'; |
||||
|
|||||
@ -1,74 +0,0 @@ |
|||||
import { Injectable, isDevMode } from '@angular/core'; |
|
||||
import { Action, createSelector, Selector, State, StateContext } from '@ngxs/store'; |
|
||||
import snq from 'snq'; |
|
||||
import { AddReplaceableComponent } from '../actions/replaceable-components.actions'; |
|
||||
import { ReplaceableComponents } from '../models/replaceable-components'; |
|
||||
import { ReplaceableComponentsService } from '../services/replaceable-components.service'; |
|
||||
|
|
||||
function logDeprecationMsg() { |
|
||||
if (isDevMode()) { |
|
||||
console.warn(` |
|
||||
ReplacableComponentsState has been deprecated. Use ReplaceableComponentsService instead. |
|
||||
See the doc https://docs.abp.io/en/abp/latest/UI/Angular/Component-Replacement
|
|
||||
`);
|
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// tslint:disable: max-line-length
|
|
||||
/** |
|
||||
* @deprecated To be deleted in v4.0. Use ReplaceableComponentsService instead. See the doc (https://docs.abp.io/en/abp/latest/UI/Angular/Component-Replacement)
|
|
||||
*/ |
|
||||
@State<ReplaceableComponents.State>({ |
|
||||
name: 'ReplaceableComponentsState', |
|
||||
defaults: { replaceableComponents: [] } as ReplaceableComponents.State, |
|
||||
}) |
|
||||
@Injectable() |
|
||||
export class ReplaceableComponentsState { |
|
||||
@Selector() |
|
||||
static getAll({ |
|
||||
replaceableComponents, |
|
||||
}: ReplaceableComponents.State): ReplaceableComponents.ReplaceableComponent[] { |
|
||||
logDeprecationMsg(); |
|
||||
return replaceableComponents || []; |
|
||||
} |
|
||||
|
|
||||
static getComponent(key: string) { |
|
||||
const selector = createSelector( |
|
||||
[ReplaceableComponentsState], |
|
||||
(state: ReplaceableComponents.State): ReplaceableComponents.ReplaceableComponent => { |
|
||||
logDeprecationMsg(); |
|
||||
return snq(() => state.replaceableComponents.find(component => component.key === key)); |
|
||||
}, |
|
||||
); |
|
||||
|
|
||||
return selector; |
|
||||
} |
|
||||
|
|
||||
constructor(private service: ReplaceableComponentsService) {} |
|
||||
|
|
||||
@Action(AddReplaceableComponent) |
|
||||
replaceableComponentsAction( |
|
||||
{ getState, patchState }: StateContext<ReplaceableComponents.State>, |
|
||||
{ payload, reload }: AddReplaceableComponent, |
|
||||
) { |
|
||||
logDeprecationMsg(); |
|
||||
|
|
||||
let { replaceableComponents } = getState(); |
|
||||
|
|
||||
const index = snq( |
|
||||
() => replaceableComponents.findIndex(component => component.key === payload.key), |
|
||||
-1, |
|
||||
); |
|
||||
if (index > -1) { |
|
||||
replaceableComponents[index] = payload; |
|
||||
} else { |
|
||||
replaceableComponents = [...replaceableComponents, payload]; |
|
||||
} |
|
||||
|
|
||||
patchState({ |
|
||||
replaceableComponents, |
|
||||
}); |
|
||||
|
|
||||
this.service.add(payload, reload); |
|
||||
} |
|
||||
} |
|
||||
@ -1,59 +0,0 @@ |
|||||
import { APP_BASE_HREF } from '@angular/common'; |
|
||||
import { Component } from '@angular/core'; |
|
||||
import { Router, RouterModule } from '@angular/router'; |
|
||||
import { SpyObject } from '@ngneat/spectator'; |
|
||||
import { createHostFactory, SpectatorHost } from '@ngneat/spectator/jest'; |
|
||||
import { NgxsModule, Store } from '@ngxs/store'; |
|
||||
import { AddReplaceableComponent } from '../actions'; |
|
||||
import { ReplaceableComponentsState } from '../states/replaceable-components.state'; |
|
||||
|
|
||||
@Component({ selector: 'abp-dummy', template: 'dummy works' }) |
|
||||
class DummyComponent {} |
|
||||
|
|
||||
describe('ReplaceableComponentsState', () => { |
|
||||
let spectator: SpectatorHost<DummyComponent>; |
|
||||
let router: SpyObject<Router>; |
|
||||
const createHost = createHostFactory({ |
|
||||
component: DummyComponent, |
|
||||
providers: [{ provide: APP_BASE_HREF, useValue: '/' }], |
|
||||
imports: [RouterModule.forRoot([]), NgxsModule.forRoot([ReplaceableComponentsState])], |
|
||||
}); |
|
||||
|
|
||||
beforeEach(() => { |
|
||||
spectator = createHost('<abp-dummy></abp-dummy>'); |
|
||||
router = spectator.inject(Router); |
|
||||
}); |
|
||||
|
|
||||
it('should add a component to the state', () => { |
|
||||
const store = spectator.inject(Store); |
|
||||
expect(store.selectSnapshot(ReplaceableComponentsState.getAll)).toEqual([]); |
|
||||
store.dispatch(new AddReplaceableComponent({ component: DummyComponent, key: 'Dummy' })); |
|
||||
expect(store.selectSnapshot(ReplaceableComponentsState.getComponent('Dummy'))).toEqual({ |
|
||||
component: DummyComponent, |
|
||||
key: 'Dummy', |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
it('should replace a exist component', () => { |
|
||||
const store = spectator.inject(Store); |
|
||||
store.dispatch(new AddReplaceableComponent({ component: DummyComponent, key: 'Dummy' })); |
|
||||
store.dispatch(new AddReplaceableComponent({ component: null, key: 'Dummy' })); |
|
||||
expect(store.selectSnapshot(ReplaceableComponentsState.getComponent('Dummy'))).toEqual({ |
|
||||
component: null, |
|
||||
key: 'Dummy', |
|
||||
}); |
|
||||
expect(store.selectSnapshot(ReplaceableComponentsState.getAll)).toHaveLength(1); |
|
||||
}); |
|
||||
|
|
||||
it('should call reloadRoute when reload parameter is given as true to AddReplaceableComponent', async () => { |
|
||||
const spy = jest.spyOn(router, 'navigateByUrl'); |
|
||||
const store = spectator.inject(Store); |
|
||||
store.dispatch(new AddReplaceableComponent({ component: DummyComponent, key: 'Dummy' })); |
|
||||
store.dispatch(new AddReplaceableComponent({ component: null, key: 'Dummy' }, true)); |
|
||||
|
|
||||
await spectator.fixture.whenStable(); |
|
||||
|
|
||||
expect(spy).toHaveBeenCalledTimes(1); |
|
||||
expect(spy).toHaveBeenCalledWith(router.url); |
|
||||
}); |
|
||||
}); |
|
||||
Loading…
Reference in new issue