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