• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript vuex.Store类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中vuex.Store的典型用法代码示例。如果您正苦于以下问题:TypeScript Store类的具体用法?TypeScript Store怎么用?TypeScript Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: async

  return async (store: Store<State>) => {
    const water: Partial<State> = {};
    for (const paths of Object.values(saveOn)) {
      for (const path of castArray(paths)) {
        const storedValue = storage.getItem(prefixKey(path));
        if (storedValue) {
          const parsedValue = JSON.parse(storedValue);
          set(water, path, parsedValue);
        }
      }
    }
    store.replaceState(merge({}, store.state, water));

    if (onLoad) await onLoad(store);

    store.subscribe(({ type }, state) => {
      if (hasOwn(saveOn, type)) {
        const paths = castArray(saveOn[type]);
        for (const [path, value] of zip(paths, at(state, paths))) {
          if (path === undefined) continue;
          const stringifiedValue = JSON.stringify(value);
          try {
            storage.setItem(prefixKey(path), stringifiedValue);
          } catch {
            // this can sometimes throw based on the spec
          }
        }
      }
    });
  };
开发者ID:Sulcata,项目名称:Sulcata-Damage-Calculator,代码行数:30,代码来源:plugins.ts


示例2: describe

describe('GinFooter', function () {
  let storeMocks: Store<any>;
  let wrapper;

  beforeEach(() => {
    // Create a fresh store and wrapper
    // instance for every test case.
    storeMocks = createStore();
    wrapper = shallow(GinFooter, {
      store: storeMocks,
      localVue,
    });
  });

  it('should render', ()=>{
    expect(wrapper.text()).toContain(new Date().getUTCFullYear());
  });


  it('should be offline', async ()=>{
    await storeMocks.dispatch('setOffline');

    expect(wrapper.text()).toContain("offline")
  })

});
开发者ID:pikax,项目名称:gincloud,代码行数:26,代码来源:GinFooter.spec.ts


示例3:

const localStoragePlugin: Plugin<RootState> = (store: Store<RootState>) => {
  store.subscribe((mutation: MutationPayload, { patch: { name }}) => {
    localStorage.setItem(_NAME, name);
  });
  
  store.subscribe((mutation: MutationPayload, { patch: { modules }}) => {
    localStorage.setItem(_MODULES, JSON.stringify(modules));
  });

  store.subscribe((mutation: MutationPayload, { patch: { connections }}) => {
    localStorage.setItem(_CONNECTIONS, JSON.stringify(connections));
  });

  store.subscribe((mutation: MutationPayload, { patch: { parameterSets }}) => {
    localStorage.setItem(_PARAMETERS, JSON.stringify(parameterSets));
  });

  store.subscribe((mutation: MutationPayload, { patch: { parameterKey }}) => {
    localStorage.setItem(_PARAMETER_KEY, parameterKey.toString());
  });

  store.subscribe((mutation: MutationPayload, { patch: { id }}) => {
    localStorage.setItem(_ID, id.toString());
  });

  store.subscribe((mutation: MutationPayload, { app: { patchKey }}) => {
    localStorage.setItem(_KEY, patchKey);
  });
};
开发者ID:apathetic,项目名称:modular-synth,代码行数:29,代码来源:plugins.ts


示例4:

const setDefaultState = (context: IServerContext, store: Store<IState>) => {
  let state: IState = store.state;
  state = PersistCookieStorage.getMergedStateFromServerContext<IState>(context, state);
  state.app.config = context.appConfig;

  if (state.app && state.app.locale) {
    context.acceptLanguage = state.app.locale;
    context.htmlLang = state.app.locale.substr(0, 2);
  } else {
    state.app.locale = context.acceptLanguage;
  }

  if (context.redirect === true) {
    state.app.redirectTo = context.url;
  }

  store.replaceState(state);
};
开发者ID:trungx,项目名称:vue-starter,代码行数:18,代码来源:isomorphic.ts


示例5: return

  return (vuexStore: Store<IState>) => {
    const hydratedState: IState = {} as IState;

    storages.forEach((storage: IVuexPersistStorage): void => {
      if (canWriteStorage(storage)) {
        processStorage(storage, hydratedState, vuexStore);
      }
    });

    const mergedState: IState = merge(vuexStore.state, hydratedState, {
      clone:      false,
      arrayMerge: (store, saved) => {
        return saved;
      },
    });

    vuexStore.replaceState(mergedState);
  };
开发者ID:trungx,项目名称:vue-starter,代码行数:18,代码来源:vuex-persist.ts


示例6:

    mutations
  };

  const nested = {
    state: nestedState,
    mutations,
    modules: { a, b }
  };

  const c = {
    state: cState,
    mutations
  };

  const store = new Vuex.Store<IModuleState>({
    modules: { nested, c }
  });

  const valA = store.state.nested.a.value;
  const valB = store.state.nested.b.value;
  const valC = store.state.c.value;
  const valNested = store.state.nested.value;
}

namespace TestPlugin {
  const a = (store: Vuex.Store<any>) => {};

  const b = (store: Vuex.Store<ISimpleState>) => {};

  new Vuex.Store<ISimpleState>({
    state: { count: 1 },
开发者ID:abc5213091,项目名称:vuex,代码行数:31,代码来源:index.ts


示例7: it

  it('should be offline', async ()=>{
    await storeMocks.dispatch('setOffline');




    expect(wrapper.text()).toContain("offline")





  })
开发者ID:pikax,项目名称:gincloud,代码行数:13,代码来源:GinFooter.mock.spec.ts


示例8: setRoute

 public static setRoute(route: IRouteConfigAugmented) {
   return store.dispatch('setRoute', route);
 }
开发者ID:remipassmoilesel,项目名称:personnal-website,代码行数:3,代码来源:store.ts


示例9: setTitle

 public static setTitle(title: string) {
   return store.dispatch('setTitle', title);
 }
开发者ID:remipassmoilesel,项目名称:personnal-website,代码行数:3,代码来源:store.ts


示例10:

ipcRenderer.on('game:exit', (event, {id}) => {
  console.log('game:exit')
  store.commit('process/onGameStop', {id})
})
开发者ID:bangbang93,项目名称:BMCLJS,代码行数:4,代码来源:index.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript vuex-router-sync.sync函数代码示例发布时间:2022-05-25
下一篇:
TypeScript vuex.mapState函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap