Skip to content

Commit 3564bfc

Browse files
committed
Rewritten livearea binding handler into behavior.
1 parent 728a4c2 commit 3564bfc

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/ko/bindingHandlers/bindingHandlers.livearea.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
import { EventManager, Events } from "@paperbits/common/events";
1+
import { LiveAreaBehavior } from "@paperbits/common/behaviors/liveAreaBehavior";
2+
import { EventManager } from "@paperbits/common/events";
23
import * as ko from "knockout";
34

4-
55
export class LiveAreaBindingHandler {
66
constructor(eventManager: EventManager) {
77
ko.bindingHandlers["livearea"] = {
8-
init: (element: HTMLElement, valueAccessor: () => (data: unknown) => void, allBindings, viewModel) => {
9-
const notificationHandler = (notification: string) => {
10-
element.innerText = notification;
11-
}
12-
13-
eventManager.addEventListener(Events.NotificationRequest, notificationHandler);
8+
init: (element: HTMLElement) => {
9+
const behaviorHandle = LiveAreaBehavior.attach(element, eventManager);
1410

1511
ko.utils.domNodeDisposal.addDisposeCallback(element, () => {
16-
eventManager.removeEventListener(Events.NotificationRequest, notificationHandler);
17-
})
12+
behaviorHandle.detach();
13+
});
1814
}
1915
};
2016
}

0 commit comments

Comments
 (0)