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


TypeScript Space.fromState方法代码示例

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


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

示例1: withWebContents

    withWebContents(store, wind, tab, wc => {
      let offset = index - oldIndex;
      const url = rs.winds[wind].tabInstances[tab].history[index].url;
      if (
        wc.canGoToOffset(offset) &&
        wc.history[wc.currentIndex + offset] === url
      ) {
        logger.debug(`\n`);
        logger.debug(`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`);
        logger.debug(
          `For index ${oldIndex} => ${index}, applying offset ${offset}`
        );
        logger.debug(`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n`);
        wc.goToOffset(offset);
      } else {
        const url = Space.fromState(rs, wind, tab).url();
        logger.debug(`\n`);
        logger.debug(`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`);
        logger.debug(
          `For index ${oldIndex} => ${index}, clearing history and loading ${url}`
        );
        logger.debug(`(could go to offset? ${wc.canGoToOffset(offset)})`);
        logger.debug(`(wcl = ${wc.history[wc.currentIndex + offset]})`);
        logger.debug(`(url = ${url})`);

        if (offset == 1) {
          logger.debug(
            `Wait, no, we're just going forward one, we don't need to clear history`
          );
        } else {
          wc.clearHistory();
        }
        logger.debug(`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n`);
        loadURL(wc, url);
      }
    });
开发者ID:itchio,项目名称:itch,代码行数:36,代码来源:web-contents.ts

示例2: sortAndFilter

export function sortAndFilter(
  games: Game[],
  window: string,
  tab: string,
  store: IStore,
  opts: ISortAndFilterOpts = {}
): Game[] {
  let set = games;
  const rs = store.getState();

  const sp = Space.fromState(rs, window, tab);
  const tabParams = sp.query() as ITabParams;
  const { sortBy, sortDirection = "DESC" } = tabParams;
  const prefs = rs.preferences;

  const hasFilters =
    prefs.onlyCompatibleGames ||
    prefs.onlyInstalledGames ||
    prefs.onlyOwnedGames;

  if (hasFilters && !opts.disableFilters) {
    const downloadSet = rs.downloads.itemIdsByGameId;
    const installedSet = rs.commons.caveIdsByGameId;
    const ownedSet = rs.commons.downloadKeyIdsByGameId;

    set = filter(set, g => {
      if (!g) {
        return false;
      }

      if (prefs.onlyCompatibleGames && !isPlatformCompatible(g)) {
        return false;
      }
      if (
        prefs.onlyInstalledGames &&
        !installedSet[g.id] &&
        !downloadSet[g.id]
      ) {
        return false;
      }
      if (prefs.onlyOwnedGames && !ownedSet[g.id]) {
        return false;
      }

      return true;
    });
  }

  if (sortBy) {
    switch (sortBy) {
      case "title":
        set = sortedBy(set, "title");
        break;
      case "publishedAt":
        set = sortedBy(set, "publishedAt");
        break;
      case "lastTouchedAt":
        set = sortedBy(set, g => {
          const cave = disambiguateCave(rs.commons, g);
          if (cave) {
            return cave.lastTouchedAt;
          } else {
            return 0;
          }
        });
        break;
      case "secondsRun":
        set = sortedBy(set, g => {
          const cave = disambiguateCave(rs.commons, g);
          if (cave) {
            return cave.secondsRun;
          } else {
            return 0;
          }
        });
        break;
      case "installedSize":
        set = sortedBy(set, g => {
          const cave = disambiguateCave(rs.commons, g);
          if (cave) {
            return cave.installedSize;
          } else {
            return 0;
          }
        });
        break;
      default:
      // don't sort if we don't know how to
    }

    if (sortDirection === "DESC") {
      set.reverse();
    }

    set = filter(set, x => !!x);
  }

  return set;
}
开发者ID:HorrerGames,项目名称:itch,代码行数:99,代码来源:sort-and-filter.ts


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