forked from ngReact/ngReact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngReact.min.js
1 lines (1 loc) · 2.04 KB
/
ngReact.min.js
1
(function(n,t){"undefined"!=typeof module&&module.exports?module.exports=t(require("react"),require("react-dom"),require("angular")):"function"==typeof define&&define.amd?define(["react","react-dom","angular"],function(e,r,angular){return n.ngReact=t(e,r,angular)}):n.ngReact=t(n.React,n.ReactDOM,n.angular)})(this,function(React,n,angular){"use strict";function t(n,t){if(angular.isFunction(n))return n;if(!n)throw Error("ReactComponent name attribute must be specified");var e;try{e=t.get(n)}catch(r){}if(!e)try{e=n.split(".").reduce(function(n,t){return n[t]},window)}catch(r){}if(!e)throw Error("Cannot find react component "+n);return e}function e(n,t){if(n.wrappedInApply)return n;var e=function(){var e=arguments,r=t.$root.$$phase;return"$apply"===r||"$digest"===r?n.apply(null,e):t.$apply(function(){return n.apply(null,e)})};return e.wrappedInApply=!0,e}function r(n,t){return Object.keys(n||{}).reduce(function(r,o){var c=n[o];return r[o]=angular.isFunction(c)?e(c,t):c,r},{})}function o(n,t,e,r){"collection"===n&&angular.isFunction(t.$watchCollection)?e.forEach(function(n){t.$watchCollection(n,r)}):"reference"===n?angular.isFunction(t.$watchGroup)?t.$watchGroup(e,r):e.forEach(function(n){t.$watch(n,r)}):e.forEach(function(n){t.$watch(n,r,!0)})}function c(t,e,r,o){r.$evalAsync(function(){n.render(React.createElement(t,e),o[0])})}var u=function(e){return{restrict:"E",replace:!0,link:function(u,i,a){var f=t(a.name,e),p=function(){var n=u.$eval(a.props),t=r(n,u);c(f,t,u,i)};a.props?o(a.watchDepth,u,[a.props],p):p(),u.$on("$destroy",function(){n.unmountComponentAtNode(i[0])})}}},i=function(e){return function(u,i,a){var f={restrict:"E",replace:!0,link:function(a,f,p){var l=t(u,e);i=i||Object.keys(l.propTypes||{});var d=function(){var n={};i.forEach(function(t){n[t]=a.$eval(p[t])}),c(l,r(n,a),a,f)},s=i.map(function(n){return p[n]});o(p.watchDepth,a,s,d),d(),a.$on("$destroy",function(){n.unmountComponentAtNode(f[0])})}};return angular.extend(f,a)}};return angular.module("react",[]).directive("reactComponent",["$injector",u]).factory("reactDirective",["$injector",i])});