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


TypeScript vuex.Store類代碼示例

本文整理匯總了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;未經允許,請勿轉載。