本文整理汇总了TypeScript中@ngxs/store.Store.select方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Store.select方法的具体用法?TypeScript Store.select怎么用?TypeScript Store.select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ngxs/store.Store
的用法示例。
在下文中一共展示了Store.select方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ngOnInit
ngOnInit() {
this.store.select(UiState.currentPage).subscribe(currentPage => {
this.currentPage = currentPage;
});
this.store.select(UiState.currentLayer).subscribe(currentLayer => {
if (this.ref) {
this.ref.selectDomNode(currentLayer);
}
});
}
示例2: ngxsOnInit
ngxsOnInit({ dispatch }: StateContext<ShopProductsModel>) {
concat(
this.stateService.getInitialState('', 'products').pipe(take(1)),
/* LOGIN: */
this.store$.select(UserState.isLoggedIn).pipe(
pairwise(),
filter(([wasLoggedIn, isLoggedIn]) => !wasLoggedIn && isLoggedIn),
switchMap(() => this.stateService.getInitialState('', 'products').pipe(take(1)))
)
).subscribe((products) => {
dispatch(new InitShopProductsAction(products));
});
// Update products from server on entry update (name, attribute, instock, reservations)
this.actions$.pipe(
ofActionSuccessful(UpdateSectionEntryFromSyncAction),
filter(action => {
const actions = ['cartTitle', 'cartPrice', 'cartAttributes'];
const prop = action.path.split('/').pop();
return actions.indexOf(prop) > -1;
}),
switchMap(() => this.stateService.getInitialState('', 'products', true).pipe(take(1)))
).subscribe((products) => {
dispatch(new InitShopProductsAction(products));
});
}
示例3: ngOnInit
ngOnInit() {
this.store.select(UiState.currentLayer).subscribe(currentLayer => {
this.currentLayer = currentLayer;
if (currentLayer) {
this.focusOnTreeNode(currentLayer);
} else {
this.treeControl.collapseAll();
}
});
}
示例4: ngxsOnInit
ngxsOnInit() {
this.store.select(ErrorState.getLastError)
.pipe(filter(lastError => !!lastError))
.subscribe((lastError: ErrorStateModel) => {
this.popupService.showPopup({
type: 'error',
content: (lastError.httpStatus ? `${lastError.httpStatus}: ` : '') + lastError.message,
timeout: 3000
});
});
}
示例5: ngOnInit
ngOnInit() {
this.store.select(UiState.currentLayer).subscribe(currentLayer => {
if (currentLayer) {
this.componentStyle = (currentLayer as any).css as LayerCSS;
this.computeBackgourndGradient();
} else {
this.componentStyle = null;
this.gradients = [];
}
});
}
示例6: constructor
constructor(private store: Store) {
this.treeFlattener = new MatTreeFlattener(this.transformer, this.getLevel, this.isExpandable, this.getChildren);
this.treeControl = new FlatTreeControl<FileFlatNode>(this.getLevel, this.isExpandable);
this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
this.store.select(UiState.currentPage).subscribe(currentPage => {
if (currentPage) {
this.dataSource.data = currentPage.layers;
}
});
}
示例7: ngxsOnInit
ngxsOnInit({ dispatch }: StateContext<ShopRegionalCostsModel>) {
return concat(
this.stateService.getInitialState('', 'regionalCosts').pipe(take(1)),
/* LOGIN: */
this.store$.select(UserState.isLoggedIn).pipe(
pairwise(),
filter(([wasLoggedIn, isLoggedIn]) => !wasLoggedIn && isLoggedIn),
switchMap(() => this.stateService.getInitialState('', 'regionalCosts').pipe(take(1)))
)
).subscribe((regionalCosts) => {
dispatch(new InitShopRegionalCostsAction(regionalCosts));
});
}
示例8: canActivate
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean> {
return this.store.select(s => s.environement).pipe(
map(env => env.uid),
map(uid => !!uid),
tap(hasUid => {
if (!hasUid) {
this.router.navigate(['/main/caption']);
}
})
);
}
示例9: changePassword
changePassword(oldPassword, newPassword) {
return this.store.select(UserState).pipe(
filter(user => !!user.token),
take(1),
switchMap(user => {
return this.http.patch('/_api/v1/user/changepassword', {
old_password: oldPassword,
new_password: newPassword,
retype_password: newPassword,
},
{
headers: { 'X-Authorization': 'Bearer ' + user.token }
}
);
})
);
}
示例10: ngxsOnInit
ngxsOnInit({ dispatch }: StateContext<ShopSettingsModel>) {
return concat(
this.stateService.getInitialState('', 'settings').pipe(take(1)),
/* LOGIN: */
this.store$.select(UserState.isLoggedIn).pipe(
pairwise(),
filter(([wasLoggedIn, isLoggedIn]) => !wasLoggedIn && isLoggedIn),
switchMap(() => this.stateService.getInitialState('', 'settings').pipe(take(1)))
)
).subscribe((settings) => {
const newState: {[k: string]: any} = {};
for (const siteSlug in settings) {
newState[siteSlug] = this.initializeShopSettingsForSite(settings[siteSlug]);
}
dispatch(new InitShopSettingsAction(newState));
});
}