本文整理汇总了TypeScript中common/types.Store类的典型用法代码示例。如果您正苦于以下问题:TypeScript Store类的具体用法?TypeScript Store怎么用?TypeScript Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Store类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: dispatchUpdateNotification
function dispatchUpdateNotification(
store: Store,
cave: Cave,
result: CheckUpdateResult
) {
if (!result) {
return;
}
if (!isEmpty(result.warnings)) {
store.dispatch(
actions.statusMessage({
message: [
"status.game_update.check_failed",
{ err: result.warnings[0] },
],
})
);
return;
}
if (isEmpty(result.updates)) {
store.dispatch(
actions.statusMessage({
message: ["status.game_update.not_found", { title: cave.game.title }],
})
);
} else {
store.dispatch(
actions.statusMessage({
message: ["status.game_update.found", { title: cave.game.title }],
})
);
}
}
示例2: 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 }));
}
示例3: 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));
}
}
示例4: 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 })
);
}
}
示例5: 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,
});
}
示例6: mcall
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}`);
}
});
示例7: onMessage
private onMessage(logger: Logger, msg: ISM) {
if (msg.type === "no-update-available") {
this.stage("idle");
} else if (msg.type === "installing-update") {
this.stage("download");
} else if (msg.type === "update-failed") {
const pp = msg.payload as ISM_UpdateFailed;
logger.error(`Self-update failed: ${pp.message}`);
} else if (msg.type === "update-ready") {
const pp = msg.payload as ISM_UpdateReady;
logger.info(`Version ${pp.version} is ready to be used.`);
this.store.dispatch(
actions.packageNeedRestart({
name: this.name,
availableVersion: pp.version,
})
);
} else if (msg.type === "progress") {
const pp = msg.payload as ISM_Progress;
this.store.dispatch(
actions.packageProgress({
name: this.name,
progressInfo: pp,
})
);
} else if (msg.type === "log") {
const pp = msg.payload as ISM_Log;
logger.info(`> ${pp.message}`);
}
}
示例8: if
(ev: Electron.Event, input: Electron.Input) => {
if (input.type === "keyUp") {
if (input.key === "Enter") {
store.dispatch(actions.commandOk({ wind }));
} else if (input.key === "Escape") {
store.dispatch(actions.commandBack({ wind }));
}
}
}
示例9: 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,
})
);
}
示例10: async
onCancel: async () => {
store.dispatch(
actions.statusMessage({
message: ["status.installing_game.cancelled", { title: game.title }],
})
);
},