本文整理汇总了TypeScript中lodash.flattenDeep函数的典型用法代码示例。如果您正苦于以下问题:TypeScript flattenDeep函数的具体用法?TypeScript flattenDeep怎么用?TypeScript flattenDeep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flattenDeep函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should assign unique ids for repeated panels', function() {
dashboardJSON.panels = [
{
id: 1,
type: 'row',
collapsed: true,
repeat: 'apps',
gridPos: { x: 0, y: 0, h: 1, w: 24 },
panels: [
{ id: 2, type: 'graph', gridPos: { x: 0, y: 1, h: 1, w: 6 } },
{ id: 3, type: 'graph', gridPos: { x: 6, y: 1, h: 1, w: 6 } },
],
},
{ id: 4, type: 'row', gridPos: { x: 0, y: 1, h: 1, w: 24 } },
{ id: 5, type: 'graph', gridPos: { x: 0, y: 2, h: 1, w: 12 } },
];
dashboard = new DashboardModel(dashboardJSON);
dashboard.processRepeats();
const panel_ids = _.flattenDeep(
_.map(dashboard.panels, panel => {
let ids = [];
if (panel.panels && panel.panels.length) {
ids = _.map(panel.panels, 'id');
}
ids.push(panel.id);
return ids;
})
);
expect(panel_ids.length).toEqual(_.uniq(panel_ids).length);
});
示例2:
]).then(results => {
// combine the annotations and flatten results
var annotations = _.flattenDeep([results[0], results[1]]);
// filter out annotations that do not belong to requesting panel
annotations = _.filter(annotations, item => {
// shownIn === 1 requires annotation matching panel id
if (item.source.showIn === 1) {
if (item.panelId && options.panel.id === item.panelId) {
return true;
}
return false;
}
return true;
});
// look for alert state for this panel
var alertState = _.find(results[2], {panelId: options.panel.id});
return {
annotations: annotations,
alertState: alertState,
};
}).catch(err => {
示例3: textForHtml
textForHtml(boundVariableLists: string[][]) {
const name = boundVariableLists[this.level][this.index];
if (_.countBy(_.flattenDeep(boundVariableLists))[name] > 1) { // Disambiguate variables that appear multiple times in scope
return this.serialize()
} else {
return name;
}
}
示例4:
_.forEach(queryResult, result => {
_.forEach(_.flattenDeep(result.rows), row => {
variables.push({
text: row,
value: row,
} as AzureLogsVariable);
});
});
示例5: relationValueMap
private async relationValueMap(joinQueryIds: Relation<number[]>): Promise<Relation<Map<number, string>>> {
let accounts = [] as DexiePromise<Entity[]>[];
let categories = [] as DexiePromise<Entity[]>[];
let subcategories = [] as DexiePromise<Entity[]>[];
let payeePayers = [] as DexiePromise<Entity[]>[];
let tags = [] as DexiePromise<Entity[]>[];
const tables = [
this.db.accounts,
this.db.categories,
this.db.subcategories,
this.db.payeePayers,
this.db.tags
];
await this.db.transaction('r', tables, () => {
joinQueryIds.accounts .forEach((id) => accounts .push(this.db.accounts .where('id').equals(id).toArray()));
joinQueryIds.categories .forEach((id) => categories .push(this.db.categories .where('id').equals(id).toArray()));
joinQueryIds.subcategories.forEach((id) => subcategories.push(this.db.subcategories.where('id').equals(id).toArray()));
joinQueryIds.payeePayers .forEach((id) => payeePayers .push(this.db.payeePayers .where('id').equals(id).toArray()));
joinQueryIds.tags .forEach((id) => tags .push(this.db.tags .where('id').equals(id).toArray()));
});
const allResolved = {
accounts : lodash.flattenDeep<Entity>(await Dexie.Promise.all(accounts)),
categories : lodash.flattenDeep<Entity>(await Dexie.Promise.all(categories)),
subcategories: lodash.flattenDeep<Entity>(await Dexie.Promise.all(subcategories)),
payeePayers : lodash.flattenDeep<Entity>(await Dexie.Promise.all(payeePayers)),
tags : lodash.flattenDeep<Entity>(await Dexie.Promise.all(tags)),
} as Relation<Entity[]>;
const _allMap = {
accounts: new Map(),
categories: new Map(),
subcategories: new Map(),
payeePayers: new Map(),
tags: new Map()
} as Relation<Map<number, string>>;
allResolved.accounts .map((item) => _allMap.accounts .set(item.id, item.name));
allResolved.categories .map((item) => _allMap.categories .set(item.id, item.name));
allResolved.subcategories.map((item) => _allMap.subcategories.set(item.id, item.name));
allResolved.payeePayers .map((item) => _allMap.payeePayers .set(item.id, item.name));
allResolved.tags .map((item) => _allMap.tags .set(item.id, item.name));
return _allMap;
}
示例6: flatMapDeep
/**
* Maps array of ValidationError returned by validation framework to FormValidationErrors containing extra form related properties.
*
* It also flattens nested structure of ValidationError (see: children property) into flat, one dimension array.
*
* @param errors - list of errors
* @param parentProperty - parent property name
*/
private flatMapDeep (errors: ValidationError[], parentProperty?: string): FormValidationError[] {
return _.flattenDeep<FormValidationError>(
errors.map((error: ValidationError) => {
if (error.children && error.children.length > 0) {
return this.flatMapDeep(error.children, parentProperty ? `${parentProperty}.${error.property}` : error.property)
} else {
return new FormValidationError(error, parentProperty)
}
})
)
}
示例7: test
test('calls the converter on the records prior to running', async () => {
const tasks = [[1, 2, 3], [4, 5]];
let index = 0;
const fetchAvailableTasks = async () => tasks[index++] || [];
const run = sinon.spy(() => false);
const converter = (x: number) => x.toString();
await fillPool(run, fetchAvailableTasks, converter);
expect(_.flattenDeep(run.args)).toEqual(['1', '2', '3']);
});
示例8: sortColorsByHue
export function sortColorsByHue(hexColors) {
const hslColors = _.map(hexColors, hexToHsl);
let sortedHSLColors = _.sortBy(hslColors, ['h']);
sortedHSLColors = _.chunk(sortedHSLColors, PALETTE_ROWS);
sortedHSLColors = _.map(sortedHSLColors, chunk => {
return _.sortBy(chunk, 'l');
});
sortedHSLColors = _.flattenDeep(_.zip(...sortedHSLColors));
return _.map(sortedHSLColors, hslToHex);
}
示例9: sortColorsByHue
function sortColorsByHue(hexColors: string[]) {
const hslColors = _.map(hexColors, hexToHsl);
const sortedHSLColors = _.sortBy(hslColors, ['h']);
const chunkedHSLColors = _.chunk(sortedHSLColors, PALETTE_ROWS);
const sortedChunkedHSLColors = _.map(chunkedHSLColors, chunk => {
return _.sortBy(chunk, 'l');
});
const flattenedZippedSortedChunkedHSLColors = _.flattenDeep(_.zip(...sortedChunkedHSLColors));
return _.map(flattenedZippedSortedChunkedHSLColors, hslToHex);
}