本文整理汇总了TypeScript中underscore.forEach函数的典型用法代码示例。如果您正苦于以下问题:TypeScript forEach函数的具体用法?TypeScript forEach怎么用?TypeScript forEach使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forEach函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getQuestExpValue
[config.SERVER_INNER.QUEST_COMPLETED.name]({questInfo, slots}: {questInfo: QUEST_MODEL, slots: AVAILABLE_SLOTS}, socket: GameSocket) {
socket.emit(config.CLIENT_GETS.QUEST_DONE.name, { id: questInfo.key });
_.forEach((questInfo.cond || {}).loot, (stack, key) => {
this.emitter.emit(itemsConfig.SERVER_INNER.ITEM_REMOVE.name, {item: { stack, key }}, socket);
});
// reward exp
if ((questInfo.reward || {}).exp) {
this.emitter.emit(statsConfig.SERVER_INNER.GAIN_EXP.name, { exp: getQuestExpValue(socket, questInfo.reward.exp) }, socket);
}
// reward stats
if ((questInfo.reward || {}).stats) {
this.emitter.emit(statsConfig.SERVER_INNER.GAIN_STATS.name, { stats: questInfo.reward.stats }, socket);
}
// reward items
_.forEach((questInfo.reward || {}).items, item => {
let instance = this.itemsRouter.getItemInstance(item.key);
if (instance) {
if (item.stack > 0) {
instance.stack = isGold(item) ? getQuestGoldValue(socket, item.stack) : item.stack;
}
let itemSlots = slots[item.key];
this.emitter.emit(itemsConfig.SERVER_INNER.ITEM_ADD.name, { slots: itemSlots, item: instance }, socket);
} else {
this.sendError({key: item.key}, socket, "No item info! cannot reward item.");
}
});
}
示例2: __make_back_references
function __make_back_references(namespace: NamespacePrivate) {
_.forEach(namespace._nodeid_index, (node: BaseNode) => {
node.propagate_back_references();
});
_.forEach(namespace._nodeid_index, (node: BaseNode) => {
node.install_extra_properties();
});
}
示例3:
elem.on('click', () => {
var elements: HTMLElement[] = [];
_.forEach(valueElements, valueElement => {
elements.push(valueElement.build(false).el);
});
_.each(elements, el => {
$$(el).insertBefore(elem.el);
});
elem.detach();
});
示例4: function
scheduleItemWidth: function(scheduleItem){
var concurrentItems = this.filter(function(item){
return item.beginning.unix() < scheduleItem.end.unix() && item.end.unix() > scheduleItem.beginning.unix()
});
var maxGutter = 0
_.forEach(concurrentItems, function(item){
if(item.calendarGutter && item.calendarGutter > maxGutter){
maxGutter = item.calendarGutter
}
});
maxGutter++;
return Math.floor(99 / maxGutter);
}
示例5: _getExtraName
private _getExtraName() {
const self = this;
const str: string[] = [];
_.forEach(extraStatusCodeBits, (value: number, key: string) => {
if ((self._extraBits & value) === value) {
str.push(key);
}
});
if (str.length === 0) {
return "";
}
return "#" + str.join("|");
}
示例6: buildUpAliases
function buildUpAliases(
node: BaseNode,
xw: XmlWriter,
options: any
) {
const addressSpace = node.addressSpace;
options.aliases = options.aliases || {};
options.aliases_visited = options.aliases_visited || {};
const k = _hash(node);
// istanbul ignore next
if (options.aliases_visited[k]) {
return;
}
options.aliases_visited[k] = 1;
// put datatype into aliases list
if (node.nodeClass === NodeClass.Variable || node.nodeClass === NodeClass.VariableType) {
const nodeV = node as UAVariableType || UAVariable;
if (nodeV.dataType && nodeV.dataType.namespace === 0 && nodeV.dataType.value !== 0) {
// name
const dataTypeName = b(xw, resolveDataTypeName(addressSpace, nodeV.dataType));
if (dataTypeName) {
if (!options.aliases[dataTypeName]) {
options.aliases[dataTypeName] = nodeV.dataType;
}
}
}
}
function collectReferenceNameInAlias(reference: Reference) {
// reference.referenceType
const key = b(xw, reference._referenceType!.browseName);
if (!options.aliases.key) {
if (reference.referenceType.namespace === 0) {
options.aliases[key] = reference.referenceType.toString().replace("ns=0;", "");
} else {
options.aliases[key] = n(xw, reference.referenceType);
}
}
}
_.forEach(node.allReferences(), collectReferenceNameInAlias);
}
示例7: SaveReciptient
public SaveReciptient(recipient: Recipient): void {
// check if recipient is undefined
assert(recipient && recipient != null, `The 'recipient' cannot be null or undefined.`);
// if there are any gifts save them
if (recipient.gifts) {
_.forEach(recipient.gifts, (gift: Gift): void => {
if (!gift.id || gift.id == "") {
let newGift = this.giftRepository.Create(gift);
gift.id = newGift.id;
}
else {
this.giftRepository.Update(gift);
}
});
}
// if the address exits, create/update
if (recipient.address) {
if (!recipient.address.id && recipient.address.id == "") {
let newAddress = this.addressRepository.Create(recipient.address);
recipient.address.id = newAddress.id;
}
else {
this.addressRepository.Update(recipient.address);
}
}
// now save the recipient
if (!recipient.id || recipient.id == "") {
let newRecipient = this.recipientRepository.Create(recipient as CoreRecipient);
recipient.id = newRecipient.id;
}
else {
this.recipientRepository.Update(recipient);
}
// lastly, update the gift-recipient relation
this.recipientGiftRelationRepository.Update(recipient.id,
_.map(recipient.gifts, (gift: Gift): string => gift.id));
return
}
示例8: visitUANode
function visitUANode(
node: BaseNode,
options: any,
forward: boolean
) {
assert(_.isBoolean(forward));
const addressSpace = node.addressSpace;
options.elements = options.elements || [];
options.index_el = options.index_el || {};
// visit references
function process_reference(reference: Reference) {
// only backward or forward refernces
if (reference.isForward !== forward) {
return;
}
if (reference.nodeId.namespace === 0) {
return; // skip OPCUA namespace
}
const k = _hash(reference);
if (!options.index_el[k]) {
options.index_el[k] = 1;
const o = addressSpace.findNode(k)! as BaseNode;
if (o) {
visitUANode(o, options, forward);
}
}
}
_.forEach(node.ownReferences(), process_reference);
options.elements.push(node);
return node;
}
示例9: _dumpUADataTypeDefinition
function _dumpUADataTypeDefinition(
xw: XmlWriter,
node: UADataType
) {
const indexes = (node as any)._getDefinition();
if (indexes) {
xw.startElement("Definition");
xw.writeAttribute("Name", node.definitionName);
_.forEach(indexes.nameIndex, (defItem: any, key) => {
xw.startElement("Field");
xw.writeAttribute("Name", defItem.name);
if (defItem.dataType && !defItem.dataType.isEmpty()) {
// there is no dataType on enumeration
const dataTypeStr = defItem.dataType.toString();
xw.writeAttribute("DataType", dataTypeStr);
}
if (!utils.isNullOrUndefined(defItem.valueRank)) {
xw.writeAttribute("ValueRank", defItem.valueRank);
}
if (!utils.isNullOrUndefined(defItem.value)) {
xw.writeAttribute("Value", defItem.value);
}
if (defItem.description) {
xw.startElement("Description");
xw.text(defItem.description);
xw.endElement();
}
xw.endElement();
});
xw.endElement();
}
}
示例10: disconnect
public disconnect(...args: any[]): any {
const callback = args[0];
assert(_.isFunction(callback), "expecting a callback function here");
debugLog("ClientBaseImpl#disconnect", this.endpointUrl);
if (this.isReconnecting) {
debugLog("ClientBaseImpl#disconnect called while reconnection is in progress");
// let's abort the reconnection process
return this._cancel_reconnection((err?: Error) => {
debugLog("ClientBaseImpl#disconnect reconnection has been canceled");
assert(!err, " why would this fail ?");
assert(!this.isReconnecting);
// sessions cannot be cancelled properly and must be discarded.
this.disconnect(callback);
});
}
if (this._sessions.length && !this.keepPendingSessionsOnDisconnect) {
debugLog("warning : disconnection : closing pending sessions");
// disconnect has been called whereas living session exists
// we need to close them first ....
this._close_pending_sessions((/*err*/) => {
this.disconnect(callback);
});
return;
}
if (this._sessions.length) {
// transfer active session to orphan and detach them from channel
_.forEach(this._sessions, (session: ClientSessionImpl) => {
this._removeSession(session);
});
this._sessions = [];
}
assert(this._sessions.length === 0, " attempt to disconnect a client with live sessions ");
OPCUAClientBase.registry.unregister(this);
if (this._secureChannel) {
const tmpChannel = this._secureChannel;
this._destroy_secure_channel();
tmpChannel.close(() => {
debugLog(" EMIT NORMAL CLOSE");
/**
* @event close
*/
this.emit("close", null);
setImmediate(callback);
});
} else {
this.emit("close", null);
callback();
}
}