Add React.Children tests and change callback param return types from void to any

This commit is contained in:
Vincent Siao
2014-12-08 15:41:47 -08:00
parent b4174b1ff1
commit 0fb398c774
2 changed files with 33 additions and 15 deletions

View File

@@ -119,12 +119,13 @@ myComponent.reset();
// Attributes
// --------------------------------------------------------------------------
var children = ["Hello world", [null], React.DOM.span(null)];
var divStyle = { // CSSProperties
flex: "1 1 main-size",
backgroundImage: "url('hello.png')"
};
var htmlAttr = {
children: ["Hello world", [null], React.DOM.span(null)],
children: children,
className: "test-attr",
style: divStyle,
onClick: (event: React.MouseEvent) => {
@@ -140,7 +141,7 @@ React.DOM.span(htmlAttr);
React.DOM.input(htmlAttr);
//
// PropTypes
// React.PropTypes
// --------------------------------------------------------------------------
var PropTypesSpecification: React.ComponentSpec<any, any> = {
@@ -180,6 +181,18 @@ var PropTypesSpecification: React.ComponentSpec<any, any> = {
}
};
//
// React.Children
// --------------------------------------------------------------------------
var childMap: { [key: string]: number } =
React.Children.map<number>(children, (child) => { return 42; });
React.Children.forEach(children, (child) => {});
var nChildren: number = React.Children.count(children);
var onlyChild = React.Children.only([null, [[["Hallo"], true]], false, {
test: null
}]);
//
// Example from http://facebook.github.io/react/
// --------------------------------------------------------------------------

31
react/react.d.ts vendored
View File

@@ -26,7 +26,10 @@ declare module React {
// type ReactText = string | number;
// type Fragment = ReactNode[];
// type ReactNode = ReactElement<any, any> | Fragment | ReactText;
// type ReactNode = ReactElement<any> | Fragment | ReactText | KeyMap;
// interface KeyMap {
// [key: string]: ReactNode;
// }
//
// React Components
@@ -63,7 +66,7 @@ declare module React {
createClass<P>(spec: ComponentSpec<P, any>): ComponentClass<P>;
createElement<P>(type: any/*ReactType*/, props: P, ...children: any/*ReactNode*/[]): ReactElement<P>;
createFactory<P>(componentClass: ComponentClass<P>): ComponentFactory<P>;
render<P>(element: ReactElement<P>, container: Element, callback?: () => void): Component<P>;
render<P>(element: ReactElement<P>, container: Element, callback?: () => any): Component<P>;
unmountComponentAtNode(container: Element): boolean;
renderToString(element: ReactElement<any>): string;
renderToStaticMarkup(element: ReactElement<any>): string;
@@ -83,8 +86,8 @@ declare module React {
isMounted(): boolean;
props: P;
setProps(nextProps: P, callback?: () => void): void;
replaceProps(nextProps: P, callback?: () => void): void;
setProps(nextProps: P, callback?: () => any): void;
replaceProps(nextProps: P, callback?: () => any): void;
}
interface DOMComponent<P> extends Component<P> {
@@ -96,9 +99,9 @@ declare module React {
interface CompositeComponent<P, S> extends Component<P>, ComponentSpec<P, S> {
state: S;
setState(nextState: S, callback?: () => void): void;
replaceState(nextState: S, callback?: () => void): void;
forceUpdate(callback?: () => void): void;
setState(nextState: S, callback?: () => any): void;
replaceState(nextState: S, callback?: () => any): void;
forceUpdate(callback?: () => any): void;
refs: {
[key: string]: Component<any>
};
@@ -634,11 +637,13 @@ declare module React {
// React.Children
// ----------------------------------------------------------------------
// type Child = ReactElement<any> | ReactText;
interface ReactChildren {
map<T>(children: any/*ReactNode*/, fn: (child: any/*ReactNode*/) => T): { [key:string]: T };
forEach(children: any/*ReactNode*/, fn: (child: any/*ReactNode*/) => any): void;
map<T>(children: any/*ReactNode*/, fn: (child: any/*Child*/) => T): { [key:string]: T };
forEach(children: any/*ReactNode*/, fn: (child: any/*Child*/) => any): void;
count(children: any/*ReactNode*/): number;
only(children: any/*ReactNode*/): any;
only(children: any/*ReactNode*/): any/*Child*/;
}
//
@@ -865,9 +870,9 @@ declare module React {
PureRenderMixin: PureRenderMixin;
TransitionGroup: TransitionGroup;
batchedUpdates<A, B>(callback: (a: A, b: B) => void, a: A, b: B): void;
batchedUpdates<A>(callback: (a: A) => void, a: A): void;
batchedUpdates(callback: () => void): void;
batchedUpdates<A, B>(callback: (a: A, b: B) => any, a: A, b: B): void;
batchedUpdates<A>(callback: (a: A) => any, a: A): void;
batchedUpdates(callback: () => any): void;
classSet(cx: { [key: string]: boolean }): string;
cloneWithProps<P>(element: ReactElement<P>, props: P): ReactElement<P>;