mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-20 15:56:35 +00:00
Don't sync dev tools service data between tabs (#10980)
This commit is contained in:
parent
b0b953bfac
commit
648c02e622
@ -5,7 +5,10 @@ import type { ClassElement } from "../../types";
|
|||||||
type Callback = (oldValue: any, newValue: any) => void;
|
type Callback = (oldValue: any, newValue: any) => void;
|
||||||
|
|
||||||
class Storage {
|
class Storage {
|
||||||
constructor() {
|
constructor(subscribe = true) {
|
||||||
|
if (!subscribe) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
window.addEventListener("storage", (ev: StorageEvent) => {
|
window.addEventListener("storage", (ev: StorageEvent) => {
|
||||||
if (ev.key && this.hasKey(ev.key)) {
|
if (ev.key && this.hasKey(ev.key)) {
|
||||||
this._storage[ev.key] = ev.newValue
|
this._storage[ev.key] = ev.newValue
|
||||||
@ -80,15 +83,18 @@ class Storage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const storage = new Storage();
|
const subscribeStorage = new Storage();
|
||||||
|
|
||||||
export const LocalStorage =
|
export const LocalStorage =
|
||||||
(
|
(
|
||||||
storageKey?: string,
|
storageKey?: string,
|
||||||
property?: boolean,
|
property?: boolean,
|
||||||
|
subscribe = true,
|
||||||
propertyOptions?: PropertyDeclaration
|
propertyOptions?: PropertyDeclaration
|
||||||
): any =>
|
): any =>
|
||||||
(clsElement: ClassElement) => {
|
(clsElement: ClassElement) => {
|
||||||
|
const storage = subscribe ? subscribeStorage : new Storage(false);
|
||||||
|
|
||||||
const key = String(clsElement.key);
|
const key = String(clsElement.key);
|
||||||
storageKey = storageKey || String(clsElement.key);
|
storageKey = storageKey || String(clsElement.key);
|
||||||
const initVal = clsElement.initializer
|
const initVal = clsElement.initializer
|
||||||
@ -97,7 +103,7 @@ export const LocalStorage =
|
|||||||
|
|
||||||
storage.addFromStorage(storageKey);
|
storage.addFromStorage(storageKey);
|
||||||
|
|
||||||
const subscribe = (el: ReactiveElement): UnsubscribeFunc =>
|
const subscribeChanges = (el: ReactiveElement): UnsubscribeFunc =>
|
||||||
storage.subscribeChanges(storageKey!, (oldValue) => {
|
storage.subscribeChanges(storageKey!, (oldValue) => {
|
||||||
el.requestUpdate(clsElement.key, oldValue);
|
el.requestUpdate(clsElement.key, oldValue);
|
||||||
});
|
});
|
||||||
@ -131,17 +137,19 @@ export const LocalStorage =
|
|||||||
configurable: true,
|
configurable: true,
|
||||||
},
|
},
|
||||||
finisher(cls: typeof ReactiveElement) {
|
finisher(cls: typeof ReactiveElement) {
|
||||||
if (property) {
|
if (property && subscribe) {
|
||||||
const connectedCallback = cls.prototype.connectedCallback;
|
const connectedCallback = cls.prototype.connectedCallback;
|
||||||
const disconnectedCallback = cls.prototype.disconnectedCallback;
|
const disconnectedCallback = cls.prototype.disconnectedCallback;
|
||||||
cls.prototype.connectedCallback = function () {
|
cls.prototype.connectedCallback = function () {
|
||||||
connectedCallback.call(this);
|
connectedCallback.call(this);
|
||||||
this[`__unbsubLocalStorage${key}`] = subscribe(this);
|
this[`__unbsubLocalStorage${key}`] = subscribeChanges(this);
|
||||||
};
|
};
|
||||||
cls.prototype.disconnectedCallback = function () {
|
cls.prototype.disconnectedCallback = function () {
|
||||||
disconnectedCallback.call(this);
|
disconnectedCallback.call(this);
|
||||||
this[`__unbsubLocalStorage${key}`]();
|
this[`__unbsubLocalStorage${key}`]();
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
if (property) {
|
||||||
cls.createProperty(clsElement.key, {
|
cls.createProperty(clsElement.key, {
|
||||||
noAccessor: true,
|
noAccessor: true,
|
||||||
...propertyOptions,
|
...propertyOptions,
|
||||||
|
@ -31,9 +31,9 @@ export class DialogTryTts extends LitElement {
|
|||||||
|
|
||||||
@query("#message") private _messageInput?: PaperTextareaElement;
|
@query("#message") private _messageInput?: PaperTextareaElement;
|
||||||
|
|
||||||
@LocalStorage("cloudTtsTryMessage") private _message!: string;
|
@LocalStorage("cloudTtsTryMessage", false, false) private _message!: string;
|
||||||
|
|
||||||
@LocalStorage("cloudTtsTryTarget") private _target!: string;
|
@LocalStorage("cloudTtsTryTarget", false, false) private _target!: string;
|
||||||
|
|
||||||
public showDialog(params: TryTtsDialogParams) {
|
public showDialog(params: TryTtsDialogParams) {
|
||||||
this._params = params;
|
this._params = params;
|
||||||
|
@ -38,10 +38,10 @@ class HaPanelDevService extends LitElement {
|
|||||||
|
|
||||||
@state() private _uiAvailable = true;
|
@state() private _uiAvailable = true;
|
||||||
|
|
||||||
@LocalStorage("panel-dev-service-state-service-data", true)
|
@LocalStorage("panel-dev-service-state-service-data", true, false)
|
||||||
private _serviceData?: ServiceAction = { service: "", target: {}, data: {} };
|
private _serviceData?: ServiceAction = { service: "", target: {}, data: {} };
|
||||||
|
|
||||||
@LocalStorage("panel-dev-service-state-yaml-mode", true)
|
@LocalStorage("panel-dev-service-state-yaml-mode", true, false)
|
||||||
private _yamlMode = false;
|
private _yamlMode = false;
|
||||||
|
|
||||||
@query("ha-yaml-editor") private _yamlEditor?: HaYamlEditor;
|
@query("ha-yaml-editor") private _yamlEditor?: HaYamlEditor;
|
||||||
|
@ -38,7 +38,7 @@ class PanelMediaBrowser extends LitElement {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@LocalStorage("mediaBrowseEntityId")
|
@LocalStorage("mediaBrowseEntityId", true, false)
|
||||||
private _entityId = BROWSER_PLAYER;
|
private _entityId = BROWSER_PLAYER;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user