当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript underscore.each函数代码示例

本文整理汇总了TypeScript中underscore.each函数的典型用法代码示例。如果您正苦于以下问题:TypeScript each函数的具体用法?TypeScript each怎么用?TypeScript each使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了each函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: buildModuleNavigationLinks

       function buildModuleNavigationLinks(extensionModule: any){
           if(extensionModule.navigation && extensionModule.navigation.length >0){

               _.each(extensionModule.navigation,function(menu: any) {
                   var group = menu.toggleGroupName;
                  if(group != undefined && group != null){
                      if(menuMap[group] == undefined){
                          menuMap[group] = menu
                          if(menu.links == undefined || menu.links == null) {
                              menu.links = [];
                          }
                      }
                      else {
                          _.each(menu.links,function(link: any){
                              menuMap[group].links.push(link);
                          })

                      }
                  }

               });
           }

           if(extensionModule.feedNavigation && extensionModule.feedNavigation.length >0) {
               _.each(extensionModule.feedNavigation,function(feedNav: any) {
                   feedNavigationMap[feedNav.linkText] = feedNav;
               });
           }

           if(extensionModule.templateNavigation && extensionModule.templateNavigation.length >0) {
               _.each(extensionModule.templateNavigation,function(templateNav: any) {
                   templateNavigationMap[templateNav.linkText] = templateNav;
               });
           }
       }
开发者ID:prashanthc97,项目名称:kylo,代码行数:35,代码来源:AngularModuleExtensionService.ts

示例2: it

    it('Functor 2: fmap (f . g) = fmap f . fmap g', () => {
        var f = (x: number) => x * 2,
            g = (x: number) => x - 3;

        _.each([ Maybe.just(10), Maybe.nothing<number>() ],
            t => {
                var lhs = t.fmap(f).fmap(g),
                    rhs = t.fmap(x => g(f(x)));
                assert.ok(lhs.equals(rhs));
            });

        _.each([ Either.right<string,number>(10), Either.left<string,number>('oook') ],
            t => {
                var lhs = t.fmap(f).fmap(g),
                    rhs = t.fmap(x => g(f(x)));
                assert.ok(lhs.equals(rhs));
            });

        _.each([ Writer.writer(['(^_^)'], 99) ],
            t => {
                var lhs = t.fmap(f).fmap(g),
                    rhs = t.fmap(x => g(f(x)));
                assert.ok(lhs.equals(rhs));
            });
    });
开发者ID:aitoroses,项目名称:TsMonad,代码行数:25,代码来源:monad.ts

示例3: linkData

    private linkData(participants:Participant[], requests:Request[], connections:Connection[]) {
        var participantsById = {};
        _.each(participants, (p:Participant) => {
            participantsById[p.registration_id] = p;
        });

        _.each(requests, (r: Request) => {
            var participant = participantsById[r._participant_id];
            if(participant){
                r._participant = participant;
                participant._request = r;
            } else {
                this.err.fire('Critical error: No Participant found with the specified id(' + r._participant_id
                    + ') for the connection with the Request(#' + r.id + ')');
            }
        });

        _.each(connections, (c: Connection) => {
            var participant = participantsById[c._participant_id];
            if(participant){
                c._participant = participant;
                participant._connection = c;
            } else {
                this.err.fire('Critical error: No Participant found with the specified id(' + c._participant_id
                    + ') for the connection with the Connection(#' + c.id + ')');
            }
        });
    }
开发者ID:it7-solutions,项目名称:networking-public-plugin,代码行数:28,代码来源:data-manager.service.ts

示例4: optimalLoadout

export function optimalLoadout(applicableItems: DimItem[], bestItemFn: (item: DimItem) => number, name: string): Loadout {
  const itemsByType = _.groupBy(applicableItems, 'type');

  // Pick the best item
  let items = _.mapObject(itemsByType, (items) => _.max(items, bestItemFn));

  // Solve for the case where our optimizer decided to equip two exotics
  const getLabel = (i) => i.equippingLabel;
  // All items that share an equipping label, grouped by label
  const overlaps: _.Dictionary<DimItem[]> = _.groupBy(Object.values(items).filter(getLabel), getLabel);
  _.each(overlaps, (overlappingItems) => {
    if (overlappingItems.length <= 1) {
      return;
    }

    const options: _.Dictionary<DimItem>[] = [];
    // For each item, replace all the others overlapping it with the next best thing
    for (const item of overlappingItems) {
      const option = copy(items);
      const otherItems = overlappingItems.filter((i) => i !== item);
      let optionValid = true;

      for (const otherItem of otherItems) {
        // Note: we could look for items that just don't have the *same* equippingLabel but
        // that may fail if there are ever mutual-exclusion items beyond exotics.
        const nonExotics = itemsByType[otherItem.type].filter((i) => !i.equippingLabel);
        if (nonExotics.length) {
          option[otherItem.type] = _.max(nonExotics, bestItemFn);
        } else {
          // this option isn't usable because we couldn't swap this exotic for any non-exotic
          optionValid = false;
        }
      }

      if (optionValid) {
        options.push(option);
      }
    }

    // Pick the option where the optimizer function adds up to the biggest number, again favoring equipped stuff
    if (options.length > 0) {
      const bestOption = _.max(options, (opt) => sum(Object.values(opt), bestItemFn));
      items = bestOption;
    }
  });

  // Copy the items and mark them equipped and put them in arrays, so they look like a loadout
  const finalItems: { [type: string]: DimItem[] } = {};
  _.each(items, (item, type) => {
    const itemCopy = copy(item);
    itemCopy.equipped = true;
    finalItems[type.toLowerCase()] = [itemCopy];
  });

  return {
    classType: -1,
    name,
    items: finalItems
  };
}
开发者ID:delphiactual,项目名称:DIM,代码行数:60,代码来源:loadout-utils.ts

示例5: each

 elem.on('click', () => {
   const elements: HTMLElement[] = [];
   each(valueElements, valueElement => {
     elements.push(valueElement.build().el);
   });
   each(elements, el => {
     $$(el).insertBefore(elem.el);
   });
   elem.detach();
 });
开发者ID:coveo,项目名称:search-ui,代码行数:10,代码来源:BreadcrumbValuesList.ts

示例6: _next

    function _next():void {
      if (queue.length > 0) {
        var exec = queue.shift();
        var result = app.converter.convert(exec.src, app.settings);
        var reflectionsIndex:string[] = [];

        // Copy base template
        wrench.copyDirSyncRecursive('data/templates/site', exec.dest, {
          forceDelete: true
        });

        //// Generate reflection json files
        //result.project.children.forEach((c:any) => {
        //  var fileName = c.name.replace(/"/g, '') + '.json';
        //  var fileFullName = path.join(exec.dest, fileName);
        //  reflectionsIndex.push(fileName);
        //  grunt.file.write(fileFullName, JSON.stringify(c.toObject(), null, 2));
        //  grunt.log.writeln('File "' + fileFullName + '" created.');
        //});

        // Generate project metadata file
        var modules = enumerateModules(result.project);
        var classes = buildClasses(modules);
        var enumerations = buildEnumerations(modules);
        var interfaces = buildInterfaces(modules);
        var indexFile:string = path.join(exec.dest, "metadata.js");

        var indexObject = {
          reflections: reflectionsIndex,
          modules: buildModules(modules),
          entities: buildEntities(exec.dest,entities)
        };

        _.each(classes, (c:any) => {
          var classFile:string = path.join(exec.dest, "data/classes", c.name + '.json');
          grunt.file.write(classFile, JSON.stringify(c.data, null, 2));
        });
        _.each(enumerations, (c:any) => {
          var classFile:string = path.join(exec.dest, "data/enumerations", c.name + '.json');
          grunt.file.write(classFile, JSON.stringify(c.data, null, 2));
        });
        _.each(interfaces, (c:any) => {
          var classFile:string = path.join(exec.dest, "data/interfaces", c.name + '.json');
          grunt.file.write(classFile, JSON.stringify(c.data, null, 2));
        });
        var jsSlug = "DocsApp.constant('METADATA', " + JSON.stringify(indexObject, null, 2) + ");";
        grunt.file.write(indexFile, jsSlug);
        grunt.log.writeln('File "' + indexFile + '" created.');

        return _next();
      }
      _done();
    }
开发者ID:justindujardin,项目名称:pow2,代码行数:53,代码来源:docs.ts

示例7: update

    /**
     * Update the contents of this view
     *
     * Called when the model is changed.  The model may have been
     * changed by another view or by a state update from the back-end.
     */
    update(options?) {
        var view = this;
        var items = this.model.get('_options_labels');
        var radios = _.pluck(
            this.container.querySelectorAll('input[type="radio"]'),
            'value'
        );
        var stale = false;

        for (var i = 0, len = items.length; i < len; ++i) {
            if (radios[i] !== items[i]) {
                stale = true;
                break;
            }
        }

        if (stale && (options === undefined || options.updated_view !== this)) {
            // Add items to the DOM.
            this.container.textContent = '';
            _.each(items, function(item: any) {
                var label = document.createElement('label');
                label.textContent = item;
                view.container.appendChild(label);

                var radio = document.createElement('input');
                radio.setAttribute('type', 'radio');
                radio.value = item;
                radio.setAttribute('data-value', encodeURIComponent(item));
                label.appendChild(radio);
            });
        }
        var description = this.model.get('description');
        if (description.length === 0) {
            this.label.style.display = 'none';
        } else {
            this.label.textContent = description;
            this.typeset(this.label, description);
            this.label.style.display = '';
        }
        _.each(items, function(item: any) {
            var item_query = 'input[data-value="' +
                encodeURIComponent(item) + '"]';
            var radio = view.container.querySelectorAll(item_query);
            if (radio.length > 0) {
              var radio_el = radio[0] as HTMLInputElement;
              radio_el.checked = view.model.get('selected_label') === item;
              radio_el.disabled = view.model.get('disabled');
            }
        });
        return super.update(options);
    }
开发者ID:Lomascolo,项目名称:ipywidgets,代码行数:57,代码来源:widget_selection.ts

示例8: function

    success: (data) => {
      if(data.success) {
        _.each(params.successActions, function(action) {
          dispatch(action(params.data, data))
        })
      } else {
        _.each(params.failureActions, function(action) {
          dispatch(action(params.data, data))
        })

        // always flash the error
        dispatch(notifyError(data.errors.join(' ')))
      }
    },
开发者ID:btgaffor,项目名称:better-than-envelopes,代码行数:14,代码来源:util.ts

示例9: moment

            data.setupFeedHealth = (feedsArray: any)=>{
             var processedFeeds: any[] = [];
             if(feedsArray) {
                     var processed: any[] = [];
                     var arr: any[] = [];
                     _.each(feedsArray,  (feedHealth: any) =>{
                         //pointer to the feed that is used/bound to the ui/service
                         var feedData = null;
                         if (data.feedSummaryData[feedHealth.feed]) {
                             feedData = data.feedSummaryData[feedHealth.feed]
                             angular.extend(feedData, feedHealth);
                             feedHealth = feedData;
                         }
                         else {
                             data.feedSummaryData[feedHealth.feed] = feedHealth;
                             feedData = feedHealth;
                         }
                         arr.push(feedData);

                         processedFeeds.push(feedData);
                         if (feedData.lastUnhealthyTime) {
                             feedData.sinceTimeString = moment(feedData.lastUnhealthyTime).fromNow();
                         }

                        this.OpsManagerFeedService.decorateFeedSummary(feedData);
                         if(feedData.stream == true && feedData.feedHealth){
                             feedData.runningCount = feedData.feedHealth.runningCount;
                             if(feedData.runningCount == null){
                                 feedData.runningCount =0;
                             }
                         }

                         if(feedData.running){
                             feedData.timeSinceEndTime = feedData.runTime;
                             feedData.runTimeString = '--';
                         }
                          processed.push(feedData.feed);
                     });
                     var keysToRemove=_.difference(Object.keys(data.feedSummaryData),processed);
                     if(keysToRemove != null && keysToRemove.length >0){
                         _.each(keysToRemove,(key: any)=>{
                             delete  data.feedSummaryData[key];
                         })
                     }
                     data.feedsArray = arr;
                 }
                 return processedFeeds;

         };
开发者ID:prashanthc97,项目名称:kylo,代码行数:49,代码来源:OpsManagerDashboardService.ts


注:本文中的underscore.each函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。