fix(animations): ignore triggers that are registered multiple times (#14723)

This commit is contained in:
Tobias Bosch 2017-02-24 16:28:14 -08:00 committed by Igor Minar
parent 9186068df1
commit 2602b039b4
3 changed files with 10 additions and 8 deletions

View File

@ -40,7 +40,7 @@ export class DomAnimationEngine {
private _elementTriggerStates = new Map<any, {[triggerName: string]: string}>();
private _triggers: {[triggerName: string]: AnimationTrigger} = {};
private _triggers: {[triggerName: string]: AnimationTrigger} = Object.create(null);
private _triggerListeners = new Map<any, TriggerListenerTuple[]>();
constructor(private _driver: AnimationDriver, private _normalizer: AnimationStyleNormalizer) {}
@ -58,7 +58,7 @@ export class DomAnimationEngine {
registerTrigger(trigger: AnimationTriggerMetadata, name: string = null): void {
name = name || trigger.name;
if (this._triggers[name]) {
throw new Error(`The provided animation trigger "${name}" has already been registered!`);
return;
}
this._triggers[name] = buildTrigger(name, trigger.definitions);
}

View File

@ -32,9 +32,14 @@ export class NoopAnimationEngine extends AnimationEngine {
private _changes: ChangeTuple[] = [];
private _flaggedRemovals = new Set<any>();
private _onDoneFns: (() => any)[] = [];
private _triggerStyles: {[triggerName: string]: {[stateName: string]: ɵStyleData}} = {};
private _triggerStyles: {[triggerName: string]: {[stateName: string]: ɵStyleData}} =
Object.create(null);
registerTrigger(trigger: AnimationTriggerMetadata, name: string = null): void {
name = name || trigger.name;
if (this._triggerStyles[name]) {
return;
}
const stateMap: {[stateName: string]: ɵStyleData} = {};
trigger.definitions.forEach(def => {
if (def.type === AnimationMetadataType.State) {
@ -42,7 +47,6 @@ export class NoopAnimationEngine extends AnimationEngine {
stateMap[stateDef.name] = normalizeStyles(stateDef.styles.styles);
}
});
name = name || trigger.name;
this._triggerStyles[name] = stateMap;
}

View File

@ -39,12 +39,10 @@ export function main() {
}
describe('trigger registration', () => {
it('should throw an error if the same trigger is registered twice', () => {
it('should ignore and not throw an error if the same trigger is registered twice', () => {
const engine = makeEngine();
engine.registerTrigger(trigger('trig', []));
expect(() => {
engine.registerTrigger(trigger('trig', []));
}).toThrowError(/The provided animation trigger "trig" has already been registered!/);
expect(() => { engine.registerTrigger(trigger('trig', [])); }).not.toThrow();
});
});