Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Naive quiescent for js.
var React = require('react');
var EventEmitter = require("events").EventEmitter;
function component (fn) {
var Component = React.createClass({
render: function () {
return fn.call(this, this.props.value, this.props.statics);
},
shouldComponentUpdate: function (nextProps) {
return this.props.value != nextProps.value;
}
});
return function (value, statics) {
return Component({ value: value, statics: statics });
};
};
// use
var Heading = component(function (value, statics) {
function onDelete () {
statics.events.emit('delete', 'someone clicked me');
}
var deleteButton = React.DOM.text({ onClick: onDelete }, 'x');
return React.DOM.text({},
value.text,
" ",
deleteButton);
});
var headingEvents = new EventEmitter();
var h = Heading({ text: 'some text' }, { events: headingEvents });
headingEvents.on('delete', function () {
console.log('got delete', h);
});
$ = document.querySelector.bind(document);
React.renderComponent(h, $('.app'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.