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

Commit

Permalink
forward compatibility with TS2.4 (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
agubler authored Jun 22, 2017
1 parent 3737d63 commit a676c30
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 30 deletions.
6 changes: 2 additions & 4 deletions src/Injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Evented } from '@dojo/core/Evented';
import {
afterRender,
diffProperty,
InternalWNode,
InternalHNode,
WidgetBase
} from './WidgetBase';
import { decorate, isHNode, isWNode } from './d';
Expand Down Expand Up @@ -70,7 +68,7 @@ export interface InjectorProperties extends WidgetProperties {
scope: any;
render(): DNode;
getProperties?: GetProperties;
properties: WidgetProperties;
properties: any;
getChildren?: GetChildren;
children: DNode[];
}
Expand Down Expand Up @@ -108,7 +106,7 @@ export function Injector<C extends Evented, T extends Constructor<BaseInjector<C
@afterRender()
protected decorateBind(node: DNode): DNode {
const { scope } = this.properties;
decorate(node, (node: InternalHNode | InternalWNode) => {
decorate(node, (node: any) => {
const { properties } = node;
properties.bind = scope;
}, (node: DNode) => { return isHNode(node) || isWNode(node); });
Expand Down
22 changes: 5 additions & 17 deletions src/WidgetBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import {
WidgetMetaConstructor,
WidgetBaseConstructor,
WidgetBaseInterface,
WidgetProperties,
WNode
WidgetProperties
} from './interfaces';
import MetaBase from './meta/Base';
import RegistryHandler from './RegistryHandler';
Expand All @@ -39,17 +38,6 @@ interface WidgetCacheWrapper {
used: boolean;
}

export interface InternalWNode extends WNode {
properties: {
bind: any;
};
}
export interface InternalHNode extends HNode {
properties: {
bind: any;
};
}

enum WidgetRenderState {
IDLE = 1,
PROPERTIES,
Expand Down Expand Up @@ -149,7 +137,7 @@ function isHNodeWithKey(node: DNode): node is HNode {
* Main widget base for all widgets to extend
*/
@diffProperty('bind', DiffType.REFERENCE)
export class WidgetBase<P extends WidgetProperties = WidgetProperties, C extends DNode = DNode> extends Evented implements WidgetBaseInterface<P, C> {
export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> extends Evented implements WidgetBaseInterface<P, C> {

/**
* static identifier
Expand Down Expand Up @@ -179,7 +167,7 @@ export class WidgetBase<P extends WidgetProperties = WidgetProperties, C extends
/**
* internal widget properties
*/
private _properties: P;
private _properties: P & WidgetProperties;

/**
* properties from the previous render
Expand Down Expand Up @@ -313,7 +301,7 @@ export class WidgetBase<P extends WidgetProperties = WidgetProperties, C extends

@afterRender()
protected decorateBind(node: DNode | DNode[]): DNode | DNode[] {
decorate(node, (node: InternalWNode | InternalHNode) => {
decorate(node, (node: any) => {
const { properties = {} }: { properties: { bind?: any } } = node;
if (!properties.bind) {
properties.bind = this;
Expand Down Expand Up @@ -376,7 +364,7 @@ export class WidgetBase<P extends WidgetProperties = WidgetProperties, C extends
this._nodeMap.set(String(properties.key), <HTMLElement> element);
}

public get properties(): Readonly<P> {
public get properties(): Readonly<P> & Readonly<WidgetProperties> {
return this._properties;
}

Expand Down
4 changes: 2 additions & 2 deletions src/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ export interface DefaultWidgetBaseInterface extends WidgetBaseInterface<WidgetPr
* The interface for WidgetBase
*/
export interface WidgetBaseInterface<
P extends WidgetProperties = WidgetProperties,
P = WidgetProperties,
C extends DNode = DNode<DefaultWidgetBaseInterface>> extends Evented {

/**
* Widget properties
*/
readonly properties: P;
readonly properties: P & WidgetProperties;

/**
* Returns the widget's children
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/WidgetBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import { stub, spy, SinonStub } from 'sinon';
import { v, w, registry } from '../../src/d';
import { DNode, Render, WidgetProperties } from '../../src/interfaces';
import { Constructor, DNode, Render } from '../../src/interfaces';
import {
WidgetBase,
diffProperty,
Expand All @@ -15,7 +15,7 @@ import {
} from '../../src/WidgetBase';
import WidgetRegistry, { WIDGET_BASE_TYPE } from './../../src/WidgetRegistry';

interface TestProperties extends WidgetProperties {
interface TestProperties {
id: string;
foo: string;
bar?: null | string;
Expand Down Expand Up @@ -896,7 +896,7 @@ widget.__setProperties__({
'async factories only initialise once'() {
let resolveFunction: any;
const loadFunction = () => {
return new Promise((resolve) => {
return new Promise<Constructor<WidgetBase>>((resolve) => {
resolveFunction = resolve;
});
};
Expand Down Expand Up @@ -944,7 +944,7 @@ widget.__setProperties__({
'render with async factory'() {
let resolveFunction: any;
const loadFunction = () => {
return new Promise((resolve) => {
return new Promise<Constructor<WidgetBase>>((resolve) => {
resolveFunction = resolve;
});
};
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/WidgetRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ registerSuite({
const RegistryTestWidget = factoryRegistry.get<TestWidget>('test-widget');
assert.isNotNull(RegistryTestWidget);
const widget = new RegistryTestWidget!();
// demontrates the design time typing
// demonstrates the design time typing
widget.__setProperties__({ foo: 'bar' });
},
'throws an error if factory has not been registered.'() {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/testIntegration.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as registerSuite from 'intern!object';
import * as assert from 'intern/chai!assert';
import { WidgetBase } from '../../src/WidgetBase';
import { fromRegistry, registry } from '../../src/d';
import { registry } from '../../src/d';
import { WidgetProperties } from '../../src/interfaces';
import { VNode } from '@dojo/interfaces/vdom';
import * as tsx from './../../src/tsx';
import { fromRegistry } from './../../src/tsx';

registerSuite({
name: 'tsx',
Expand Down

0 comments on commit a676c30

Please sign in to comment.