本文整理匯總了TypeScript中underscore.zip函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript zip函數的具體用法?TypeScript zip怎麽用?TypeScript zip使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了zip函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: convertJavaScriptToVariant
export function convertJavaScriptToVariant(
argumentDefinition: ArgumentOptions[],
values: any[]
): Variant[] {
assert(argumentDefinition.length === values.length);
assert(_.isArray(argumentDefinition));
assert(_.isArray(values));
return _.zip(values, argumentDefinition).map((pair: any) => {
pair = pair as [VariantLike, Argument];
const value = pair[0];
const arg = pair[1];
const variant = _.extend({}, arg);
variant.value = value;
return new Variant(variant);
});
}
示例2: loadProgress
async function loadProgress(account: DestinyAccount): Promise<ProgressProfile | undefined> {
try {
const defsPromise = getDefinitions();
const profileInfo = await getProgression(account);
const characterIds = Object.keys(profileInfo.characters.data);
let vendors: DestinyVendorsResponse[] = [];
try {
vendors = await Promise.all(
characterIds.map((characterId) => getVendors(account, characterId))
);
} catch (e) {
console.error('Failed to load vendors', e);
}
const defs = await defsPromise;
return {
defs,
profileInfo,
vendors: _.object(_.zip(characterIds, vendors)) as ProgressProfile['vendors'],
get lastPlayedDate() {
return Object.values((this.profileInfo as DestinyProfileResponse).characters.data).reduce(
(memo, character: DestinyCharacterComponent) => {
const d1 = new Date(character.dateLastPlayed);
return memo ? (d1 >= memo ? d1 : memo) : d1;
},
new Date(0)
);
}
};
} catch (e) {
toaster.pop(bungieErrorToaster(e));
console.error('Error loading progress', e);
reportException('progressService', e);
// It's important that we swallow all errors here - otherwise
// our observable will fail on the first error. We could work
// around that with some rxjs operators, but it's easier to
// just make this never fail.
return undefined;
} finally {
D2ManifestService.loaded = true;
}
}
示例3: callback
session.call(methodToCall, (err: Error | null, callResult?: CallMethodResult) => {
// istanbul ignore next
if (err) {
return callback(err);
}
callResult = callResult!;
if (callResult.statusCode !== StatusCodes.Good) {
return callback(new Error("Error " + callResult.statusCode.toString()));
}
callResult.outputArguments = callResult.outputArguments || [];
obj[name].outputArguments = obj[name].outputArguments || [];
if (callResult.outputArguments.length !== obj[name].outputArguments.length) {
return callback(new Error("Internal error callResult.outputArguments.length "
+ callResult.outputArguments.length + " " + obj[name].outputArguments.length));
}
const outputArgs: any = {};
const outputArgsDef = obj[name].outputArguments;
_.zip(outputArgsDef, callResult.outputArguments).forEach((pair: any) => {
const arg = pair[0];
const variant = pair[1];
const propName = lowerFirstLetter(arg.name);
outputArgs[propName] = variant.value;
});
callback(err, outputArgs);
});
示例4: queuedAction
export const distribute = queuedAction((actionableItem: DimItem) => {
// Sort vault to the end
const stores = _.sortBy(actionableItem.getStoresService().getStores(), (s) => {
return s.id === 'vault' ? 2 : 1;
});
let total = 0;
const amounts = stores.map((store) => {
const amount = store.amountOfItem(actionableItem);
total += amount;
return amount;
});
const numTargets = stores.length - 1; // exclude the vault
let remainder = total % numTargets;
const targets = stores.map((_store, index) => {
if (index >= numTargets) {
return 0; // don't want any in the vault
}
const result = remainder > 0 ? Math.ceil(total / numTargets) : Math.floor(total / numTargets);
remainder--;
return result;
});
const deltas = _.zip(amounts, targets).map((pair) => {
return pair[1] - pair[0];
});
const vaultMoves: {
source: DimStore;
target: DimStore;
amount: number;
}[] = [];
const targetMoves: {
source: DimStore;
target: DimStore;
amount: number;
}[] = [];
const vaultIndex = stores.length - 1;
const vault = stores[vaultIndex];
deltas.forEach((delta, index) => {
if (delta < 0 && index !== vaultIndex) {
vaultMoves.push({
source: stores[index],
target: vault,
amount: -delta
});
} else if (delta > 0) {
targetMoves.push({
source: vault,
target: stores[index],
amount: delta
});
}
});
// All moves to vault in parallel, then all moves to targets in parallel
function applyMoves(moves) {
return $q.all(
moves.map((move) => {
const item = move.source.items.find((i) => i.hash === actionableItem.hash);
return dimItemService.moveTo(item, move.target, false, move.amount);
})
);
}
let promise: IPromise<any> = applyMoves(vaultMoves).then(() => {
return applyMoves(targetMoves);
});
promise = promise
.then(() => {
toaster.pop('success', t('ItemMove.Distributed', { name: actionableItem.name }));
})
.catch((a) => {
toaster.pop('error', actionableItem.name, a.message);
console.log('error distributing', actionableItem, a);
});
loadingTracker.addPromise(promise);
return promise;
});
示例5: exploreDataTypeDefinition
export async function exploreDataTypeDefinition(
session: IBasicSession,
dataTypeDictionaryTypeNode: NodeId,
typeDictionary: TypeDictionary,
namespaces: string[]
) {
const nodeToBrowse = {
browseDirection: BrowseDirection.Forward,
includeSubtypes: false,
nodeClassMask: makeNodeClassMask("Variable"),
nodeId: dataTypeDictionaryTypeNode,
referenceTypeId: resolveNodeId("HasComponent"),
resultMask: makeResultMask("ReferenceType | IsForward | BrowseName | NodeClass | TypeDefinition")
};
const result = await session.browse(nodeToBrowse);
const references = result.references || [];
/* istanbul ignore next */
if (references.length === 0) {
return;
}
// request the Definition of each not
const nodesToBrowse2 = references.map((ref: ReferenceDescription) => {
return {
browseDirection: BrowseDirection.Inverse,
includeSubtypes: false,
nodeClassMask: makeNodeClassMask("Object | Variable"),
nodeId: ref.nodeId,
referenceTypeId: resolveNodeId("HasDescription"),
resultMask: makeResultMask("NodeId | ReferenceType | BrowseName | NodeClass | TypeDefinition")
};
});
const results2 = await session.browse(nodesToBrowse2);
const binaryEncodingNodeIds = results2.map((br: BrowseResult) => {
const defaultBin = br.references!.filter((r: ReferenceDescription) => r.browseName.toString() === "Default Binary");
/* istanbul ignore next */
if (defaultBin.length < 1) {
return ExpandedNodeId;
}
return ExpandedNodeId.fromNodeId(defaultBin[0].nodeId, namespaces[defaultBin[0].nodeId.namespace]);
});
const tuples = _.zip(references, binaryEncodingNodeIds);
for (const [ref, defaultBinary] of tuples) {
const name = ref.browseName!.name!.toString();
const constructor = getOrCreateConstructor(name, typeDictionary, defaultBinary);
/* istanbul ignore next */
if (doDebug) {
try {
const testObject = new constructor();
debugLog(testObject.toString());
} catch (err) {
debugLog(err.message);
}
}
}
}