mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
react: progress on react containers and mobx-state-tree store
This commit is contained in:
33
public/app/routes/ReactContainer.tsx
Normal file
33
public/app/routes/ReactContainer.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import coreModule from 'app/core/core_module';
|
||||
import { store } from 'app/stores/store';
|
||||
import { Provider } from 'mobx-react';
|
||||
|
||||
function WrapInProvider(store, Component, props) {
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<Component {...props} />
|
||||
</Provider>
|
||||
);
|
||||
}
|
||||
|
||||
/** @ngInject */
|
||||
export function reactContainer($route) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: '<h2>hasad</h2>',
|
||||
link(scope, elem) {
|
||||
let component = $route.current.locals.component;
|
||||
let props = {};
|
||||
|
||||
ReactDOM.render(WrapInProvider(store, component, props), elem[0]);
|
||||
|
||||
scope.$on('$destroy', function() {
|
||||
ReactDOM.unmountComponentAtNode(elem[0]);
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
coreModule.directive('reactContainer', reactContainer);
|
||||
Reference in New Issue
Block a user