UNPKG

@logo-elements/component-base

Version:

A set of mixins used by Logo Elements which is extended from Vaadin components.

72 lines (63 loc) 1.98 kB
/** * @license * Copyright LOGO YAZILIM SANAYİ VE TİCARET A.Ş. * * Save to the extent permitted by law, you may not use, copy, modify, * distribute or create derivative works of this material or any part * of it without the prior written consent of LOGO YAZILIM SANAYİ VE TİCARET A.Ş. Limited. * Any reproduction of this material must contain this notice. */ import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js'; /** * A mixin for connecting controllers to the element. * * @polymerMixin */ export const ControllerMixin = dedupingMixin( (superClass) => class ControllerMixinClass extends superClass { constructor() { super(); /** * @type {Set<import('lit').ReactiveController>} */ this.__controllers = new Set(); } /** @protected */ connectedCallback() { super.connectedCallback(); this.__controllers.forEach((c) => { c.hostConnected && c.hostConnected(); }); } /** @protected */ disconnectedCallback() { super.disconnectedCallback(); this.__controllers.forEach((c) => { c.hostDisconnected && c.hostDisconnected(); }); } /** * Registers a controller to participate in the element update cycle. * * @param {import('lit').ReactiveController} controller * @protected */ addController(controller) { this.__controllers.add(controller); // Call hostConnected if a controller is added after the element is attached. if (this.$ !== undefined && this.isConnected && controller.hostConnected) { controller.hostConnected(); } } /** * Removes a controller from the element. * * @param {import('lit').ReactiveController} controller * @protected */ removeController(controller) { this.__controllers.delete(controller); } } );