Extract navigate mixin (#1865)

* Extract navigate to function

* Remove eventsmixin properly and side effects
This commit is contained in:
Paulus Schoutsen 2018-10-27 10:56:03 +02:00 committed by GitHub
parent 13c5724d7c
commit 35194cf345
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 12 deletions

14
src/common/navigate.ts Normal file
View File

@ -0,0 +1,14 @@
import { fireEvent } from "./dom/fire_event.js";
export const navigate = (
node: HTMLElement,
path: string,
replace: boolean = false
) => {
if (replace) {
history.replaceState(null, "", path);
} else {
history.pushState(null, "", path);
}
fireEvent(node, "location-changed");
};

View File

@ -1,5 +1,5 @@
import { dedupingMixin } from "@polymer/polymer/lib/utils/mixin.js";
import EventsMixin from "./events-mixin";
import { navigate } from "../common/navigate";
/*
* @polymerMixin
@ -7,14 +7,9 @@ import EventsMixin from "./events-mixin";
*/
export default dedupingMixin(
(superClass) =>
class extends EventsMixin(superClass) {
navigate(path, replace = false) {
if (replace) {
history.replaceState(null, null, path);
} else {
history.pushState(null, null, path);
}
this.fire("location-changed");
class extends superClass {
navigate(...args) {
navigate(this, ...args);
}
}
);

View File

@ -52,7 +52,7 @@ class HaConfigDashboard extends NavigateMixin(LocalizeMixin(PolymerElement)) {
<template is="dom-if" if="[[computeIsLoaded(hass, 'cloud')]]">
<paper-card>
<a href='/config/cloud' tabindex="-1">
<paper-item on-click="_navigate">
<paper-item>
<paper-item-body two-line="">
[[localize('ui.panel.config.cloud.caption')]]
<template is="dom-if" if="[[cloudStatus.logged_in]]">

View File

@ -8,6 +8,7 @@ import NavigateMixin from "../../../mixins/navigate-mixin.js";
import "./ha-user-picker.js";
import "./ha-user-editor.js";
import { fireEvent } from "../../../common/dom/fire_event.js";
/*
* @appliesMixin NavigateMixin
@ -68,8 +69,8 @@ class HaConfigUsers extends NavigateMixin(PolymerElement) {
_checkRoute(route) {
if (!route || route.path.substr(0, 6) !== "/users") return;
// prevent list gettung under toolbar
this.fire("iron-resize");
// prevent list getting under toolbar
fireEvent(this, "iron-resize");
this._debouncer = Debouncer.debounce(
this._debouncer,