本文整理匯總了TypeScript中@ngrx/effects.EffectsModule.forRoot方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript EffectsModule.forRoot方法的具體用法?TypeScript EffectsModule.forRoot怎麽用?TypeScript EffectsModule.forRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ngrx/effects.EffectsModule
的用法示例。
在下文中一共展示了EffectsModule.forRoot方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: entityServicesSetup
function entityServicesSetup() {
const logger = jasmine.createSpyObj('Logger', ['error', 'log', 'warn']);
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({}),
EffectsModule.forRoot([]),
NgrxDataModule.forRoot({
entityMetadata: entityMetadata
})
],
/* tslint:disable-next-line:no-use-before-declare */
providers: [
{ provide: EntityCacheEffects, useValue: {} },
{ provide: EntityDataService, useValue: null },
{ provide: Logger, useValue: logger }
]
});
const actions$: Observable<Action> = TestBed.get(Actions);
const entityActionFactory: EntityActionFactory = TestBed.get(EntityActionFactory);
const entityDispatcherFactory: EntityDispatcherFactory = TestBed.get(EntityDispatcherFactory);
const entityServices: EntityServices = TestBed.get(EntityServices);
const store: Store<EntityCache> = TestBed.get(Store);
return {
actions$,
entityActionFactory,
entityServices,
store
};
}
示例2: beforeEach
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
BrowserModule,
StoreModule.forRoot({ routerReducer }),
EffectsModule.forRoot([ IdentityEffects ]),
StoreDevtoolsModule.instrument({ maxAge: 50 }),
BrowserAnimationsModule,
FormsModule,
CoreModule.forRoot([
{ provide: WindowService, useFactory: (win) },
{ provide: ConsoleService, useFactory: (cons) },
{ provide: LogTarget, useFactory: (consoleLogTarget), deps: [ ConsoleService ], multi: true },
]),
RouterModule.forRoot(routes),
MultilingualModule.forRoot(TEST_MULTILINGUAL_PROVIDERS),
SampleModule,
DialogModule,
IdentityModule,
StoreRouterConnectingModule,
StoreModule.forFeature('sidebar', sidebarReducer),
StoreModule.forFeature('toolbar', toolbarReducer),
MATERIAL_MODULES,
FlexLayoutModule,
PLUGIN_MODULES,
],
declarations: [
AppComponent,
],
providers: [
{ provide: APP_BASE_HREF, useValue: '/' },
],
}).compileComponents();
}));
示例3: heroesComponentCoreSetup
// region helpers
function heroesComponentCoreSetup() {
const testHttp = jasmine.createSpyObj('HttpClient', [
'delete',
'get',
'put',
'post'
]);
// tslint:disable:quotemark
testHttp.delete.and.throwError("TEST FAIL! Shouldn't call http.delete");
testHttp.get.and.throwError("TEST FAIL! Shouldn't call http.get");
testHttp.post.and.throwError("TEST FAIL! Shouldn't call http.post");
testHttp.put.and.throwError("TEST FAIL! Shouldn't call http.put");
// tslint:enable:quotemark
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({}),
EffectsModule.forRoot([]),
CoreModule,
EntityStoreModule
],
providers: [
AppSelectors,
HeroesComponent, // When testing class-only
HeroesService,
{ provide: HttpClient, useValue: testHttp },
{ provide: NgrxDataToastService, useValue: null }
]
});
// Component listens for toggle between local and remote DB
appSelectorsDataSource = new BehaviorSubject('local');
const appSelectors: AppSelectors = TestBed.get(AppSelectors);
spyOn(appSelectors, 'dataSource$').and.returnValue(appSelectorsDataSource);
entityActionFactory = TestBed.get(EntityActionFactory);
heroesService = TestBed.get(HeroesService);
spyOn(heroesService, 'getAll').and.callFake(() => {
const getAllSuccessAction = createHeroAction(
EntityOp.QUERY_ALL_SUCCESS,
initialHeroes
);
testStore.dispatch(getAllSuccessAction);
});
testStore = TestBed.get(Store);
}
示例4: beforeEach
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
SDKBrowserModule.forRoot(),
StoreModule.forRoot(reducerToken, {}),
EffectsModule.forRoot(effects)
],
providers: [
{ provide: Router, useClass: RouterStub },
reducerProvider
]
});
store = TestBed.get(Store);
spyOn(store, 'dispatch').and.callThrough();
});
示例5: beforeEach
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
RouterTestingModule,
HttpModule,
NoopAnimationsModule,
DataListModule,
StoreModule.forRoot(reducers),
StoreRouterConnectingModule.forRoot({
stateKey: 'router'
}),
EffectsModule.forRoot([RoutingEffects]),
StoreModule.forFeature('users', usersReducer),
EffectsModule.forFeature([UserEffects])
],
providers: [ LoggerService,
{ provide: ActivatedRoute, useClass: ActivatedRouteStub },
{ provide: UserService, useValue: spyUserService },
{ provide: LoginService, useClass: LoginServiceStub },
{ provide: API_BASE_URL, useValue: '/api' },
UserActions,
UserResolver,
],
declarations: [UserListComponent]
});
// Create component
fixture = TestBed.createComponent(UserListComponent);
comp = fixture.componentInstance;
// Get BackendService actually injected into the component
// userService = TestBed.get(UserService);
userService = fixture.debugElement.injector.get(UserService);
// Setup spy on the `getQuote` method
// spy1 = spyOn(userService, 'findAllUsers').and.returnValue(Observable.of(testUsers));
// Get the tested element by CSS selector (e.g., by class name)
de = fixture.debugElement.query(By.css('ul'));
el = de.nativeElement;
});
示例6: beforeEach
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
imports: [
NoopAnimationsModule,
MatToolbarModule, MatIconModule, MatSidenavModule, MatListModule,
RouterTestingModule.withRoutes([]),
StoreModule.forRoot({sidenav, floatingPlayer}),
EffectsModule.forRoot([]),
FloatingPlayerModule
]
}).compileComponents();
fixture = TestBed.createComponent(AppComponent);
el = fixture.debugElement;
component = el.componentInstance;
fixture.detectChanges();
}));
示例7: beforeEach
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterModule,
UiModule,
RouterTestingModule,
NoopAnimationsModule,
StoreModule.forRoot(reducers),
StoreRouterConnectingModule.forRoot({
stateKey: 'router'
}),
EffectsModule.forRoot([RoutingEffects])
],
providers: [ LoggerService,
{ provide: ActivatedRoute, useClass: ActivatedRouteStub },
{ provide: UserService, useClass: UserServiceStub },
{ provide: API_BASE_URL, useValue: '/api' }
],
declarations: [
AppComponent
],
}).compileComponents();
}));
示例8:
import { BootEffects } from "./boot.effect";
import { PatientEffects } from './patient.effect';
import { SessionsEffects } from './sessions.effect';
import { PaymentsEffects } from './payments.effect';
import { PatientsEffects } from './patients.effect';
import { StoreEffects } from './store.effect';
import { StoreActionsEffects } from './storeActions.effect';
import { DiaryEffects } from './diary.effect';
import { MessagesEffects } from './messages.effect';
import { BackupEffects } from './backup.effect';
import { AppointmentsEffects } from './appointments.effect';
import { SearchsEffects } from './searchs.effect';
import { AuthEffects } from './auth.effect';
export const EFFECTS = EffectsModule.forRoot([
PatientEffects,
SessionsEffects,
StoreEffects,
StoreActionsEffects,
DiaryEffects,
MessagesEffects,
PaymentsEffects,
BackupEffects,
PatientsEffects,
AppointmentsEffects,
SearchsEffects,
AuthEffects,
BootEffects, // Should always remain last https://github.com/ngrx/platform/issues/103#issuecomment-316813618
]);
示例9: heroesComponentClassSetup
function heroesComponentClassSetup() {
TestBed.configureTestingModule({
imports: [StoreModule.forRoot({}), EffectsModule.forRoot([]), CoreModule, EntityStoreModule],
providers: [
Actions,
AppEntityServices,
AppSelectors,
HeroesComponent, // When testing class-only
HeroesService,
{ provide: HttpClient, useValue: null },
{ provide: NgrxDataToastService, useValue: null }
]
});
// Component listens for toggle between local and remote DB
const appSelectorsDataSource = new BehaviorSubject('local');
const appSelectors: AppSelectors = TestBed.get(AppSelectors);
spyOn(appSelectors, 'dataSource$').and.returnValue(appSelectorsDataSource);
// Create Hero entity actions as ngrx-data will do it
const entityActionFactory: EntityActionFactory = TestBed.get(EntityActionFactory);
function createHeroAction(op: EntityOp, data?: any, options?: EntityActionOptions) {
return entityActionFactory.create('Hero', op, data, options);
}
// Spy on EntityEffects
const effects: EntityEffects = TestBed.get(EntityEffects);
let persistResponsesSubject: ReplaySubject<Action>;
const persistSpy = spyOn(effects, 'persist').and.callFake(
(action: EntityAction) => (persistResponsesSubject = new ReplaySubject<Action>(1))
);
// Control EntityAction responses from EntityEffects spy
function setPersistResponses(...actions: Action[]) {
actions.forEach(action => persistResponsesSubject.next(action));
persistResponsesSubject.complete();
}
// Sample Hero test data
const initialHeroes = [
{ id: 1, name: 'A', saying: 'A says' },
{ id: 3, name: 'B', saying: 'B says' },
{ id: 2, name: 'C', saying: 'C says' }
];
// Spy on dispatches to the store (not very useful)
const testStore: Store<EntityCache> = TestBed.get(Store);
const dispatchSpy = spyOn(testStore, 'dispatch').and.callThrough();
return {
appSelectorsDataSource,
createHeroAction,
dispatchSpy,
effects,
entityActionFactory,
initialHeroes,
persistResponsesSubject,
persistSpy,
setPersistResponses,
testStore
};
}
示例10:
import { EffectsModule } from '@ngrx/effects';
import { AppPlayerEffects } from './app-player.effects';
import { NowPlaylistEffects } from './now-playlist.effects';
import { UserProfileEffects } from './user-profile.effects';
import { PlayerSearchEffects } from './player-search.effects';
import { AppSettingsEffects } from './app-settings.effects';
import { RouterEffects } from './router.effects';
export const AppEffectsModules = EffectsModule.forRoot([
AppPlayerEffects,
NowPlaylistEffects,
UserProfileEffects,
PlayerSearchEffects,
AppSettingsEffects,
RouterEffects
]);