本文整理汇总了TypeScript中common/util/lru-memoize.memoize函数的典型用法代码示例。如果您正苦于以下问题:TypeScript memoize函数的具体用法?TypeScript memoize怎么用?TypeScript memoize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了memoize函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: memoize
import { IDownloadsState } from "common/types";
import { first, filter, sortBy } from "underscore";
import { memoize } from "common/util/lru-memoize";
import { Download } from "common/butlerd/messages";
export const getActiveDownload = memoize(1, function(
downloads: IDownloadsState
): Download {
return first(getPendingDownloads(downloads));
});
export const getPendingDownloads = memoize(1, function(
downloads: IDownloadsState
): Download[] {
const pending = filter(downloads.items, i => !i.finishedAt);
return sortBy(pending, "position");
});
export const getFinishedDownloads = memoize(1, function(
downloads: IDownloadsState
): Download[] {
const pending = filter(downloads.items, i => !!i.finishedAt);
return sortBy(pending, "finishedAt").reverse();
});
export function getPendingForGame(
downloads: IDownloadsState,
gameId: number
): Download[] {
return filter(
示例2: memoize
import { IStore, IRootState, II18nState, IMenuTemplate } from "common/types";
import { fleshOutTemplate } from "./context-menu/flesh-out-template";
import { currentRuntime } from "main/os/runtime";
import { memoize } from "common/util/lru-memoize";
const setTrayMenu = memoize(1, function(
template: IMenuTemplate,
store: IStore
) {
const fleshedOut = fleshOutTemplate(
"root",
store,
currentRuntime(),
template
);
const menu = Menu.buildFromTemplate(fleshedOut);
if (os.platform() === "darwin") {
// don't have a tray icon on macOS, we just live in the dock
app.dock.setMenu(menu);
} else {
getTray(store).setContextMenu(menu);
}
});
async function go(store: IStore, url: string) {
// TODO: should navigate focus the window anyway ?
store.dispatch(actions.focusWindow({ window: "root" }));
store.dispatch(actions.navigate({ window: "root", url }));
}
示例3: isPlatformCompatible
progress: null,
eta: null,
bps: null,
stage: null,
};
operation = {
type: OperationType.Download,
id: download.id,
reason: download.reason,
active: isDownloadActive,
paused: areDownloadsPaused,
progress: p.progress,
eta: p.eta,
bps: p.bps,
stage: p.stage,
};
}
const compatible = isPlatformCompatible(game);
return {
cave,
numCaves,
downloadKey,
access,
operation,
update,
compatible,
};
}
const realGetGameStatus = memoize(300, rawGetGameStatus);
示例4: memoize
import { Task, TasksState } from "common/types";
import { first, values } from "underscore";
import { memoize } from "common/util/lru-memoize";
export const getActiveTask = memoize(1, function(tasks: TasksState): Task {
return first(getRunningTasks(tasks));
});
export const getRunningTasks = memoize(1, function(tasks: TasksState): Task[] {
return values(tasks.tasks);
});