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


TypeScript Store.getState方法代码示例

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


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

示例1: t

  nativeWindow.on("close", (e: any) => {
    const rs = store.getState();
    if (wind === "root") {
      const prefs =
        rs.preferences || ({ closeToTray: true } as PreferencesState);

      let { closeToTray } = prefs;
      if (rs.system.macos) {
        closeToTray = true;
      }
      if (env.integrationTests) {
        // always let app close in testing
        closeToTray = false;
      }

      if (store.getState().system.quitting) {
        logger.debug("On window.close: quitting, letting it close");
        return;
      }
      if (closeToTray) {
        logger.debug("On window.close: close to tray enabled");
      } else {
        logger.debug("On window.close: close to tray disabled, quitting!");
        process.nextTick(() => {
          store.dispatch(actions.quit({}));
        });
        return;
      }

      // hide, never destroy
      e.preventDefault();
      nativeWindow.hide();

      if (!prefs.gotMinimizeNotification && !store.getState().system.macos) {
        store.dispatch(
          actions.updatePreferences({
            gotMinimizeNotification: true,
          })
        );

        const i18n = store.getState().i18n;
        store.dispatch(
          actions.notify({
            title: t(i18n, ["notification.see_you_soon.title"]),
            body: t(i18n, ["notification.see_you_soon.message"]),
          })
        );
      }
    } else {
      store.dispatch(actions.windClosed({ wind }));
    }
  });
开发者ID:itchio,项目名称:itch,代码行数:52,代码来源:winds.ts

示例2: updateCommonsNowThrows

async function updateCommonsNowThrows(store: Store) {
  if (!store.getState().setup.done) {
    return;
  }

  const { caves, downloadKeys, installLocations } = await mcall(
    messages.FetchCommons,
    {}
  );

  let locationSizes: { [key: string]: number } = {};
  if (!isEmpty(installLocations)) {
    for (const x of installLocations) {
      locationSizes[x.id] = x.sizeInfo.installedSize;
    }
  }

  push(store, {
    caves: indexBy(caves, "id"),
    caveIdsByGameId: groupIdBy(caves, "gameId"),
    downloadKeys: indexBy(downloadKeys, "id"),
    downloadKeyIdsByGameId: groupIdBy(downloadKeys, "gameId"),
    locationSizes,
  });
}
开发者ID:itchio,项目名称:itch,代码行数:25,代码来源:commons.ts

示例3: doAsync

      doAsync(async () => {
        try {
          const dkIdString = details.responseHeaders["X-Itch-Download-Key-Id"];
          const pIdString =
            details.responseHeaders["X-Itch-Download-Key-Owner-Id"];
          if (dkIdString && pIdString) {
            const downloadKeyId = parseInt(dkIdString, 10);
            const profileId = parseInt(pIdString, 10);
            const { downloadKeys } = store.getState().commons;

            logger.info(
              `Visiting download key page, has key ${downloadKeyId} (owner ${profileId})`
            );

            if (!downloadKeys[downloadKeyId]) {
              logger.info(`That's a new key, fetching...`);
              await mcall(messages.FetchDownloadKey, {
                downloadKeyId,
                profileId,
              });
              store.dispatch(actions.ownedKeysFetched({}));
            }
          }
        } catch (e) {
          logger.warn(`While sniffing headers: ${e.stack}`);
        }
      });
开发者ID:itchio,项目名称:itch,代码行数:27,代码来源:register-itch-protocol.ts

示例4: convertTemplate

function convertTemplate(
  store: Store,
  template: MenuItem[]
): MenuItemConstructorOptions[] {
  const rs = store.getState();
  const { i18n } = rs;
  const result: MenuItemConstructorOptions[] = [];
  for (const item of template) {
    const opts: MenuItemConstructorOptions = {};
    if (item.localizedLabel) {
      opts.label = t(i18n, item.localizedLabel);
    }
    if (item.action) {
      opts.click = () => {
        store.dispatch(item.action);
      };
    }
    if (item.type) {
      opts.type = item.type;
    }
    if (item.submenu) {
      opts.submenu = convertTemplate(store, item.submenu);
    }
    if (item.accelerator) {
      opts.accelerator = item.accelerator;
    }
    result.push(opts);
  }
  return result;
}
开发者ID:itchio,项目名称:itch,代码行数:30,代码来源:context-menu.ts

示例5: saveTabs

export async function saveTabs(store: Store) {
  const rs = store.getState();
  const { navigation, tabInstances } = rs.winds["root"];
  const { profile } = rs.profile;
  if (!profile) {
    return;
  }
  const { tab, openTabs } = navigation;
  const profileId = profile.id;
  let items: TabDataSave[];
  items = map(openTabs, id => {
    const ti = tabInstances[id];
    if (!ti) {
      return null;
    }

    const sp = Space.fromInstance(id, ti);
    const { history, currentIndex } = ti;
    const savedLabel = sp.label();
    return { id, history, currentIndex, savedLabel };
  });
  items = filter(items, x => !!x);

  const snapshot: Snapshot = { current: tab, items };

  await mcall(messages.ProfileDataPut, {
    profileId,
    key: "@itch/tabs",
    value: JSON.stringify(snapshot),
  });
}
开发者ID:itchio,项目名称:itch,代码行数:31,代码来源:tab-save.ts

示例6: ensure

 async ensure(opts: EnsureOpts) {
   const rs = this.store.getState();
   this.store.dispatch(
     actions.packageGotVersionPrefix({
       name: this.name,
       version: rs.system.appVersion,
       versionPrefix: rs.system.userDataPath,
     })
   );
 }
开发者ID:itchio,项目名称:itch,代码行数:10,代码来源:self-package.ts

示例7: applyTabOffset

async function applyTabOffset(store: Store, wind: string, offset: number) {
  const { tab, openTabs } = store.getState().winds[wind].navigation;

  const numTabs = openTabs.length;
  const index = openTabs.indexOf(tab);

  // adding numPaths takes care of negative wrapping too!
  const newIndex = (index + offset + numTabs) % numTabs;
  const newTab = openTabs[newIndex];

  store.dispatch(actions.tabFocused({ wind, tab: newTab }));
}
开发者ID:itchio,项目名称:itch,代码行数:12,代码来源:tabs.ts

示例8: setTimeout

 setTimeout(() => {
   let endpointOnRestart = store.getState().butlerd.endpoint;
   if (endpointOnRestart === endpointAtCrash) {
     logger.warn(
       `Still no new butlerd endpoint 2s after butlerd instance ${id} threw, refreshing...`
     );
     refreshButlerd(store).catch(() => {});
   } else {
     logger.info(
       `Got a new endpoint after butlerd ${id} threw, all seems well.`
     );
   }
 }, 2000);
开发者ID:itchio,项目名称:itch,代码行数:13,代码来源:setup.ts

示例9: push

function push(store: Store, next: typeof actions.commonsUpdated.payload) {
  const prev = store.getState().commons;

  let hasDifferences = false;
  for (const k of Object.keys(next)) {
    if (!isEqual((prev as any)[k], (next as any)[k])) {
      hasDifferences = true;
      break;
    }
  }

  if (hasDifferences) {
    store.dispatch(actions.commonsUpdated(next));
  }
}
开发者ID:itchio,项目名称:itch,代码行数:15,代码来源:commons.ts

示例10: syncInstallLocations

async function syncInstallLocations(store: Store) {
  const { installLocations } = await mcall(messages.InstallLocationsList, {});
  const newLocationsById = indexBy(installLocations, "id");

  const { preferences } = store.getState();
  if (!preferences.importedOldInstallLocations) {
    await mkdirp(appdataLocationPath());
    let oldLocations = {
      ...preferences.installLocations,
      appdata: {
        id: "appdata",
        path: appdataLocationPath(),
      },
    } as { [key: string]: { id: string; path: string } };

    let numAdded = 0;
    if (!isEmpty(oldLocations)) {
      for (const id of Object.keys(oldLocations)) {
        logger.debug(`Checking install location ${id}...`);
        const oldLoc = oldLocations[id];
        const newLoc = newLocationsById[id];
        if (newLoc) {
          logger.debug(`Has on butler side too!`);
        } else {
          logger.debug(`Synchronizing ${id}...`);
          numAdded++;
          try {
            await mcall(messages.InstallLocationsAdd, {
              id,
              path: oldLoc.path,
            });
          } catch (e) {
            logger.warn(`Could not add ${oldLoc.path}: ${e.stack}`);
          }
        }
      }
    }

    if (numAdded > 0) {
      logger.info(`Registered ${numAdded} install locations with butler`);
    } else {
      logger.info(`All install locations synchronized with butler`);
    }
    store.dispatch(
      actions.updatePreferences({ importedOldInstallLocations: true })
    );
  }
}
开发者ID:itchio,项目名称:itch,代码行数:48,代码来源:setup.ts


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