import Directive from './directive';
import {POSITION_NAME, GRID_NAME} from '@grid/view/definition';
import {PositionView} from '@grid/plugin/position/position.view';

class Position extends Directive(POSITION_NAME, {root: `^?${GRID_NAME}`}) {
	constructor($element, $attrs, $window) {
		super();

		this.element = $element[0];
		this.$attrs = $attrs;
		this.$window = $window;

		this.position = new PositionView({
			element: this.element,
			window: this.$window
		});
		this.using(this.position.invalidateEvent.on(this.invalidate.bind(this)));
	}

	onInit() {
		this.invalidate();
	}

	invalidate() {
		if (this.root) {
			const targetName = this.$attrs[POSITION_NAME];
			this.position.invalidate(targetName);
		}
	}
}

Position.$inject = ['$element', '$attrs', '$window'];

export default {
	restrict: 'A',
	bindToController: true,
	controllerAs: '$position',
	controller: Position,
	require: Position.require,
	link: Position.link,
	scope: false
};
@@ -302,79 +302,23 @@
 his.
-element = $element%5B0%5D;%0A%09%09this.$attrs = $attrs;%0A%09%09this.$window = $window
+$attrs = $attrs
 ;%0A%0A%09
@@ -369,20 +369,19 @@
 nt: 
-this.
+$
 element
+%5B0%5D
 ,%0A%09%09
@@ -389,21 +389,16 @@
 window: 
-this.
 $window%0A

clean code