angular-cn/packages/animations/browser/src/dsl/element_instruction_map.ts
2020-04-14 12:08:36 -07:00

39 lines
1009 B
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {AnimationTimelineInstruction} from './animation_timeline_instruction';
export class ElementInstructionMap {
private _map = new Map<any, AnimationTimelineInstruction[]>();
consume(element: any): AnimationTimelineInstruction[] {
let instructions = this._map.get(element);
if (instructions) {
this._map.delete(element);
} else {
instructions = [];
}
return instructions;
}
append(element: any, instructions: AnimationTimelineInstruction[]) {
let existingInstructions = this._map.get(element);
if (!existingInstructions) {
this._map.set(element, existingInstructions = []);
}
existingInstructions.push(...instructions);
}
has(element: any): boolean {
return this._map.has(element);
}
clear() {
this._map.clear();
}
}