listen for changes in angular land and propagate that back to react

This commit is contained in:
Torkel Ödegaard 2018-10-31 09:19:08 -07:00
parent 2342f60a31
commit 7885453bcd
2 changed files with 21 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import _ from 'lodash';
import React, { PureComponent } from 'react';
import { DataSource, Plugin } from 'app/types/';
import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader';
@ -23,13 +24,24 @@ export class PluginSettings extends PureComponent<Props> {
const scopeProps = {
ctrl: {
datasourceMeta: dataSourceMeta,
current: dataSource,
current: _.cloneDeep(dataSource),
},
onModelChanged: this.onModelChanged,
};
this.component = loader.load(this.element, scopeProps, template);
}
componentWillUnmount() {
if (this.component) {
this.component.destroy();
}
}
onModelChanged(dataSource: DataSource) {
console.log(dataSource);
}
render() {
return <div ref={element => (this.element = element)} />;
}

View File

@ -149,6 +149,14 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $
return { notFound: true };
}
scope.$watch(
'ctrl.current',
() => {
scope.onModelChanged(scope.ctrl.current);
},
true
);
return {
baseUrl: dsMeta.baseUrl,
name: 'ds-config-' + dsMeta.id,