当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript StateContext.setState方法代码示例

本文整理汇总了TypeScript中@ngxs/store.StateContext.setState方法的典型用法代码示例。如果您正苦于以下问题:TypeScript StateContext.setState方法的具体用法?TypeScript StateContext.setState怎么用?TypeScript StateContext.setState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@ngxs/store.StateContext的用法示例。


在下文中一共展示了StateContext.setState方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: processUpdateEvent

 private processUpdateEvent(
   ctx: StateContext<SourceModel[]>,
   action: ObsDispatchEvent
 ) {
   const state = ctx.getState();
   switch (action.payload['update-type']) {
     case 'SwitchScenes':
       ctx.setState([...action.payload.sources]);
       ctx.dispatch(new GetSourceMuteState());
       break;
     case 'SceneItemVisibilityChanged':
       const newstate = state.map(x => {
         if (x.name === action.payload['item-name']) {
           x.render = action.payload['item-visible'];
         }
         return x;
       });
       ctx.setState([...newstate]);
       break;
     case 'SceneItemAdded':
     case 'SceneItemRemoved':
     case 'SourceOrderChanged':
       ctx.dispatch(new GetCurrentScene());
       break;
   }
 }
开发者ID:chgc,项目名称:stream-tools,代码行数:26,代码来源:source.state.ts

示例2: receiveEvent

 @Action(ObsDispatchEvent)
 receiveEvent(ctx: StateContext<SourceModel[]>, action: ObsDispatchEvent) {
   if (action.payload['update-type']) {
     this.processUpdateEvent(ctx, action);
     return;
   }
   const { id, actionType } = this.service.getActionType(action.payload);
   const state = ctx.getState();
   switch (actionType) {
     case 'GetSceneList':
       action.payload.scenes
         .filter(s => s.name === action.payload['current-scene'])
         .map(scene => ctx.setState([...scene.sources]));
       ctx.dispatch(new GetSourceMuteState());
       break;
     case 'GetCurrentScene':
       ctx.setState([...action.payload.sources]);
       ctx.dispatch(new GetSourceMuteState());
       break;
     case 'ToggleMute':
     case 'GetMute':
       const sources = state.map(source => {
         if (source.name === action.payload.name) {
           source.muted = action.payload.muted;
         }
         return source;
       });
       ctx.setState([...sources]);
       break;
   }
 }
开发者ID:chgc,项目名称:stream-tools,代码行数:31,代码来源:source.state.ts

示例3: gettDisplayUrl

 @Action(SetDisplayUrl)
 gettDisplayUrl(ctx: StateContext<CaptionPanelModel>, action: SetDisplayUrl) {
   const currentState = ctx.getState();
   ctx.setState({
     ...currentState,
     displayUrl: `${location.origin}/main/caption/display/${currentState.uid}`
   });
 }
开发者ID:chgc,项目名称:stream-tools,代码行数:8,代码来源:environment.state.ts

示例4: getCategories

  @Action(GetCategoryAction)
  async getCategories(ctx: StateContext<CategoryStateModel>, action: GetCategoryAction) {
    let categories = await this.categoryService.getCategories();

    ctx.setState({
      categories
    });
  }
开发者ID:Talalaev,项目名称:momonga,代码行数:8,代码来源:category.state.ts

示例5: logout

 @Action(LogoutAction)
 logout(ctx: StateContext<SessionStateModel>) {
     if (ctx.getState().state === 'authenticated') {
         ctx.setState(defaultSessionState);
         localStorage.setItem('session', JSON.stringify(defaultSessionState));
         this.store.dispatch(new HideSideNavAction());
         this.store.dispatch(new Navigate(['/']));
     }
 }
开发者ID:strongbox,项目名称:strongbox-web-ui,代码行数:9,代码来源:session.state.ts

示例6: addPurchase

  @Action(AddPurchaseAction)
  async addPurchase(ctx: StateContext<PurchaseStateModel>, action: AddPurchaseAction) {
    let purchase: Purchase = await this.purchaseService.add(action.purchase);

    const state = ctx.getState();
    ctx.setState({
      ...state,
      purchases: [action.purchase]
    });
  }
开发者ID:Talalaev,项目名称:momonga,代码行数:10,代码来源:purchase.state.ts

示例7: getPurchase

  @Action(GetPurchaseAction)
  async getPurchase(ctx: StateContext<PurchaseStateModel>, action: GetPurchaseAction) {
    let purchases: Array<Purchase> = await this.purchaseService.getPurchase(action.date);

    const state = ctx.getState();
    ctx.setState({
      ...state,
      purchases
    });
  }
开发者ID:Talalaev,项目名称:momonga,代码行数:10,代码来源:purchase.state.ts

示例8: setAuthUser

  @Action(SetAuthUser)
  async setAuthUser(ctx: StateContext<AuthStateModel>) {
    const user: any = await this.authService.getAuthUser();

    const state = ctx.getState();
    ctx.setState({
      ...state,
      user,
      isAuth: Boolean(user)
    });
  }
开发者ID:Talalaev,项目名称:momonga,代码行数:11,代码来源:auth.state.ts

示例9: loguot

  @Action(LogoutAction)
  async loguot(ctx: StateContext<AuthStateModel>) {
    await this.authService.logout();

    const state = ctx.getState();
    ctx.setState({
      ...state,
      user: null,
      isAuth: false
    });
  }
开发者ID:Talalaev,项目名称:momonga,代码行数:11,代码来源:auth.state.ts

示例10: registration

  @Action(RegistrationAction)
  async registration(ctx: StateContext<AuthStateModel>, action: RegistrationAction) {
    const data: {user: any, token: string} = await this.authService.registration(action.user);

    const state = ctx.getState();
    ctx.setState({
      ...state,
      user: data.user,
      isAuth: true
    });
  }
开发者ID:Talalaev,项目名称:momonga,代码行数:11,代码来源:auth.state.ts


注:本文中的@ngxs/store.StateContext.setState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。