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; }); } }
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)); }); });
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 + ')'); } }); }
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 }; }
elem.on('click', () => { const elements: HTMLElement[] = []; each(valueElements, valueElement => { elements.push(valueElement.build().el); }); each(elements, el => { $$(el).insertBefore(elem.el); }); elem.detach(); });
it('Functor 1: fmap id = id', () => { _.each([ Maybe.just(20), Maybe.nothing<number>() ], t => assert.ok(t.equals(t.fmap(x => x)))); _.each([ Either.right<string,number>(20), Either.left<string,number>('oook') ], t => assert.ok(t.equals(t.fmap(x => x)))); _.each([ Writer.writer(['(^_^)'], 99) ], t => assert.ok(t.equals(t.fmap(x => x)))); });
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(); }
/** * 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); }
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(' '))) } },
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; };