Skip to content

Instantly share code, notes, and snippets.

@wesleycho
Last active August 29, 2015 14:06
Show Gist options
  • Save wesleycho/1a904893add7e64c464f to your computer and use it in GitHub Desktop.
Save wesleycho/1a904893add7e64c464f to your computer and use it in GitHub Desktop.
React grid with angular psuedocode
module.directive('react-grid', function () {
return {
scope: { props: '=' },
link: function (scope, elem, attrs) {
var renderScheduled = false;
var component = React.createClass({
/** @jsx React.DOM */
var items = this.props.items;
var itemsDOM = items.map(function (item) {
var itemDOM = item.map(function (subItem) {
return (
<div>{subItem}</div>
);
});
return (
<div>{itemDOM}</div>
);
});
return itemsDOM;
});
scope.$watch('props', queueRender, true);
function queueRender(val) {
if (!renderScheduled) {
renderScheduled = true;
scope.$$postDigest(renderComponent);
}
}
function renderComponent() {
return React.renderComponent(component)(scope.props);
}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment