This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createComponent(render) { | |
var def = typeof render === 'function' ? {render: render} : render; | |
render = def.render; | |
def.displayName = render.name; | |
def.render = function () { | |
return render.call(this, this.props.data, this.props.children); | |
}; | |
if (!def.getInitialState) { | |
def.getInitialState = function () { | |
return {}; | |
}; | |
} | |
if (def.componentDidMount) { | |
var cdm = def.componentDidMount; | |
def.componentDidMount = function () { | |
cdm.call(this, this.props.data); | |
}; | |
} | |
if (def.componentWillReceiveProps) { | |
var cwrp = def.componentWillReceiveProps; | |
def.componentWillReceiveProps = function (newProps) { | |
cwrp.call(this, newProps.data, this.props.data); | |
}; | |
} | |
if (def.componentWillUpdate) { | |
var cwu = def.componentWillUpdate; | |
def.componentWillUpdate = function () { | |
cwu.call(this, this.props.data); | |
}; | |
} | |
if (def.componentDidUpdate) { | |
var cdu = def.componentDidUpdate; | |
def.componentDidUpdate = function () { | |
cdu.call(this, this.props.data); | |
}; | |
} | |
if (def.shouldComponentUpdate) { | |
var scu = def.shouldComponentUpdate; | |
def.shouldComponentUpdate = function (newp, newState) { | |
return scu.call(this, this.props.data, newp.data, this.state, newState); | |
}; | |
} | |
var component = createFactory(createClass(def)); | |
return function () { | |
var data = arguments[0]; | |
var args = [{data, key: data && data.key}]; | |
return component.apply(this, args.concat([].slice.call(arguments, 1))); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var h1 = React.DOM.h1; | |
var div = React.DOM.div; | |
var MinKomponent = createComponent(function (data) { | |
return div({}, h1({}, 'Hei ' + data.name + '!')); | |
}); | |
React.render(MinKomponent({name: 'Dude'}), el); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment