當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript underscore.forEach函數代碼示例

本文整理匯總了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.");
			}
		});
	}
開發者ID:Tzook,項目名稱:lul,代碼行數:31,代碼來源:quests.router.ts

示例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();
    });
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:9,代碼來源:load_nodeset2.ts

示例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();
 });
開發者ID:erocheleau,項目名稱:search-ui,代碼行數:10,代碼來源:BreadcrumbValuesList.ts

示例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);
			}
開發者ID:entcore,項目名稱:infra-front,代碼行數:13,代碼來源:calendar.ts

示例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("|");
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:14,代碼來源:opcua_status_code.ts

示例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);

}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:49,代碼來源:nodeset_to_xml.ts

示例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
    }
開發者ID:LBBLUG,項目名稱:bastas-core,代碼行數:41,代碼來源:RecipientController.ts

示例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;
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:38,代碼來源:nodeset_to_xml.ts

示例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();
    }
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:36,代碼來源:nodeset_to_xml.ts

示例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();
        }
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:65,代碼來源:client_base_impl.ts


注:本文中的underscore.forEach函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。