frontend: move value assignment into Store constructor
This commit is contained in:
parent
ce4592c6c0
commit
efae331f99
1 changed files with 4 additions and 6 deletions
|
@ -2,8 +2,9 @@ import { writable } from "svelte/store";
|
||||||
import gateway, { GatewayEventType } from "./gateway";
|
import gateway, { GatewayEventType } from "./gateway";
|
||||||
|
|
||||||
class Store {
|
class Store {
|
||||||
constructor() {
|
constructor(value=null) {
|
||||||
this._handlers = [];
|
this._handlers = [];
|
||||||
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe(handler) {
|
subscribe(handler) {
|
||||||
|
@ -24,9 +25,7 @@ class Store {
|
||||||
|
|
||||||
class ChannelsStore extends Store {
|
class ChannelsStore extends Store {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super(gateway.channels || []);
|
||||||
|
|
||||||
this.value = gateway.channels || [];
|
|
||||||
|
|
||||||
gateway.subscribe(GatewayEventType.Ready, ({ channels }) => {
|
gateway.subscribe(GatewayEventType.Ready, ({ channels }) => {
|
||||||
this.value = channels;
|
this.value = channels;
|
||||||
|
@ -59,8 +58,7 @@ class ChannelsStore extends Store {
|
||||||
|
|
||||||
class GatewayStatusStore extends Store {
|
class GatewayStatusStore extends Store {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super({ open: gateway.open, ready: gateway.authenticated });
|
||||||
this.value = { open: gateway.open, ready: gateway.authenticated };
|
|
||||||
|
|
||||||
gateway.subscribe(GatewayEventType.Open, () => {
|
gateway.subscribe(GatewayEventType.Open, () => {
|
||||||
this.value.open = true;
|
this.value.open = true;
|
||||||
|
|
Loading…
Reference in a new issue