本文整理汇总了TypeScript中lodash.toArray函数的典型用法代码示例。如果您正苦于以下问题:TypeScript toArray函数的具体用法?TypeScript toArray怎么用?TypeScript toArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了toArray函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _parse_measures
_parse_measures(name, measures, draw_missing_datapoint_as_zero){
var dps = [];
var last_granularity;
var last_timestamp;
var last_value;
// NOTE(sileht): sample are ordered by granularity, then timestamp.
_.each(_.toArray(measures).reverse(), (metricData) => {
var granularity = metricData[1];
var timestamp = moment(metricData[0], moment.ISO_8601);
var value = metricData[2];
if (last_timestamp !== undefined){
// We have a more precise granularity
if (timestamp.valueOf() >= last_timestamp.valueOf()){
return;
}
if (draw_missing_datapoint_as_zero) {
var c_timestamp = last_timestamp;
c_timestamp.subtract(last_granularity, "seconds");
while (timestamp.valueOf() < c_timestamp.valueOf()) {
dps.push([0, c_timestamp.valueOf()]);
c_timestamp.subtract(last_granularity, "seconds");
}
}
}
last_timestamp = timestamp;
last_granularity = granularity;
last_value = value;
dps.push([last_value, last_timestamp.valueOf()]);
});
return { target: name, datapoints: _.toArray(dps).reverse() };
}
示例2: traverse
/**
* Traverse all potential child reflections of this reflection.
*
* The given callback will be invoked for all children, signatures and type parameters
* attached to this reflection.
*
* @param callback The callback function that should be applied for each child reflection.
*/
traverse(callback: TraverseCallback) {
for (const child of toArray(this.children)) {
if (callback(child, TraverseProperty.Children) === false) {
return;
}
}
}
示例3: return
firebase.database().ref(notesIndexRefPath).orderByChild('timestamp').limitToLast(100).on('value', snapshot => {
const noteIndices: FirebaseNoteIndex[] = lodash.toArray(snapshot.val()); // rename, reshape
let cachedNotes = this.store.cachedNotes; // Storeに保存してあるcachedNotesを取得する
/* 更新の必要があるnoteIndexだけを抽出する(noteidとtimestampが同一のnoteは更新の必要がない) */
let differenceNoteIndices = noteIndices.filter(noteIndex => {
const compareNotes = cachedNotes.filter(note => note.noteid === noteIndex.noteid);
return (compareNotes.length > 0 && compareNotes[0].timestamp === noteIndex.timestamp) ? false : true;
});
differenceNoteIndices = lodash.orderBy(differenceNoteIndices, ['timestamp'], ['desc']); // timestampの降順で並び替える
console.log('differenceNoteIndices: ');
console.log(differenceNoteIndices);
/* noteIndexに基づいてnoteを取得する。onceメソッドは非同期のため完了は順不同となる。(本当に?) */
if (differenceNoteIndices.length > 0) {
differenceNoteIndices.forEach(noteIndex => {
const notesRefPath = 'notes/' + noteIndex.noteid;
firebase.database().ref(notesRefPath).once('value', snapshot => {
const note: FirebaseNote = snapshot.val(); // rename
cachedNotes.unshift(note); // cachedNotesの先頭にnoteを追加
cachedNotes = lodash.uniqBy(cachedNotes, 'noteid'); // noteidの重複をまとめる。(先頭寄りにあるものを生かす)
cachedNotes = lodash.orderBy(cachedNotes, ['timestamp'], ['desc']); // timestampの降順で並べ替える
this.notes$.next(cachedNotes);
this.store.cachedNotes = cachedNotes; // 新しいcachedNotesをStoreのcachedNotesに書き戻す
});
});
} else { // differenceNoteIndices.length === 0
this.notes$.next(cachedNotes);
}
}, err => {
示例4: constructor
constructor(name?: string, opts?: IEnvironmentWorkerOpts) {
super([], {
id: idHelper.newId(),
name: 'iw-env' + (_.isUndefined(name) || name.length === 0 ? '' : '-' + name)
}, opts);
var defOpts = {};
this.opts = this.opts.beAdoptedBy<IEnvironmentWorkerOpts>(defOpts, 'worker');
this.opts.merge(opts);
this.genericConnections = this.opts.get<IGenericConnection[]>('genericConnections');
this.genericConnections = _.isUndefined(this.genericConnections) ? [] : _.toArray(this.genericConnections);
this.environmentObject = this.opts.get('environmentObject');
this.environmentObject = _.isUndefined(this.environmentObject) ? process.env : this.environmentObject;
var serviceConnections = this.opts.get<IServiceConnection[]>('serviceConnections');
if (!_.isUndefined(serviceConnections)) {
this.serviceConnections = _.map(serviceConnections, (srvConn: IServiceConnection) => {
var conn: IServiceConnection = {
name: srvConn.name,
protocol: srvConn.protocol,
host: srvConn.host,
port: srvConn.port,
endPoints: srvConn.endPoints,
token: srvConn.token,
url: EnvironmentWorker.getServiceConnectionUrl(srvConn)
};
return conn;
});
}
}
示例5: getDataRelativePath
function getDataRelativePath(...paths: string[]) {
let args = _.toArray(arguments);
args.unshift(getDataPath());
return path.join.apply(this, args);
}
示例6: it
it('has the appropriate DOM structure', function() {
var labelText = dropdownButton.querySelector('button').textContent;
assert.equal(labelText, 'adaugă persoană', 'has the appropriate label');
actionButtons = _.toArray(dropdownButton.querySelectorAll('option-list>button'));
var actionButtonLablels = actionButtons.map(_.property('textContent'));
assert.deepEqual(actionButtonLablels, ['debitor', 'persoană terţă'], 'options have the appropriate labels');
});
示例7: function
component.prototype[fnName] = function() {
const argArray = _.toArray(arguments);
const returnValue = newFn.apply(this, argArray);
if (oldFn) {
oldFn.apply(this, argArray);
}
return returnValue;
};
示例8: permutations
/**
* Generate permutations, in all possible orderings, with no repeat values
*
*
* permutations([1,2,3],2)
* // => [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]
*
* permutations('cat',2)
* // => [["c","a"],["c","t"],["a","c"],["a","t"],["t","c"],["t","a"]]
*/
function permutations(obj, n){
if (typeof obj=='string') obj = _.toArray(obj);
n = n?n:obj.length;
// make n copies of keys/indices
for (var j = 0, nInds=[]; j < n; j++) {nInds.push(_.keys(obj)) }
// get product of the indices, then filter to remove the same key twice
var arrangements = product(nInds).filter(pair=>pair[0]!==pair[1]);
return _.map(arrangements,indices=>_.map(indices,i=>obj[i]));
}
示例9: combinations_with_replacement
/**
* Generate n combinations with repeat values.
*
*
* combinations_with_replacement([0,1,2,3],2)
* // => [[0,0],[0,1],[0,2],[0,3],[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]]
*/
function combinations_with_replacement(obj,n){
if (typeof obj=='string') obj = _.toArray(obj);
n = n?n:obj.length;
// make n copies of keys/indices
for (var j = 0, nInds=[]; j < n; j++) {nInds.push(_.keys(obj)) }
// get product of the indices, then filter to keep elements in order
var arrangements = product(nInds).filter(pair=>pair[0]<=pair[1]);
return _.map(arrangements,indices=>_.map(indices,i=>obj[i]))
}
示例10: spy
return function spy() {
spy.calls = spy.calls || [];
spy.calls.push({ args: _.toArray(arguments) });
spy.executed = true;
spy.reset = function() {
spy.calls = [];
spy.executed = false;
};
};
示例11: before
before(function() {
activities = [
new InstitutionActivity()
];
activityAdder = createSpy();
addActivityButton = new AddActivityButton(activities, activityAdder);
domElement = getWidgetDOMElement(addActivityButton);
optionButtons = _.toArray(domElement.querySelectorAll('dropdown-button>option-list>button'));
});
示例12: postImportRoutine
function postImportRoutine(db) {
if (db.sequelize.dialect.name === 'postgres') {
return Promise.resolve(_.toArray(db.models))
.map(model => {
return updatePostgresSequence(model, db);
});
}
return Promise.resolve(null);
}
示例13: it
it('creates TodoItem widgets for each item in the given array', function() {
var todoItemData = [{
id: 'first-item',
label: 'the first new item'
}, {
id: 'second-item',
label: 'the second new item'
}];
todoList.setData(todoItemData);
var itemElements = _.toArray(domElement.querySelectorAll('ul>li>labeled-checkbox input[type="checkbox"]'));
assert.equal(itemElements.length, todoItemData.length, 'renders items as <li>s');
var itemLabels = _.toArray(domElement.querySelectorAll('ul>li>labeled-checkbox'));
var itemLabelTexts = itemLabels.map(_.property('textContent'));
var expectedItemLabels = todoItemData.map(_.property('label'));
assert.deepEqual(itemLabelTexts, expectedItemLabels, 'items have the appropriate label texts');
});
示例14: traverse
/**
* Traverse all potential child reflections of this reflection.
*
* The given callback will be invoked for all children, signatures and type parameters
* attached to this reflection.
*
* @param callback The callback function that should be applied for each child reflection.
*/
traverse(callback: TraverseCallback) {
if (this.type instanceof ReflectionType) {
if (callback(this.type.declaration, TraverseProperty.TypeLiteral) === false) {
return;
}
}
for (const parameter of toArray(this.typeParameters)) {
if (callback(parameter, TraverseProperty.TypeParameter) === false) {
return;
}
}
for (const parameter of toArray(this.parameters)) {
if (callback(parameter, TraverseProperty.Parameters) === false) {
return;
}
}
super.traverse(callback);
}
示例15: traverse
/**
* Traverse all potential child reflections of this reflection.
*
* The given callback will be invoked for all children, signatures and type parameters
* attached to this reflection.
*
* @param callback The callback function that should be applied for each child reflection.
*/
traverse(callback: TraverseCallback) {
for (const parameter of toArray(this.typeParameters)) {
if (callback(parameter, TraverseProperty.TypeParameter) === false) {
return;
}
}
if (this.type instanceof ReflectionType) {
if (callback(this.type.declaration, TraverseProperty.TypeLiteral) === false) {
return;
}
}
for (const signature of toArray(this.signatures)) {
if (callback(signature, TraverseProperty.Signatures) === false) {
return;
}
}
if (this.indexSignature) {
if (callback(this.indexSignature, TraverseProperty.IndexSignature) === false) {
return;
}
}
if (this.getSignature) {
if (callback(this.getSignature, TraverseProperty.GetSignature) === false) {
return;
}
}
if (this.setSignature) {
if (callback(this.setSignature, TraverseProperty.SetSignature) === false) {
return;
}
}
super.traverse(callback);
}