Skip to content

Instantly share code, notes, and snippets.

@cevek
Last active August 29, 2015 14:06
Show Gist options
  • Save cevek/36e0546ddf001cf2801b to your computer and use it in GitHub Desktop.
Save cevek/36e0546ddf001cf2801b to your computer and use it in GitHub Desktop.
class R<P,S> {
state:S;
props:P;
static instance;
refs:{ [ref: string]: React.ReactComponent<any, any>; };
getDOMNode():Element {
return null
}
setProps(nextProps:P, callback?:() => void):void {
return null
}
replaceProps(nextProps:P, callback?:() => void):void {
return null
}
transferPropsTo<C extends React.ReactComponent<P, any>>(target:C):C {
return null
}
setState(nextState:S, callback?:() => void):void {
return null
}
replaceState(nextState:S, callback?:() => void):void {
return null
}
forceUpdate(callback?:() => void):void {
return null
}
constructor(props:P, ...children:any[]) {
var proto = this.constructor.prototype;
if (!this.constructor["component"]) {
proto.displayName = proto.constructor.name;
delete proto.constructor.prototype.constructor;
this.constructor["component"] = React["create" + "Class"](proto);
proto._isReactDescriptor = true;
}
var c = this.constructor["component"](props, children);
this["_context"] = c._context;
this["_owner"] = c._owner;
this["_store"] = c._store;
this["key"] = c.key;
this["ref"] = c.ref;
this["type"] = c.type;
this["props"] = c.props;
//console.log(this);
}
}
class A extends R <{name: string; test: boolean; children?}, {secondsElapsed: number}> {
interval;
getInitialState() {
return {secondsElapsed: 0};
}
componentDidMount() {
this.interval = setInterval(this.tick, 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
tick() {
this.setState({secondsElapsed: this.state.secondsElapsed + 1});
}
render() {
console.log("Render A");
return (
React.DOM.div(null, "Seconds Elapsed: ", this.state.secondsElapsed, new B({ap: Math.random().toString()}))
);
}
}
React.renderComponent(new A({name: "Good", test: true}), document.getElementById('test'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment