本文整理汇总了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;
},
示例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);
}
示例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;
}
示例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')}`);
}
示例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);
};
示例6:
storeService.getStores().forEach((store) => {
_maxPowerItems.push(
..._.flatten(Object.values(maxLightLoadout(storeService, store).items)).map((i) => {
return i.id;
})
);
});
示例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);
});
示例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;
}
示例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;
}
示例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);
}