Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Ensure _decoratorCache uses class-level decorators #623

Merged
merged 4 commits into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/WidgetBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends E
specificDecoratorList.push(...value);
}
else {
const decorators = this._decoratorCache.get(decoratorKey) || [];
const decorators = this.getDecorator(decoratorKey);
this._decoratorCache.set(decoratorKey, [ ...decorators, ...value ]);
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/WidgetBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1379,5 +1379,24 @@ registerSuite({

assert.equal(testWidget.getAfterRenders().length, 1);
assert.equal(testWidget2.getAfterRenders().length, 2);
},
'decorator cache is populated when addDecorator is called after instantiation'() {
class TestWidget extends WidgetBase<any> {
constructor() {
super();

this.addDecorator('beforeRender', function() {});
this.addDecorator('afterRender', function() {});
}

getDecoratorCount(key: string): number {
return this.getDecorator(key).length;
}
}

const testWidget = new TestWidget();

assert.equal(testWidget.getDecoratorCount('beforeRender'), 2, 'beforeRender = 1 (existing) + 1');
assert.equal(testWidget.getDecoratorCount('afterRender'), 1, 'afterRender = 0 (existing) + 1');
}
});