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

Commit

Permalink
reinstated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdye committed Nov 3, 2017
1 parent 5314358 commit a4d075d
Show file tree
Hide file tree
Showing 10 changed files with 437 additions and 439 deletions.
16 changes: 8 additions & 8 deletions src/WidgetBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,14 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends E

private _renderState: WidgetRenderState = WidgetRenderState.IDLE;

private _metaMap = new WeakMap<WidgetMetaConstructor<any>, WidgetMetaBase>();
private _metaMap = new Map<WidgetMetaConstructor<any>, WidgetMetaBase>();

private _boundRenderFunc: Render;

private _boundInvalidate: () => void;

private _nodeHandler: NodeHandler;

private _metaAfterRenders: (() => void)[] = [];

/**
* @constructor
*/
Expand Down Expand Up @@ -157,9 +155,9 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends E
if (!cached) {
cached = new MetaType({
invalidate: this._boundInvalidate,
nodeHandler: this._nodeHandler
nodeHandler: this._nodeHandler,
bind: this
});
this._metaAfterRenders.push(cached.afterRender.bind(cached));
this._metaMap.set(MetaType, cached);
this.own(cached);
}
Expand Down Expand Up @@ -477,9 +475,11 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends E
return afterRenderFunction.call(this, dNode);
}, dNode);
}
if (this._metaAfterRenders.length) {
this._metaAfterRenders.forEach(afterRender => afterRender());
}

this._metaMap.forEach(meta => {
meta.afterRender();
});

return dNode;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ export interface NodeHandlerInterface extends Evented {
export interface WidgetMetaProperties {
invalidate: () => void;
nodeHandler: NodeHandlerInterface;
bind: any;
}

export interface Render {
Expand Down
5 changes: 4 additions & 1 deletion src/meta/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ export class Base extends Destroyable implements WidgetMetaBase {

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

protected _bind: any;

constructor(properties: WidgetMetaProperties) {
super();

this._invalidate = properties.invalidate;
this.nodeHandler = properties.nodeHandler;
this._bind = properties.bind;
}

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

public afterRender(): void {
// No nothing by default
// Do nothing by default.
}
}

Expand Down
22 changes: 4 additions & 18 deletions src/meta/WebAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,15 @@ export class WebAnimations extends Base {
}

if (onFinish) {
player.onfinish = onFinish;
player.onfinish = onFinish.bind(this._bind);
}

if (onCancel) {
player.oncancel = onCancel;
player.oncancel = onCancel.bind(this._bind);
}
}

// private _bindControlCallbacks(controls: AnimationControls, bindScope: any): AnimationControls {

// const {
// onFinish,
// onCancel
// } = controls;

// return {
// ...controls,
// onFinish: onFinish ? onFinish.bind(bindScope) : null,
// onCancel: onCancel ? onCancel.bind(bindScope) : null
// };
// }

add(key: string, animateProperties: AnimationProperties | AnimationProperties[], bindScope: any) {
add(key: string, animateProperties: AnimationProperties | AnimationProperties[]) {
const node = this.getNode(key);

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

this._updatePlayer(player, controls); // this._bindControlCallbacks(controls, bindScope));
this._updatePlayer(player, controls);

this._animationMap.set(id, {
player,
Expand Down
15 changes: 10 additions & 5 deletions tests/unit/meta/Dimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ registerSuite('meta - Dimensions', {

const dimensions = new Dimensions({
invalidate: () => {},
nodeHandler
nodeHandler,
bind: this
});

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

const dimensions = new Dimensions({
invalidate: () => {},
nodeHandler
nodeHandler,
bind: this
});

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

const dimensions = new Dimensions({
invalidate: () => {},
nodeHandler
nodeHandler,
bind: this
});

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

const dimensions = new Dimensions({
invalidate: invalidateStub,
nodeHandler
nodeHandler,
bind: this
});

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

const dimensions = new Dimensions({
invalidate: () => {},
nodeHandler
nodeHandler,
bind: this
});

assert.deepEqual(dimensions.get('foo'), {
Expand Down
27 changes: 18 additions & 9 deletions tests/unit/meta/Intersection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ registerSuite('meta - Intersection', {

const intersection = new Intersection({
invalidate: () => {},
nodeHandler
nodeHandler,
bind: this
});

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

const intersection = new Intersection({
invalidate: () => {},
nodeHandler
nodeHandler,
bind: this
});

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

const intersection = new Intersection({
invalidate: () => {},
nodeHandler
nodeHandler,
bind: this
});
const element = document.createElement('div');
nodeHandler.add(element, 'root');
Expand All @@ -80,7 +83,8 @@ registerSuite('meta - Intersection', {

const intersection = new Intersection({
invalidate: () => {},
nodeHandler
nodeHandler,
bind: this
});

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

const intersection = new Intersection({
invalidate: () => {},
nodeHandler
nodeHandler,
bind: this
});

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

const intersection = new Intersection({
invalidate: invalidateStub,
nodeHandler
nodeHandler,
bind: this
});

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

const intersection = new Intersection({
invalidate: invalidateStub,
nodeHandler
nodeHandler,
bind: this
});

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

const intersection = new Intersection({
invalidate: invalidateStub,
nodeHandler
nodeHandler,
bind: this
});

intersection.get('foo', { root: 'root' });
Expand Down Expand Up @@ -213,7 +221,8 @@ registerSuite('meta - Intersection', {
const nodeHandler = new NodeHandler();
const intersection = new Intersection({
invalidate: () => {},
nodeHandler
nodeHandler,
bind: this
});

const root = document.createElement('div');
Expand Down
Loading

0 comments on commit a4d075d

Please sign in to comment.