當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Store.selectSnapshot方法代碼示例

本文整理匯總了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;
      })
    );
  }
開發者ID:berta-cms,項目名稱:berta,代碼行數:28,代碼來源:shop-regional-costs.state.ts

示例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;
      })
    );
  }
開發者ID:berta-cms,項目名稱:berta,代碼行數:33,代碼來源:shop-products.state.ts

示例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;
      })
    );
  }
開發者ID:berta-cms,項目名稱:berta,代碼行數:33,代碼來源:shop-regional-costs.state.ts

示例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;
      })
    );
  }
開發者ID:berta-cms,項目名稱:berta,代碼行數:31,代碼來源:shop-regional-costs.state.ts

示例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;
      })
    );
  }
開發者ID:berta-cms,項目名稱:berta,代碼行數:28,代碼來源:shop-regional-costs.state.ts

示例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;
      })
    );
  }
開發者ID:berta-cms,項目名稱:berta,代碼行數:35,代碼來源:shop-settings.state.ts

示例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 };
                  })
                };
              })
            }
          });
        }
      })
    );
  }
開發者ID:berta-cms,項目名稱:berta,代碼行數:52,代碼來源:site-template-settings.state.ts

示例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'});
            });
          },
開發者ID:berta-cms,項目名稱:berta,代碼行數:29,代碼來源:site-sections.component.ts

示例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
                };
              })
開發者ID:berta-cms,項目名稱:berta,代碼行數:17,代碼來源:preview.service.ts

示例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' });
 },
開發者ID:berta-cms,項目名稱:berta,代碼行數:9,代碼來源:site-sections.component.ts


注:本文中的@ngxs/store.Store.selectSnapshot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。