本文整理汇总了TypeScript中underscore.isEmpty函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isEmpty函数的具体用法?TypeScript isEmpty怎么用?TypeScript isEmpty使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isEmpty函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
watcher.on(actions.checkForGameUpdates, async (store, action) => {
reschedule(store);
if (!store.getState().setup.done) {
return;
}
store.dispatch(
actions.gameUpdateCheckStatus({
checking: true,
progress: 0,
})
);
try {
store.dispatch(
actions.gameUpdateCheckStatus({
checking: true,
progress: 0,
})
);
const res = await mcall(messages.CheckUpdate, {}, convo => {
hookLogging(convo, logger);
convo.on(messages.GameUpdateAvailable, async ({ update }) => {
store.dispatch(actions.gameUpdateAvailable({ update }));
});
convo.on(messages.Progress, async ({ progress }) => {
store.dispatch(
actions.gameUpdateCheckStatus({
checking: true,
progress,
})
);
});
});
if (!isEmpty(res.updates)) {
for (const update of res.updates) {
store.dispatch(actions.gameUpdateAvailable({ update }));
}
}
if (!isEmpty(res.warnings)) {
logger.warn(`Got warnings when checking for updates: `);
for (const w of res.warnings) {
logger.warn(w);
}
}
} finally {
store.dispatch(
actions.gameUpdateCheckStatus({
checking: false,
progress: -1,
})
);
}
});
示例2: 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 }],
})
);
}
}
示例3: hasSearchResults
export function hasSearchResults(sr: ISearchResults): boolean {
if (sr && sr.games && !isEmpty(sr.games.ids)) {
return true;
}
if (sr && sr.users && !isEmpty(sr.users.ids)) {
return true;
}
return false;
}
示例4: concatTemplates
export function concatTemplates(
a: IMenuTemplate,
b: IMenuTemplate
): IMenuTemplate {
if (isEmpty(a)) {
return b;
}
if (isEmpty(b)) {
return a;
}
return [...a, { type: "separator" }, ...b];
}
示例5: getFromAdapters
async function getFromAdapters(): Promise<DimData | undefined> {
for (const adapter of adapters.slice().reverse()) {
if (adapter.enabled) {
if ($featureFlags.debugSync) {
console.log('getting from ', adapter.name);
}
try {
const value = await adapter.get();
if (value && !_.isEmpty(value)) {
if ($featureFlags.debugSync) {
console.log('got', value, 'from adapter ', adapter.name);
}
return value;
}
} catch (e) {
console.error('Sync: Error loading from', adapter.name, e);
reportException('Sync Load', e);
}
} else if ($featureFlags.debugSync) {
console.log(adapter.name, 'is disabled');
}
}
return undefined;
}
示例6: work
async work(): Promise<void> {
const installLocationId = this.space().firstPathElement();
let call = withLogger(this.logger);
const { caves, installLocationPath, installLocationSize } = await call(
messages.FetchCavesByInstallLocationID,
{ installLocationId }
);
let games: Game[] = [];
if (!isEmpty(caves)) {
for (const c of caves) {
games.push(c.game);
}
games = uniq(games, g => g.id);
}
this.pushUnfilteredGames(games, { disableFilters: true });
this.push({
location: {
path: installLocationPath,
size: installLocationSize,
},
});
}
示例7: countCurrencies
/**
* Calculates a count of how many of each type of currency you
* have on all characters, limited to only currencies required to
* buy items from the provided vendors.
*/
function countCurrencies(stores: D1Store[], vendors: { [vendorHash: number]: Vendor }) {
if (!stores || !vendors || !stores.length || _.isEmpty(vendors)) {
return {};
}
const categories = flatMap(Object.values(vendors), (v) => v.categories);
const saleItems = flatMap(categories, (c) => c.saleItems);
const costs = flatMap(saleItems, (i: any) => i.costs);
const currencies = costs.map((c: any) => c.currency.itemHash);
const totalCoins: { [currencyHash: number]: number } = {};
currencies.forEach((currencyHash) => {
// Legendary marks and glimmer are special cases
switch (currencyHash) {
case 2534352370:
totalCoins[currencyHash] = D1StoresService.getVault()!.legendaryMarks;
break;
case 3159615086:
totalCoins[currencyHash] = D1StoresService.getVault()!.glimmer;
break;
case 2749350776:
totalCoins[currencyHash] = D1StoresService.getVault()!.silver;
break;
default:
totalCoins[currencyHash] = sum(stores, (store) => {
return store.amountOfItem({ hash: currencyHash } as any);
});
break;
}
});
return totalCoins;
}
示例8: validateRequest
// res: Response where to send error HTTP message if the request is invalid
// requestBody: req.body OR req.query
// constraints: validate.js format
// return true if the request is valid
static validateRequest(res: Response,
requestBody: any,
constraints: any): boolean {
console.log(requestBody);
if (_.isEmpty(requestBody)) {
APIHelper.sendEmptyRequestResponse(res);
return false;
}
let validation = validate(requestBody, constraints);
console.log(requestBody);
if (_.keys(validation).length > 0) {
let validationErrors = {};
for (let prop in validation) {
if (!validation.hasOwnProperty(prop)) {
continue;
}
validationErrors[prop] = validation[prop];
}
APIHelper.sendInvalidInputResponse(res, validationErrors);
return false;
} else {
return true;
}
}
示例9: on
on(actions.searchHighlightOffset, (state, action) => {
const { offset, relative } = action.payload;
let highlight = offset;
if (relative) {
highlight = state.highlight + offset;
}
let numGames = 0;
if (
state.results &&
state.results.games &&
!isEmpty(state.results.games.ids)
) {
numGames = state.results.games.ids.length;
}
if (highlight < 0) {
highlight = numGames - 1;
}
if (highlight >= numGames) {
highlight = 0;
}
return {
...state,
highlight,
};
});