lit#PropertyValues TypeScript Examples

The following examples show how to use lit#PropertyValues. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: editor.ts    From power-distribution-card with MIT License 6 votes vote down vote up
/**
   * This is for Checking if something relevant has changed and updating variables accordingly
   * @param changedProps The Changed Property Values
   */
  protected updated(changedProps: PropertyValues): void {
    super.updated(changedProps);
    const attachedChanged = changedProps.has('_attached');
    const entitiesChanged = changedProps.has('_config');
    if (!entitiesChanged && !attachedChanged) {
      return;
    }

    if (attachedChanged && !this._attached) {
      // Tear down sortable, if available
      this._sortable?.destroy();
      this._sortable = undefined;
      return;
    }

    if (!this._sortable && this._config?.entities) {
      this._createSortable();
      return;
    }

    if (entitiesChanged && this._subElementEditor == undefined) {
      this._handleEntitiesChanged();
    }
  }
Example #2
Source File: power-distribution-card.ts    From power-distribution-card with MIT License 6 votes vote down vote up
protected updated(changedProps: PropertyValues): void {
    super.updated(changedProps);
    if (!this._card || (!changedProps.has('hass') && !changedProps.has('editMode'))) {
      return;
    }
    if (this.hass) {
      this._card.hass = this.hass;
    }
  }
Example #3
Source File: helpers.ts    From floor3d-card with MIT License 6 votes vote down vote up
// Check if config or Entity changed
export function hasConfigOrEntitiesChanged(element: any, changedProps: PropertyValues, forceUpdate: boolean): boolean {
  if (changedProps.has('config') || forceUpdate) {
    return true;
  }
  for (const config of element._configArray) {
    if (config.entity) {
      const oldHass = changedProps.get('hass') as HomeAssistant | undefined;
      if (oldHass) {
        if (oldHass.states[config.entity] !== element.hass!.states[config.entity]) {
          return true;
        } else {
          continue;
        }
      }
      return true;
    }
  }
  return false;
}
Example #4
Source File: ngm-cam-configuration.ts    From ngm with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
updated(changedProperties: PropertyValues) {
    if (this.viewer && !this.unlistenPostRender) {
      this.scene = this.viewer.scene;
      this.handler = new ScreenSpaceEventHandler(this.viewer!.canvas);
      this.unlistenPostRender = this.scene.postRender.addEventListener(() => this.updateFromCamera());
      this.updateFromCamera();
    }
    if (changedProperties.has('lockType'))
      NavToolsStore.setNavLockType(this.lockType);
    super.updated(changedProperties);
  }
Example #5
Source File: ngm-app.ts    From ngm with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected updated(changedProperties: PropertyValues) {
    if (changedProperties.has('showCamConfig')) {
      if (this.showCamConfig) {
        (<HTMLElement>document.querySelector('.ngm-cam-lock-info'))?.parentElement?.remove();
      } else if (this.camConfigElement.lockType) {
        let message = '';
        switch (this.camConfigElement.lockType) {
          case 'angle':
            message = i18next.t('cam_lock_info_angle');
            break;
          case 'elevation':
            message = i18next.t('cam_lock_info_elevation');
            break;
          case 'move':
            message = i18next.t('cam_lock_info_move');
            break;
          case 'pitch':
            message = i18next.t('cam_lock_info_pitch');
            break;
        }
        showSnackbarInfo(message,
          {
            displayTime: 0,
            class: 'ngm-cam-lock-info',
            actions: [
              {
                text: i18next.t('app_cancel_btn_label'),
                click: () => this.camConfigElement.disableLock()
              }]
          });
        // closeOnClick doesn't work with actions
        document.querySelector('.ngm-cam-lock-info')?.addEventListener('click', () => {
          (<HTMLElement>document.querySelector('.ngm-cam-lock-info'))?.parentElement?.remove();
        });
      }
    }
    super.updated(changedProperties);
  }
Example #6
Source File: ngm-draw-section.ts    From ngm with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
update(changedProperties: PropertyValues) {
    if (changedProperties.has('enabledTypes') && this.enabledTypes) {
      this.shownDrawTypes = this.drawGeometries.filter(geom => this.enabledTypes!.includes(<GeometryTypes>geom.type));
    }
    if (this.draw && changedProperties.has('hidden') && !changedProperties.get('hidden')) {
      this.draw.active = false;
      this.draw.clear();
    }
    super.update(changedProperties);
  }
Example #7
Source File: ngm-toolbox.ts    From ngm with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected update(changedProperties: PropertyValues) {
    const resumeSlicing = !this.slicerElement || (this.forceSlicingToolOpen && this.slicerElement?.sceneSlicingActive);
    if (!resumeSlicing && changedProperties.has('toolsHidden') && !this.toolsHidden) {
      if (this.activeTool === 'slicing' && this.slicerElement) {
        this.slicerElement.slicer?.deactivateDrawing();
        if (this.slicerElement.slicingEnabled) {
          this.slicerElement.toggleSlicer();
        }
      }
      this.activeTool = undefined;
      document.querySelector('.ngm-open-slicing-toast')?.parentElement?.remove();
    } else if (this.forceSlicingToolOpen)
      this.forceSlicingToolOpen = false;
    super.update(changedProperties);
  }
Example #8
Source File: compass-card.ts    From compass-card with MIT License 6 votes vote down vote up
protected shouldUpdate(changedProps: PropertyValues): boolean {
    if (changedProps.has('_config')) {
      return true;
    }
    if (changedProps.has('_hass')) {
      const newHass = changedProps.get('_hass') as HomeAssistant;
      for (const entity in this.entities) {
        if (newHass.states[entity].last_updated !== this._hass.states[entity].last_updated) {
          return true;
        }
      }
    }
    return false;
  }
Example #9
Source File: component.ts    From xiome with MIT License 5 votes vote down vote up
firstUpdated(changes: PropertyValues) {
		super.firstUpdated(changes)
		this.init()
	}
Example #10
Source File: ngm-cam-coordinates.ts    From ngm with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
updated(changedProperties: PropertyValues) {
    $(this.dropdown).dropdown();
    super.updated(changedProperties);
  }