本文整理匯總了TypeScript中@ngrx/store.Store類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Store類的具體用法?TypeScript Store怎麽用?TypeScript Store使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Store類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor(private store$: Store<AppState>) {
this.counter$ = store$.select('counter');
}
示例2: constructor
constructor(private store: Store<any>) {
this.names = store.select('names');
}
示例3: hasHotelInStore
hasHotelInStore(id: number){
return this.store.let(hasHotel(id)).take(1);
}
示例4: describe
describe('EpisodesComponent', () => {
let component: EpisodesComponent;
let fixture: ComponentFixture<EpisodesComponent>;
let el: DebugElement;
let store: Store<PodcastState>;
let datePipe: DatePipe;
beforeEach(
async(() => {
TestBed.configureTestingModule({
declarations: [EpisodesComponent],
imports: [
MatListModule,
MatPaginatorModule,
RouterTestingModule.withRoutes([]),
StoreModule.forRoot({}),
StoreModule.forFeature('podcast', fromPodcast.reducer),
RouterTestingModule
],
}).compileComponents();
datePipe = new DatePipe('en-US');
})
);
beforeEach(async () => {
store = TestBed.get(Store);
spyOn(store, 'dispatch').and.callThrough();
});
beforeEach(async () => {
store.dispatch(new FindItemsByPodcastsAndPageSuccessAction(items));
fixture = TestBed.createComponent(EpisodesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
el = fixture.debugElement;
await fixture.whenStable();
});
it('should create', () => {
/* Given */
/* When */
/* Then */
expect(component).toBeTruthy();
});
it('should have coherent number of items', () => {
/* Given */
/* When */
const itemsElement = el.queryAll(By.css('[mat-list-item]'));
/* Then */
expect(itemsElement.length).toEqual(10);
});
it('should have each line with cover', () => {
/* Given */
const coversExpected = items.content.map(v => v.cover.url);
/* When */
const coversUrl = el.queryAll(By.css('img')).map(v => v.properties.src);
/* Then */
expect(coversExpected).toEqual(coversUrl);
});
it('should have each line with title', () => {
/* Given */
const titleExpected = items.content.map(v => v.title);
/* When */
const titles = el.queryAll(By.css('h3[matLine]')).map(asText);
/* Then */
expect(titleExpected).toEqual(titles);
});
it('should have each line with date', () => {
/* Given */
const dateExpected = items.content.map(v => v.pubDate).map(v => datePipe.transform(v, 'dd/MM/yyyy Ă HH:mm'));
/* When */
const dates = el.queryAll(By.css('p[matLine]')).map(asText);
/* Then */
expect(dateExpected).toEqual(dates);
});
function asText(v: DebugElement) {
return v.nativeElement.textContent.trim();
}
});
示例5: ngOnInit
ngOnInit() {
this.shoppingListState = this.store.select('shoppingList');
}
示例6:
this.usersService.getUsers().subscribe(users => {
this.users = users;
this.store.dispatch({type: INIT_USERS, payload: this.users});
});
示例7: ngOnInit
ngOnInit() {
this.isFetching$ = this.store.select(fromCustomer.getCustomersLoading);
this.customers$ = this.store.select(fromCustomer.getCustomers);
this.store.dispatch(new customerActions.LoadAction());
}
示例8: clearFlashMessage
clearFlashMessage() {
this.store.dispatch(new ClearFlashMessage())
}
示例9: toggle
toggle(node: TreeNode){
this._store.dispatch({type: TOGGLE_NODE, payload: node.name});
}
示例10:
.do(action => this.store.dispatch(action))