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

Commit a4d075d

Browse files
committed
reinstated tests
1 parent 5314358 commit a4d075d

File tree

10 files changed

+437
-439
lines changed

10 files changed

+437
-439
lines changed

src/WidgetBase.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,14 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends E
106106

107107
private _renderState: WidgetRenderState = WidgetRenderState.IDLE;
108108

109-
private _metaMap = new WeakMap<WidgetMetaConstructor<any>, WidgetMetaBase>();
109+
private _metaMap = new Map<WidgetMetaConstructor<any>, WidgetMetaBase>();
110110

111111
private _boundRenderFunc: Render;
112112

113113
private _boundInvalidate: () => void;
114114

115115
private _nodeHandler: NodeHandler;
116116

117-
private _metaAfterRenders: (() => void)[] = [];
118-
119117
/**
120118
* @constructor
121119
*/
@@ -157,9 +155,9 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends E
157155
if (!cached) {
158156
cached = new MetaType({
159157
invalidate: this._boundInvalidate,
160-
nodeHandler: this._nodeHandler
158+
nodeHandler: this._nodeHandler,
159+
bind: this
161160
});
162-
this._metaAfterRenders.push(cached.afterRender.bind(cached));
163161
this._metaMap.set(MetaType, cached);
164162
this.own(cached);
165163
}
@@ -477,9 +475,11 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends E
477475
return afterRenderFunction.call(this, dNode);
478476
}, dNode);
479477
}
480-
if (this._metaAfterRenders.length) {
481-
this._metaAfterRenders.forEach(afterRender => afterRender());
482-
}
478+
479+
this._metaMap.forEach(meta => {
480+
meta.afterRender();
481+
});
482+
483483
return dNode;
484484
}
485485
}

src/interfaces.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ export interface NodeHandlerInterface extends Evented {
453453
export interface WidgetMetaProperties {
454454
invalidate: () => void;
455455
nodeHandler: NodeHandlerInterface;
456+
bind: any;
456457
}
457458

458459
export interface Render {

src/meta/Base.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ export class Base extends Destroyable implements WidgetMetaBase {
88

99
private _requestedNodeKeys = new Set<string | number>();
1010

11+
protected _bind: any;
12+
1113
constructor(properties: WidgetMetaProperties) {
1214
super();
1315

1416
this._invalidate = properties.invalidate;
1517
this.nodeHandler = properties.nodeHandler;
18+
this._bind = properties.bind;
1619
}
1720

1821
public has(key: string | number): boolean {
@@ -42,7 +45,7 @@ export class Base extends Destroyable implements WidgetMetaBase {
4245
}
4346

4447
public afterRender(): void {
45-
// No nothing by default
48+
// Do nothing by default.
4649
}
4750
}
4851

src/meta/WebAnimation.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,15 @@ export class WebAnimations extends Base {
6969
}
7070

7171
if (onFinish) {
72-
player.onfinish = onFinish;
72+
player.onfinish = onFinish.bind(this._bind);
7373
}
7474

7575
if (onCancel) {
76-
player.oncancel = onCancel;
76+
player.oncancel = onCancel.bind(this._bind);
7777
}
7878
}
7979

80-
// private _bindControlCallbacks(controls: AnimationControls, bindScope: any): AnimationControls {
81-
82-
// const {
83-
// onFinish,
84-
// onCancel
85-
// } = controls;
86-
87-
// return {
88-
// ...controls,
89-
// onFinish: onFinish ? onFinish.bind(bindScope) : null,
90-
// onCancel: onCancel ? onCancel.bind(bindScope) : null
91-
// };
92-
// }
93-
94-
add(key: string, animateProperties: AnimationProperties | AnimationProperties[], bindScope: any) {
80+
add(key: string, animateProperties: AnimationProperties | AnimationProperties[]) {
9581
const node = this.getNode(key);
9682

9783
if (node) {
@@ -114,7 +100,7 @@ export class WebAnimations extends Base {
114100
const { player } = this._animationMap.get(id);
115101
const { controls = {} } = properties;
116102

117-
this._updatePlayer(player, controls); // this._bindControlCallbacks(controls, bindScope));
103+
this._updatePlayer(player, controls);
118104

119105
this._animationMap.set(id, {
120106
player,

tests/unit/meta/Dimensions.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ registerSuite('meta - Dimensions', {
5454

5555
const dimensions = new Dimensions({
5656
invalidate: () => {},
57-
nodeHandler
57+
nodeHandler,
58+
bind: this
5859
});
5960

6061
assert.deepEqual(dimensions.get('foo'), defaultDimensions);
@@ -64,7 +65,8 @@ registerSuite('meta - Dimensions', {
6465

6566
const dimensions = new Dimensions({
6667
invalidate: () => {},
67-
nodeHandler
68+
nodeHandler,
69+
bind: this
6870
});
6971

7072
assert.deepEqual(dimensions.get(1234), defaultDimensions);
@@ -75,7 +77,8 @@ registerSuite('meta - Dimensions', {
7577

7678
const dimensions = new Dimensions({
7779
invalidate: () => {},
78-
nodeHandler
80+
nodeHandler,
81+
bind: this
7982
});
8083

8184
dimensions.get('foo');
@@ -89,7 +92,8 @@ registerSuite('meta - Dimensions', {
8992

9093
const dimensions = new Dimensions({
9194
invalidate: invalidateStub,
92-
nodeHandler
95+
nodeHandler,
96+
bind: this
9397
});
9498

9599
dimensions.get('foo');
@@ -131,7 +135,8 @@ registerSuite('meta - Dimensions', {
131135

132136
const dimensions = new Dimensions({
133137
invalidate: () => {},
134-
nodeHandler
138+
nodeHandler,
139+
bind: this
135140
});
136141

137142
assert.deepEqual(dimensions.get('foo'), {

tests/unit/meta/Intersection.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ registerSuite('meta - Intersection', {
3333

3434
const intersection = new Intersection({
3535
invalidate: () => {},
36-
nodeHandler
36+
nodeHandler,
37+
bind: this
3738
});
3839

3940
const hasIntersectionInfo = intersection.has('root');
@@ -44,7 +45,8 @@ registerSuite('meta - Intersection', {
4445

4546
const intersection = new Intersection({
4647
invalidate: () => {},
47-
nodeHandler
48+
nodeHandler,
49+
bind: this
4850
});
4951

5052
const hasIntersectionInfo = intersection.has('root', { root: 'root' });
@@ -55,7 +57,8 @@ registerSuite('meta - Intersection', {
5557

5658
const intersection = new Intersection({
5759
invalidate: () => {},
58-
nodeHandler
60+
nodeHandler,
61+
bind: this
5962
});
6063
const element = document.createElement('div');
6164
nodeHandler.add(element, 'root');
@@ -80,7 +83,8 @@ registerSuite('meta - Intersection', {
8083

8184
const intersection = new Intersection({
8285
invalidate: () => {},
83-
nodeHandler
86+
nodeHandler,
87+
bind: this
8488
});
8589

8690
intersection.get('root');
@@ -93,7 +97,8 @@ registerSuite('meta - Intersection', {
9397

9498
const intersection = new Intersection({
9599
invalidate: () => {},
96-
nodeHandler
100+
nodeHandler,
101+
bind: this
97102
});
98103

99104
intersection.get(1234);
@@ -107,7 +112,8 @@ registerSuite('meta - Intersection', {
107112

108113
const intersection = new Intersection({
109114
invalidate: invalidateStub,
110-
nodeHandler
115+
nodeHandler,
116+
bind: this
111117
});
112118

113119
intersection.get('root');
@@ -128,7 +134,8 @@ registerSuite('meta - Intersection', {
128134

129135
const intersection = new Intersection({
130136
invalidate: invalidateStub,
131-
nodeHandler
137+
nodeHandler,
138+
bind: this
132139
});
133140

134141
intersection.get('root');
@@ -174,7 +181,8 @@ registerSuite('meta - Intersection', {
174181

175182
const intersection = new Intersection({
176183
invalidate: invalidateStub,
177-
nodeHandler
184+
nodeHandler,
185+
bind: this
178186
});
179187

180188
intersection.get('foo', { root: 'root' });
@@ -213,7 +221,8 @@ registerSuite('meta - Intersection', {
213221
const nodeHandler = new NodeHandler();
214222
const intersection = new Intersection({
215223
invalidate: () => {},
216-
nodeHandler
224+
nodeHandler,
225+
bind: this
217226
});
218227

219228
const root = document.createElement('div');

0 commit comments

Comments
 (0)