本文整理汇总了TypeScript中@ngxs/store.Store.selectSnapshot方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Store.selectSnapshot方法的具体用法?TypeScript Store.selectSnapshot怎么用?TypeScript Store.selectSnapshot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ngxs/store.Store
的用法示例。
在下文中一共展示了Store.selectSnapshot方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateShopRegion
@Action(UpdateShopRegionAction)
updateShopRegion({getState, patchState}: StateContext<ShopRegionalCostsModel>, action: UpdateShopRegionAction) {
const state = getState();
const site = this.store$.selectSnapshot(AppState.getSite);
const syncURLs = this.store$.selectSnapshot(ShopState.getURLs);
return this.appStateService.sync(syncURLs.regions, {
path: `${site}/${action.id}/${action.payload.field}`,
value: action.payload.value
}, 'PATCH').pipe(
tap((response: {message: string, data: any}) => {
patchState({[site]: state[site].map(region => {
if (region.id !== action.id) {
return region;
}
return {...region, [action.payload.field]: response.data.value};
})});
}),
catchError((error: HttpErrorResponse|Error) => {
if (error instanceof HttpErrorResponse) {
console.error(error.error.message);
} else {
console.error(error.message);
}
throw error;
})
);
}
示例2: updateShopProduct
@Action(UpdateShopProductAction)
updateShopProduct({ getState, patchState }: StateContext<ShopProductsModel>, action: UpdateShopProductAction) {
const currentSite = this.store$.selectSnapshot(AppState.getSite);
const syncURLs = this.store$.selectSnapshot(ShopState.getURLs);
const state = getState();
return this.appStateService.sync(syncURLs.products, {
path: `${currentSite}/${action.id}/${action.payload.field}`,
value: action.payload.value
}, 'PATCH').pipe(
tap(response => {
patchState({
[currentSite]: state[currentSite].map(product => {
if (product.id !== action.id) {
return product;
}
return {
... product,
[action.payload.field]: response.data.value
};
})
});
}),
catchError((error: HttpErrorResponse|Error) => {
if (error instanceof HttpErrorResponse) {
console.error(error.error.message);
} else {
console.error(error.message);
}
throw error;
})
);
}
示例3: addShopRegionalCost
@Action(AddShopRegionCostAction)
addShopRegionalCost({getState, patchState}: StateContext<ShopRegionalCostsModel>, action: AddShopRegionCostAction) {
const state = getState();
const site = this.store$.selectSnapshot(AppState.getSite);
const syncURLs = this.store$.selectSnapshot(ShopState.getURLs);
return this.appStateService.sync(syncURLs.regionalCosts, {
site: site,
data: { id_region: action.regionId, ...action.payload }
}, 'POST').pipe(
tap((response: {message: string, data: any}) => {
patchState({[site]: state[site].map(region => {
if (region.id !== action.regionId) {
return region;
}
return {...region, costs: [...region.costs, {
id: response.data.data.id,
weight: response.data.data.weight,
price: response.data.data.price
}]};
})});
}),
catchError((error: HttpErrorResponse|Error) => {
if (error instanceof HttpErrorResponse) {
console.error(error.error.message);
} else {
console.error(error.message);
}
throw error;
})
);
}
示例4: deleteShopRegionalCost
@Action(DeleteShopRegionCostAction)
deleteShopRegionalCost({getState, patchState}: StateContext<ShopRegionalCostsModel>, action: DeleteShopRegionCostAction) {
const state = getState();
const site = this.store$.selectSnapshot(AppState.getSite);
const syncURLs = this.store$.selectSnapshot(ShopState.getURLs);
return this.appStateService.sync(syncURLs.regionalCosts + `/${(site || 0)}/${action.payload.id}`, {}, 'DELETE').pipe(
tap(() => {
patchState({[site]: state[site].map(region => {
if (region.id !== action.regionId) {
return region;
}
return {
...region,
costs: region.costs.filter(cost => {
/** @todo: make sure state holds correct value types */
return +cost.id !== +action.payload.id;
})
};
})});
}),
catchError((error: HttpErrorResponse|Error) => {
if (error instanceof HttpErrorResponse) {
console.error(error.error.message);
} else {
console.error(error.message);
}
throw error;
})
);
}
示例5: addShopRegion
@Action(AddShopRegionAction)
addShopRegion({getState, patchState}: StateContext<ShopRegionalCostsModel>, action: AddShopRegionAction) {
const state = getState();
const site = this.store$.selectSnapshot(AppState.getSite);
const syncURLs = this.store$.selectSnapshot(ShopState.getURLs);
return this.appStateService.sync(syncURLs.regions, {
site: site,
data: {vat: 0, ...action.payload}
}, 'POST').pipe(
tap((response: {message: string, data: any}) => {
patchState({[site]: [...state[site], {
id: +response.data.data.id,
name: response.data.data.name,
vat: +response.data.data.vat,
costs: []
}]});
}),
catchError((error: HttpErrorResponse|Error) => {
if (error instanceof HttpErrorResponse) {
console.error(error.error.message);
} else {
console.error(error.message);
}
throw error;
})
);
}
示例6: updateShopSettings
@Action(UpdateShopSettingsAction)
updateShopSettings({getState, patchState}: StateContext<ShopSettingsModel>, action: UpdateShopSettingsAction) {
const state = getState();
const site = this.store$.selectSnapshot(AppState.getSite);
const syncURLs = this.store$.selectSnapshot(ShopState.getURLs);
return this.appStateService.sync(syncURLs.settings, {
path: `${site}/${action.groupSlug}/${action.payload.field}`,
value: action.payload.value
}, 'PATCH').pipe(
tap(response => {
patchState({
[site]: state[site].map(settingGroup => {
if (settingGroup.slug !== action.groupSlug) {
return settingGroup;
}
return {...settingGroup, settings: settingGroup.settings.map(setting => {
if (setting.slug !== action.payload.field) {
return setting;
}
return {...setting, value: response.data.value};
})};
})
});
}),
catchError((error: HttpErrorResponse|Error) => {
if (error instanceof HttpErrorResponse) {
console.error(error.error.message);
} else {
console.error(error.message);
}
throw error;
})
);
}
示例7: updateSiteTemplateSettings
@Action(UpdateSiteTemplateSettingsAction)
updateSiteTemplateSettings({ patchState, getState }: StateContext<SitesTemplateSettingsStateModel>,
action: UpdateSiteTemplateSettingsAction) {
const currentSite = this.store.selectSnapshot(AppState.getSite);
const currentSiteTemplate = this.store.selectSnapshot(SiteSettingsState.getCurrentSiteTemplate);
const settingKey = Object.keys(action.payload)[0];
const data = {
path: currentSite + '/site_template_settings/' + currentSiteTemplate + '/' + action.settingGroup + '/' + settingKey,
value: action.payload[settingKey]
};
const url = currentSiteTemplate + '/' + action.settingGroup + '/' + settingKey;
const fileUpload$ = data.value instanceof File ?
this.fileUploadService.upload(url, data.value).pipe(
map(fileUpload => ({ ...data, value: fileUpload['filename'] })))
:
of(data);
return fileUpload$.pipe(
switchMap(syncData => this.appStateService.sync('siteTemplateSettings', syncData)),
tap(response => {
if (response.error_message) {
// @TODO handle error message
console.error(response.error_message);
} else {
const currentState = getState();
patchState({
[currentSite]: {
...currentState[currentSite],
[currentSiteTemplate]: currentState[currentSite][currentSiteTemplate].map(settingGroup => {
if (settingGroup.slug !== action.settingGroup) {
return settingGroup;
}
return {
...settingGroup,
settings: settingGroup.settings.map(setting => {
if (setting.slug !== settingKey) {
return setting;
}
return { ...setting, value: response.value };
})
};
})
}
});
}
})
);
}
示例8: take
next: (state) => {
const currentSite = this.store.selectSnapshot(AppState.getSite);
const updatedSection = state.siteSections.find(section => {
return section.site_name === currentSite && section.order === sectionData.section.order;
});
this.route.queryParams.pipe(
take(1),
map(query => {
const obj = {};
if (query.section && query.section === sectionData.section.name) {
obj['query'] = {section: updatedSection.name};
}
if (this.currentSection === sectionData.section.name) {
obj['params'] = ['/sections', updatedSection.name];
}
return obj;
}),
filter(obj => !!Object.keys(obj).length)
).subscribe(obj => {
const route = 'params' in obj ? obj['params'] : [];
const qParams = 'query' in obj ? obj['query'] : {};
this.router.navigate(route, {replaceUrl: true, queryParams: qParams, queryParamsHandling: 'merge'});
});
},
示例9: map
map(() => {
const section = this.store.selectSnapshot(SiteSectionsState.getCurrentSiteSections)
.find(_section => _section.name === data.section);
const tags = this.store.selectSnapshot(SectionTagsState.getCurrentSiteTags)
.find(_section => _section['@attributes'].name === data.section);
return {
site_name: data.site,
section_name: data.section,
entry_id: data.entryId,
entry_count: section['@attributes'].entry_count,
section: section,
section_order: section.order,
has_direct_content: section['@attributes'].has_direct_content,
tags: tags
};
})
示例10: return
next: (state) => {
const currentSite = this.store.selectSnapshot(AppState.getSite);
const createdSection = state.siteSections
.filter(section => section.site_name === currentSite)
.reduce((prev, current) => {
return (prev.order > current.order) ? prev : current;
});
this.router.navigate(['/sections', createdSection.name], { queryParamsHandling: 'preserve' });
},