Last active
August 29, 2015 14:06
-
-
Save wesleycho/1a904893add7e64c464f to your computer and use it in GitHub Desktop.
React grid with angular psuedocode
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
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