本文整理汇总了TypeScript中underscore.flatten函数的典型用法代码示例。如果您正苦于以下问题:TypeScript flatten函数的具体用法?TypeScript flatten怎么用?TypeScript flatten使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flatten函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: justObjects
valueFromComponents: (components) => {
const node: AST.CallableLiteral = {
type: 'expressioncallableLiteral',
input: [],
output: null,
body: []
};
const inputs = justObjects(components[1]);
// group each identifier with its type
const withTypes = _.flatten(inputs.map((input: AST.Nodes, index: number) => {
// ignore the types, we'll work with the argument identifiers
if (input.type !== 'expressionidentifier') {
return;
}
if (inputs[index + 1] && inputs[index + 1].type !== 'expressionidentifier') {
// we've got a type, return it with its type
return {identifier: input.value, type: inputs[index + 1]};
}
else {
// no type m8, make one up
return {identifier: input.value, type: types.getAnyType()};
}
}));
node.input = withTypes.nullMap(input => assignParent(input, node));
node.body = _.flatten(components[10] as any).filter(c => typeof(c) === 'object') as AST.ModuleChild[];
node.output = justObjects(_.flatten(components[4] as any))[0] || AST.createIdentifier('null', node);
return node;
},
开发者ID:shnud94,项目名称:livelang,代码行数:33,代码来源:javascriptStyle.ts
示例2: getLight
// Pass in full loadout and store objects. loadout should have all types of weapon and armor
// or it won't be accurate. function properly supports guardians w/o artifacts
// returns to tenth decimal place.
function getLight(store: DimStore, loadout: Loadout): string {
// https://www.reddit.com/r/DestinyTheGame/comments/6yg4tw/how_overall_power_level_is_calculated/
const itemWeight = {
Weapons: 6,
Armor: 5,
General: 4
};
// 3 Weapons, 4 Armor, 2 General
let itemWeightDenominator = 46;
if (store.destinyVersion === 2) {
// 3 Weapons, 4 Armor, 1 General
itemWeightDenominator = 42;
} else if (store.level === 40) {
// 3 Weapons, 4 Armor, 3 General
itemWeightDenominator = 50;
}
const items = _.flatten(Object.values(loadout.items)).filter((i) => i.equipped);
const exactLight = _.reduce(items, (memo, item) => {
return memo + (item.primStat.value * itemWeight[item.type === 'ClassItem' ? 'General' : item.location.sort]);
}, 0) / itemWeightDenominator;
// Floor-truncate to one significant digit since the game doesn't round
return (Math.floor(exactLight * 10) / 10).toFixed(1);
}
开发者ID:delphiactual,项目名称:DIM,代码行数:29,代码来源:loadout.service.ts
示例3: createElement
export function createElement(type: string, props: { [name: string]: any },
...children: Array<string | HTMLElement | Array<string | HTMLElement>>): HTMLElement {
let elem;
if (type === "fragment") {
elem = document.createDocumentFragment();
} else {
elem = document.createElement(type);
for (let k in props) {
let v = props[k];
if (k === "className")
k = "class";
if (k === "class" && isArray(v))
v = v.filter(c => c != null).join(" ");
if (v == null || isBoolean(v) && !v)
continue
elem.setAttribute(k, v);
}
}
for (const v of flatten(children, true)) {
if (v instanceof HTMLElement)
elem.appendChild(v);
else if (isString(v))
elem.appendChild(document.createTextNode(v))
}
return elem;
}
开发者ID:jfinkels,项目名称:bokeh,代码行数:28,代码来源:dom.ts
示例4: log
function log(): void {
const errors = _.flatten(allErrors);
const seen = new Set<string>();
errors.map(err => {
if (!seen.has(err)) {
seen.add(err);
fancyLog(`${ansiColors.red('Error')}: ${err}`);
}
});
const regex = /^([^(]+)\((\d+),(\d+)\): (.*)$/;
const messages = errors
.map(err => regex.exec(err))
.filter(match => !!match)
.map(x => x as string[])
.map(([, path, line, column, message]) => ({ path, line: parseInt(line), column: parseInt(column), message }));
try {
fs.writeFileSync(buildLogPath, JSON.stringify(messages));
} catch (err) {
//noop
}
fancyLog(`Finished ${ansiColors.green('compilation')} with ${errors.length} errors after ${ansiColors.magenta((new Date().getTime() - startTime!) + ' ms')}`);
}
开发者ID:PKRoma,项目名称:vscode,代码行数:27,代码来源:reporter.ts
示例5: equip
vm.equip = function equip(item) {
if (!vm.loadout) {
return;
}
if (item.equipment) {
if ((item.type === 'Class') && (!item.equipped)) {
item.equipped = true;
} else if (item.equipped) {
item.equipped = false;
} else {
const allItems: DimItem[] = _.flatten(Object.values(vm.loadout.items));
if (item.equippingLabel) {
const exotics = allItems.filter((i) => i.equippingLabel === item.equippingLabel && i.equipped);
for (const exotic of exotics) {
exotic.equipped = false;
}
}
allItems
.filter((i) => i.type === item.type && i.equipped)
.forEach((i) => {
i.equipped = false;
});
item.equipped = true;
}
}
vm.recalculateStats(vm.loadout.items);
};
开发者ID:delphiactual,项目名称:DIM,代码行数:31,代码来源:loadout-drawer.component.ts
示例6:
storeService.getStores().forEach((store) => {
_maxPowerItems.push(
..._.flatten(Object.values(maxLightLoadout(storeService, store).items)).map((i) => {
return i.id;
})
);
});
开发者ID:bhollis,项目名称:DIM,代码行数:7,代码来源:search-filters.ts
示例7: it
it("should produce SQL for joined tables", function () {
this.$http.whenGET("js/feeds/feeds-table.html").respond(200, "");
this.$http.whenGET("js/visual-query/visual-query-builder-connection-dialog.html").respond(200, "");
// Add tables
const chartViewModel = this.controller.chartViewModel;
chartViewModel.addNode(USERS_NODE);
chartViewModel.addNode(SALES_NODE);
chartViewModel.addNode(EVENT_NODE);
chartViewModel.addNode(VENUE_NODE);
connectTables(chartViewModel, 10, "userid", 11, "buyerid");
connectTables(chartViewModel, 11, "eventid", 12, "eventid");
connectTables(chartViewModel, 12, "venueid", 13, "venueid");
// Test SQL
let expected: any = "SELECT tbl10.`username`, tbl10.`firstname`, tbl10.`lastname`, tbl11.`qtysold`, tbl11.`pricepaid`, tbl11.`commission`, tbl12.`eventname`, tbl13.`venuename` "
+ "FROM `tickit`.`users` tbl10 INNER JOIN `tickit`.`sales` tbl11 ON tbl11.`buyerid` = tbl10.`userid` INNER JOIN `tickit`.`event` tbl12 ON tbl12.`eventid` = tbl11.`eventid` "
+ "INNER JOIN `tickit`.`venue` tbl13 ON tbl13.`venueid` = tbl12.`venueid`";
expect(this.controller.getSQLModel()).toBe(expected);
// Test selected columns
expected = _.flatten([USERS_COLUMNS, SALES_COLUMNS, EVENT_COLUMNS, VENUE_COLUMNS], true);
expect(this.controller.selectedColumnsAndTables).toEqual(expected);
});
开发者ID:prashanthc97,项目名称:kylo,代码行数:26,代码来源:build-query.component.spec.ts
示例8: mergeVendors
function mergeVendors([firstVendor, ...otherVendors]: Vendor[]) {
const mergedVendor = copy(firstVendor);
otherVendors.forEach((vendor) => {
Object.assign(firstVendor.cacheKeys, vendor.cacheKeys);
vendor.categories.forEach((category) => {
const existingCategory = _.find(mergedVendor.categories, { title: category.title });
if (existingCategory) {
mergeCategory(existingCategory, category);
} else {
mergedVendor.categories.push(category);
}
});
mergedVendor.hasArmorWeaps = mergedVendor.hasArmorWeaps || vendor.hasArmorWeaps;
mergedVendor.hasVehicles = mergedVendor.hasVehicles || vendor.hasVehicles;
mergedVendor.hasShadersEmbs = mergedVendor.hasShadersEmbs || vendor.hasShadersEmbs;
mergedVendor.hasEmotes = mergedVendor.hasEmotes || vendor.hasEmotes;
mergedVendor.hasConsumables = mergedVendor.hasConsumables || vendor.hasConsumables;
mergedVendor.hasBounties = mergedVendor.hasBounties || vendor.hasBounties;
});
mergedVendor.allItems = _.flatten(mergedVendor.categories.map((i) => i.saleItems), true);
return mergedVendor;
}
开发者ID:bhollis,项目名称:DIM,代码行数:27,代码来源:vendor.service.ts
示例9: getTagsFromState
getTagsFromState(state:ITodoState) {
let tags:string[] = _.flatten(state.todos.map(todo => todo.tags));
let nonBlank = tags.filter(t => !!t);
let sorted = _.sortBy(nonBlank);
let unique = _.uniq(sorted, true);
return unique;
}
开发者ID:allash,项目名称:angular2-seed-example-mashup,代码行数:8,代码来源:TodoService.ts
示例10: getFacetValues
private getFacetValues(fieldValues: IIndexFieldValue[]): FacetValue[] {
var values = [];
_.each(fieldValues, fieldValue => {
var hierarchy = this.facet.getValueFromHierarchy(fieldValue.value);
values.push(this.createFacetValuesFromHierarchy(hierarchy));
});
return _.flatten(values);
}
开发者ID:coveo,项目名称:search-ui,代码行数:8,代码来源:HierarchicalFacetSearch.ts
注:本文中的underscore.flatten函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论