static parseEventName(eventName: string): StringMap<string, string> { var parts = eventName.toLowerCase().split('.'); var domEventName = ListWrapper.removeAt(parts, 0); if ((parts.length === 0) || !(StringWrapper.equals(domEventName, 'keydown') || StringWrapper.equals(domEventName, 'keyup'))) { return null; } var key = KeyEventsPlugin._normalizeKey(ListWrapper.removeLast(parts)); var fullKey = ''; ListWrapper.forEach(modifierKeys, (modifierName) => { if (ListWrapper.contains(parts, modifierName)) { ListWrapper.remove(parts, modifierName); fullKey += modifierName + '.'; } }); fullKey += key; if (parts.length != 0 || key.length === 0) { // returning null instead of throwing to let another plugin process the event return null; } var result = StringMapWrapper.create(); StringMapWrapper.set(result, 'domEventName', domEventName); StringMapWrapper.set(result, 'fullKey', fullKey); return result; }
it('should return the last sampleSize runs when the regression slope is >0', () => { createValidator({size: 2, metric: 'script'}); var sample = [mv(0, 0, {'script': 1}), mv(1, 1, {'script': 2}), mv(2, 2, {'script': 3})]; expect(validator.validate(ListWrapper.slice(sample, 0, 2))) .toEqual(ListWrapper.slice(sample, 0, 2)); expect(validator.validate(sample)).toEqual(ListWrapper.slice(sample, 1, 3)); });
it('should return the last sampleSize runs when it has at least the given size', () => { createValidator(2); var sample = [mv(0, 0, {'a': 1}), mv(1, 1, {'b': 2}), mv(2, 2, {'c': 3})]; expect(validator.validate(ListWrapper.slice(sample, 0, 2))) .toEqual(ListWrapper.slice(sample, 0, 2)); expect(validator.validate(sample)).toEqual(ListWrapper.slice(sample, 1, 3)); });
function constructResolvingPath(keys: any[]): string { if (keys.length > 1) { var reversed = findFirstClosedCycle(ListWrapper.reversed(keys)); var tokenStrs = ListWrapper.map(reversed, (k) => stringify(k.token)); return " (" + tokenStrs.join(' -> ') + ")"; } else { return ""; } }
_addFrameMetrics(result: {[key: string]: any}, frameTimes: any[]) { result['frameTime.mean'] = ListWrapper.reduce(frameTimes, (a, b) => a + b, 0) / frameTimes.length; var firstFrame = frameTimes[0]; result['frameTime.worst'] = ListWrapper.reduce(frameTimes, (a, b) => a > b ? a : b, firstFrame); result['frameTime.best'] = ListWrapper.reduce(frameTimes, (a, b) => a < b ? a : b, firstFrame); result['frameTime.smooth'] = ListWrapper.filter(frameTimes, (a) => a < _FRAME_TIME_SMOOTH_THRESHOLD).length / frameTimes.length; }
static all(debugElement: DebugElement): DebugElement[] { var scope = []; scope.push(debugElement); ListWrapper.forEach(debugElement.children, (child) => { scope = scope.concat(Scope.all(child)); }); ListWrapper.forEach(debugElement.componentViewChildren, (child) => { scope = scope.concat(Scope.all(child)); }); return scope; }
it('should detect changes in list', () => { let l = []; differ.check(l); l.push('a'); differ.check(l); expect(differ.toString()) .toEqual( iterableChangesAsString({collection: ['a[null->0]'], additions: ['a[null->0]']})); l.push('b'); differ.check(l); expect(differ.toString()) .toEqual(iterableChangesAsString( {collection: ['a', 'b[null->1]'], previous: ['a'], additions: ['b[null->1]']})); l.push('c'); l.push('d'); differ.check(l); expect(differ.toString()) .toEqual(iterableChangesAsString({ collection: ['a', 'b', 'c[null->2]', 'd[null->3]'], previous: ['a', 'b'], additions: ['c[null->2]', 'd[null->3]'] })); ListWrapper.removeAt(l, 2); differ.check(l); expect(differ.toString()) .toEqual(iterableChangesAsString({ collection: ['a', 'b', 'd[3->2]'], previous: ['a', 'b', 'c[2->null]', 'd[3->2]'], moves: ['d[3->2]'], removals: ['c[2->null]'] })); ListWrapper.clear(l); l.push('d'); l.push('c'); l.push('b'); l.push('a'); differ.check(l); expect(differ.toString()) .toEqual(iterableChangesAsString({ collection: ['d[2->0]', 'c[null->1]', 'b[1->2]', 'a[0->3]'], previous: ['a[0->3]', 'b[1->2]', 'd[2->0]'], additions: ['c[null->1]'], moves: ['d[2->0]', 'b[1->2]', 'a[0->3]'] })); });
add(b: BindingRecord, variableNames: string[], bindingIndex: number) { var oldLast = ListWrapper.last(this.records); if (isPresent(oldLast) && oldLast.bindingRecord.directiveRecord == b.directiveRecord) { oldLast.lastInDirective = false; } var numberOfRecordsBefore = this.records.length; this._appendRecords(b, variableNames, bindingIndex); var newLast = ListWrapper.last(this.records); if (isPresent(newLast) && newLast !== oldLast) { newLast.lastInBinding = true; newLast.lastInDirective = true; this._setArgumentToPureFunction(numberOfRecordsBefore); } }
_addEvents(events: { [key: string]: string }[]) { var needSort = false; events.forEach(event => { if (StringWrapper.equals(event['ph'], 'X')) { needSort = true; var startEvent = {}; var endEvent = {}; StringMapWrapper.forEach(event, (value, prop) => { startEvent[prop] = value; endEvent[prop] = value; }); startEvent['ph'] = 'B'; endEvent['ph'] = 'E'; endEvent['ts'] = startEvent['ts'] + startEvent['dur']; this._remainingEvents.push(startEvent); this._remainingEvents.push(endEvent); } else { this._remainingEvents.push(event); } }); if (needSort) { // Need to sort because of the ph==='X' events ListWrapper.sort(this._remainingEvents, (a, b) => { var diff = a['ts'] - b['ts']; return diff > 0 ? 1 : diff < 0 ? -1 : 0; }); } }
visitAll(asts: any[]): any[] { var res = ListWrapper.createFixedSize(asts.length); for (var i = 0; i < asts.length; ++i) { res[i] = asts[i].visit(this); } return res; }