NgReact - React Components in Angular

1,072 阅读1分钟
原文链接: davidchang.github.io

Intro

Facebook's React library is designed to be used as a view component atop other JavaScript frameworks. NgReact is a pair of proof of concept directives that show how React can cooperate with Angular, resulting in performance gains nearly up to 78% (or, well, losses up to 23%).

Installation

bower install ngReact

Set Up

In your HTML:






Declare ngReact as a dependency of your Angular module:


angular.module('ngReactDemo', ['ngReact']);

ngReactComponent Directive

Render a user-defined React component via Angular. This got up to nearly 78% faster performance against a native, naive ng-repeat.

You'll have to create a globally available React component, like this iterator example (but it could be anything):


And then invoke it using the ng-react-component directive:

ngReactRepeat Directive

Render a unit of HTML for each entry in a collection just like you use ng-repeat. This was about 23% slower performance.

You'll use this directive just like you use ng-repeat. Your HTML will look like this:


And that's it - just make sure $scope.data exists. Please note that this only supports the ng-bind and ng-click directives and the class and id attributes.

With this code in particular, I would love any help I could get in figuring out how my performance is so bad.