Created
July 11, 2018 20:25
-
-
Save klzns/2b913a19b3965c38a1b4f485854878d3 to your computer and use it in GitHub Desktop.
React dentro de AngularJS
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
<react component="vtex.Hello" props=something.insideAngularScope"></react> |
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
angular.module('vtex.react', []) | |
.directive 'react', ($translate) -> | |
restrict: 'E' | |
scope: { | |
component: '@', | |
props: '=', | |
}, | |
link: (scope, elem, attrs) -> | |
componentPath = scope.component.split('.') | |
component = componentPath.reduce(((component, path) -> component[path]), window) | |
container = elem[0] | |
ReactDOM.render( | |
React.createElement(component, scope.props), | |
container | |
) | |
elem.on '$destroy', () -> | |
ReactDOM.unmountComponentAtNode(container) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment