import { StoreService, StoreSubscriber } from "../../../store.service"
import { IRootScopeService } from "angular"
import { {{properCase name}}Actions } from "./{{camelCase name}}.actions"
import { isActionOfType } from "../../../../util/actionHelper"

export interface {{properCase name}}Subscriber {
	on{{properCase name}}Changed({{camelCase name}}: {{type}})
}

export class {{properCase name}}Service implements StoreSubscriber {
	private static {{constantCase name}}_CHANGED_EVENT = "{{kebabCase name}}-changed"

	constructor(private $rootScope: IRootScopeService, private storeService: StoreService) {
		StoreService.subscribe(this.$rootScope, this)
	}

	public onStoreChanged(actionType: string) {
		if (isActionOfType(actionType, {{properName}}Actions)) {
			this.notify(this.select())
		}
	}

	private select() {
		return this.storeService.getState().{{camelCase subreducer}}.{{camelCase name}}
	}

	private notify(newState: {{type}}) {
		this.$rootScope.$broadcast({{properCase name}}Service.{{constantCase name}}_CHANGED_EVENT, { {{camelCase name}}: newState })
	}

	public static subscribe($rootScope: IRootScopeService, subscriber: {{properCase name}}Subscriber) {
		$rootScope.$on({{properCase name}}Service.{{constantCase name}}_CHANGED_EVENT, (event, data) => {
			subscriber.on{{properCase name}}Changed(data.{{camelCase name}})
		})
	}
}

import { StoreService, StoreSubscriber } from "../../../store.service"
import { IRootScopeService } from "angular"
import { {{properCase name}}Actions } from "./{{camelCase name}}.actions"
import { isActionOfType } from "../../../../util/actionHelper"

export interface {{properCase name}}Subscriber {
	on{{properCase name}}Changed({{camelCase name}}: {{type}})
}

export class {{properCase name}}Service implements StoreSubscriber {
	private static {{constantCase name}}_CHANGED_EVENT = "{{kebabCase name}}-changed"

	constructor(private $rootScope: IRootScopeService, private storeService: StoreService) {
		StoreService.subscribe(this.$rootScope, this)
	}

	public onStoreChanged(actionType: string) {
		if (isActionOfType(actionType, {{properCase name}}Actions)) {
			this.notify(this.select())
		}
	}

	private select() {
		return this.storeService.getState().{{camelCase subreducer}}.{{camelCase name}}
	}

	private notify(newState: {{type}}) {
		this.$rootScope.$broadcast({{properCase name}}Service.{{constantCase name}}_CHANGED_EVENT, { {{camelCase name}}: newState })
	}

	public static subscribe($rootScope: IRootScopeService, subscriber: {{properCase name}}Subscriber) {
		$rootScope.$on({{properCase name}}Service.{{constantCase name}}_CHANGED_EVENT, (event, data) => {
			subscriber.on{{properCase name}}Changed(data.{{camelCase name}})
		})
	}
}

Fix plop template variable usage
Fix plop template variable usage
