From 89c9458d271e926d8f8c1432581aa4876bf6f749 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Thu, 23 Jun 2016 13:30:02 -0700 Subject: [PATCH] Reload on reconnect --- src/js/app.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/js/app.js b/src/js/app.js index fd7ea04..0e998bd 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -34,27 +34,37 @@ module.exports = new Vue({ events: { 'config-changed': function () {this.modified = true;}, - 'send': function (msg) {if (this.status == 'connected') this.sock.send(msg)} + + + send: function (msg) { + if (this.status == 'connected') this.sock.send(msg) + }, + + + connected: function () {this.update()} }, ready: function () { + $(window).on('hashchange', this.parse_hash); this.connect(); + }, - $.get('/config-template.json').success(function (data, status, xhr) { - this.template = data; - api.get('load').done(function (data) { - this.config = data; + methods: { + update: function () { + $.get('/config-template.json').success(function (data, status, xhr) { + this.template = data; - this.parse_hash(); - $(window).on('hashchange', this.parse_hash); - }.bind(this)) - }.bind(this)) - }, + api.get('load').done(function (data) { + this.config = data; + + this.parse_hash(); + }.bind(this)) + }.bind(this)) + }, - methods: { connect: function () { this.sock = new Sock('//' + window.location.host + '/ws'); @@ -64,6 +74,7 @@ module.exports = new Vue({ this.sock.onopen = function (e) { this.status = 'connected'; + this.$emit(this.status); this.$broadcast(this.status); }.bind(this); -- 2.27.0