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

Commit

Permalink
exposed changed property keys from WidgetBase (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
agubler authored Sep 21, 2017
1 parent 4c579de commit aab9464
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/WidgetBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,18 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends E
*/
private _properties: P & WidgetProperties & { [index: string]: any };

/**
* Array of property keys considered changed from the previous set properties
*/
private _changedPropertyKeys: string[] = [];

/**
* Core properties widget base sets for all widget
*/
private _coreProperties: CoreProperties = {} as CoreProperties;

/**
* cached chldren map for instance management
* cached children map for instance management
*/
private _cachedChildrenMap: Map<string | number | Promise<WidgetBaseConstructor> | WidgetBaseConstructor, WidgetCacheWrapper[]>;

Expand Down Expand Up @@ -305,6 +313,10 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends E
return this._properties;
}

public get changedPropertyKeys(): string[] {
return [ ...this._changedPropertyKeys ];
}

public __setCoreProperties__(coreProperties: CoreProperties): void {
this._renderState = WidgetRenderState.PROPERTIES;
const { baseRegistry } = coreProperties;
Expand Down Expand Up @@ -368,6 +380,7 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends E
}

this._properties = diffPropertyResults;
this._changedPropertyKeys = changedPropertyKeys;

if (changedPropertyKeys.length > 0) {
this.invalidate();
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/WidgetBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,20 @@ registerSuite({

assert.strictEqual(called, true);
},
changedPropertyKeys() {
class TestWidget extends WidgetBase<any> {}
const widget = new TestWidget();
widget.__setProperties__({ foo: true });
assert.deepEqual(widget.changedPropertyKeys, [ 'foo' ]);
widget.__setProperties__({ foo: true });
assert.deepEqual(widget.changedPropertyKeys, []);
widget.__setProperties__({ foo: true });
widget.__setProperties__({ foo: true, bar: true });
assert.deepEqual(widget.changedPropertyKeys, [ 'bar' ]);
const changedPropertyKeys = widget.changedPropertyKeys;
changedPropertyKeys.push('bad key');
assert.notDeepEqual(changedPropertyKeys, widget.changedPropertyKeys);
},
render: {
'render with non widget children'() {
class TestWidget extends WidgetBase<any> {
Expand Down

0 comments on commit aab9464

Please sign in to comment.