Skip to content

Commit

Permalink
Merge branch 'master' into faster-explicit-if
Browse files Browse the repository at this point in the history
  • Loading branch information
robertknight authored Mar 31, 2017
2 parents 2098502 + 9d9c232 commit b8e367f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "preact",
"amdName": "preact",
"version": "7.2.1",
"description": "Tiny & fast Component-based virtual DOM framework.",
"main": "dist/preact.js",
Expand All @@ -21,7 +20,8 @@
"minify": "uglifyjs dist/preact.js -c collapse_vars,evaluate,screw_ie8,unsafe,loops=false,keep_fargs=false,pure_getters,unused,dead_code -m -o dist/preact.min.js -p relative --in-source-map dist/preact.js.map --source-map dist/preact.min.js.map",
"strip": "jscodeshift --run-in-band -s -t config/codemod-strip-tdz.js dist/preact.dev.js && jscodeshift --run-in-band -s -t config/codemod-const.js dist/preact.dev.js",
"size": "node -e \"process.stdout.write('gzip size: ')\" && gzip-size dist/preact.min.js",
"test": "npm-run-all lint --parallel test:mocha test:karma",
"test": "npm-run-all lint --parallel test:mocha test:karma test:ts",
"test:ts": "tsc -p test/ts/",
"test:mocha": "mocha --recursive --compilers js:babel/register test/shared test/node",
"test:karma": "karma start test/karma.conf.js --single-run",
"test:mocha:watch": "npm run test:mocha -- --watch",
Expand Down Expand Up @@ -104,6 +104,7 @@
"rollup-plugin-node-resolve": "^2.0.0",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0",
"typescript": "^2.2.2",
"uglify-js": "^2.7.5",
"webpack": "^1.13.1"
},
Expand Down
15 changes: 10 additions & 5 deletions src/preact.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare namespace preact {
interface ComponentProps<C extends Component<any, any>> {
interface ComponentProps<C extends Component<any, any> | FunctionalComponent<any>> {
children?:JSX.Element[];
key?:string | number | any;
ref?:(el: C) => void;
Expand Down Expand Up @@ -33,18 +33,23 @@ declare namespace preact {
componentDidUpdate?(previousProps:PropsType,previousState:StateType,previousContext:any):void;
}

interface FunctionalComponent<PropsType> {
(props?: PropsType & ComponentProps<this>, context?: any): JSX.Element
}

interface ComponentConstructor<PropsType, StateType> {
new (props?:PropsType):Component<PropsType, StateType>;
new (props?:PropsType, context?: any):Component<PropsType, StateType>;
}

abstract class Component<PropsType, StateType> implements ComponentLifecycle<PropsType, StateType> {
constructor(props?:PropsType);
constructor(props?:PropsType, context?:any);

static displayName?:string;
static defaultProps?:any;

state:StateType;
props:PropsType & ComponentProps<this>;
context: any;
base:HTMLElement;

linkState:(name:string) => (event: Event) => void;
Expand All @@ -54,10 +59,10 @@ declare namespace preact {

forceUpdate(): void;

abstract render(props:PropsType & ComponentProps<this>, state:any):JSX.Element;
abstract render(props?:PropsType & ComponentProps<this>, state?:StateType, context?: any):JSX.Element;
}

function h<PropsType>(node:ComponentConstructor<PropsType, any>, params:PropsType, ...children:(JSX.Element|JSX.Element[]|string)[]):JSX.Element;
function h<PropsType>(node:ComponentConstructor<PropsType, any> | FunctionalComponent<PropsType>, params:PropsType, ...children:(JSX.Element|JSX.Element[]|string)[]):JSX.Element;
function h(node:string, params:JSX.HTMLAttributes&JSX.SVGAttributes&{[propName: string]: any}, ...children:(JSX.Element|JSX.Element[]|string)[]):JSX.Element;
function render(node:JSX.Element, parent:Element, mergeWith?:Element):Element;
function rerender():void;
Expand Down
32 changes: 32 additions & 0 deletions test/ts/prect-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { h, render, Component } from 'preact';

interface DummyProps {
initialInput: string;
}

interface DummyState {
input: string;
}

class DummyComponent extends Component<DummyProps, DummyState> {
constructor(props: DummyProps) {
super(props);
this.state = {
input: `x${this.props}x`
}
}

render({ initialInput }: DummyProps, { input }: DummyState) {
return <DummerComponent initialInput={initialInput} input={input} />
}
}

interface DummerComponentProps extends DummyProps, DummyState {

}

function DummerComponent({ input, initialInput }: DummerComponentProps) {
return <div>Input: {input}, initial: {initialInput}</div>;
}

render(h(DummerComponent, { initialInput: "The input" }), document.getElementById("xxx"));
24 changes: 24 additions & 0 deletions test/ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"typeRoots": [
"../../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"jsxFactory": "h"
},
"files": [
"prect-test.tsx",
"../../src/preact.d.ts"
]
}

0 comments on commit b8e367f

Please sign in to comment.