UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

35 lines (34 loc) 1.44 kB
/** * DevExtreme (esm/__internal/integration/knockout/event_registrator.js) * Version: 25.2.7 * Build date: Tue May 05 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import eventRegistratorCallbacks from "../../../common/core/events/core/event_registrator_callbacks"; import $ from "../../../core/renderer"; import { isPlainObject } from "../../core/utils/m_type"; import eventsEngine from "../../events/core/m_events_engine"; import { addNamespace } from "../../events/utils/index"; import ko from "knockout"; if (ko) { eventRegistratorCallbacks.add(name => { const koBindingEventName = addNamespace(name, `${name}Binding`); ko.bindingHandlers[name] = { update(element, valueAccessor, allBindingsAccessor, viewModel) { const $element = $(element); const unwrappedValue = ko.utils.unwrapObservable(valueAccessor()); const eventSource = unwrappedValue.execute ? unwrappedValue.execute : unwrappedValue; eventsEngine.off($element, koBindingEventName); eventsEngine.on($element, koBindingEventName, isPlainObject(unwrappedValue) ? unwrappedValue : {}, e => { eventSource.call(viewModel, viewModel, e) }) } } }) }