Skip to content

Commit af9bd1c

Browse files
committed
✨ Added hub for notifying item events
1 parent 92fab83 commit af9bd1c

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/businessLogic/contracts/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export interface ItemTypeCustomisations {
1414

1515
export interface TreeViewCreatedEventPayload {
1616
itemCustomisations: ItemTypeCustomisations;
17+
eventManager: EventManager
18+
}
19+
20+
export interface EventManager {
21+
subscribeToItemChecked(type: string, callback: (item: TreeViewItem[]) => void): void;
22+
subscribeToItemUnchecked(type: string, callback: (item: TreeViewItem[]) => void): void;
1723
}
1824

1925
export interface Customisations {

src/businessLogic/eventHub/explorerEventPublisher.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
import { TreeViewItem } from "../contracts/types"
2-
import { cascadeStateToDescendants, findChildrenOfType } from "../hierachyTraversal/hierachyTraversal";
1+
import { EventManager, TreeViewItem } from "../contracts/types"
2+
import { findChildrenOfType } from "../hierachyTraversal/hierachyTraversal";
33

44
const onCheckedSubscribers: {[type: string]: ((items: TreeViewItem[]) => void)[] } = {}
55
const onUnCheckedSubscribers: {[type: string]: ((items: TreeViewItem[]) => void)[] } = {}
66

7-
export const eventHub = {
7+
export const eventManager: EventManager = {
88
// Add subscriber for item hecked to collection of subscribers
99
subscribeToItemChecked(type: string, callback: (item: TreeViewItem[]) => void): void {
10+
onCheckedSubscribers[type] = onCheckedSubscribers[type] ?? [];
11+
1012
onCheckedSubscribers[type].push(callback);
1113
},
1214

1315
// Add subscriber for item unchecked to collection of subscribers
14-
subscribeToItemUnchecked(type: string, callback: (item: TreeViewItem[]) => void) {
16+
subscribeToItemUnchecked(type: string, callback: (item: TreeViewItem[]) => void): void {
17+
onUnCheckedSubscribers[type] = onUnCheckedSubscribers[type] ?? [];
18+
1519
onUnCheckedSubscribers[type].push(callback);
1620
},
17-
21+
}
22+
23+
export const eventHub = {
1824
// Publish events if any subscriber listening for item checked
1925
onItemChecked(item: TreeViewItem): void {
2026
if (item.type == 'folder') {

src/components/treeView.vue/treeView.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {Vue, Component, Prop} from 'vue-property-decorator';
3737
import { TreeViewViewModel } from '@/businessLogic/treviewViewModel/treeViewViewModel'
3838
import { CheckedState, Customisations, ItemCheckedChangedEvent, TreeViewCreatedEventPayload, TreeViewItem } from '@/businessLogic/contracts/types';
3939
import { ItemCustomisations } from "@/businessLogic/itemCustomisations/itemCustomisations";
40+
import { eventManager } from '@/businessLogic/eventHub/explorerEventPublisher';
4041
4142
@Component
4243
export default class TreeView extends Vue {
@@ -46,7 +47,8 @@ export default class TreeView extends Vue {
4647
4748
created(): void {
4849
const payload: TreeViewCreatedEventPayload = {
49-
itemCustomisations: this.itemCustomisations
50+
itemCustomisations: this.itemCustomisations,
51+
eventManager
5052
};
5153
5254
this.$emit("created", payload);

0 commit comments

Comments
 (0)