本文整理汇总了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);
}
});
示例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;
}