diff --git a/public/eventable.js b/public/eventable.js deleted file mode 100644 index 2c53d59..0000000 --- a/public/eventable.js +++ /dev/null @@ -1,26 +0,0 @@ -export class Eventable -{ - constructor() - { - this._events = { }; - } - - on(eventName, handler) - { - if (!this._events[eventName]) - { - this._events[eventName] = [ ]; - } - - this._events[eventName].push(handler); - } - - emit(eventName, eventData) - { - let handlers = this._events[eventName] || [ ]; - for (let i = 0; i < handlers.length; i++) - { - handlers[i](eventData); - } - } -} diff --git a/public/main.js b/public/main.js index 19a4e9e..3b9f5df 100644 --- a/public/main.js +++ b/public/main.js @@ -13,15 +13,6 @@ let playing = false; // Project model/state let model = new Model(); -model.on('loading', () => { - // Stop playback to avoid glitching - stopPlayback(); - - // Show the Edit tab before loading the graph, - // so it can resize itself correctly - /* showTab('edit'); */ -}); - // Graph editor view let editor = new Editor(model); @@ -36,21 +27,17 @@ document.body.onload = function () if (window.location.hash) return; - let modelData = localStorage.getItem('model'); - if (!modelData) + let serializedModelData = localStorage.getItem('latestModelData'); + if (!serializedModelData) return; - if (model.deserialize(modelData)) { - console.log('model restored from previous session'); - } else { - console.warn('could not restore model from previous session'); - } + importModel(serializedModelData); } window.onunload = function () { // Save the graph when unloading the page - localStorage.setItem('model', model.serialize()); + localStorage.setItem('latestModelData', model.serialize()); } window.onkeydown = function (event) @@ -107,6 +94,18 @@ window.onkeydown = function (event) } } +export function importModel(serializedModelData) +{ + // Stop playback to avoid glitching + stopPlayback(); + + if (model.deserialize(serializedModelData)) { + console.log('model restored from previous session'); + } else { + console.warn('could not restore model from previous session'); + } +} + export function startPlayback() { if (playing) diff --git a/public/model.js b/public/model.js index e871df9..723b78b 100644 --- a/public/model.js +++ b/public/model.js @@ -60,7 +60,6 @@ or it's a special undoable action. */ import { assert, treeCopy, treeEq, isString, isObject } from './utils.js'; -import { Eventable } from './eventable.js'; /** * High-level description/scheme for each type of node @@ -639,12 +638,10 @@ export class Disconnect extends Action } /** Graph of nodes model, operates on internal state data */ -export class Model extends Eventable +export class Model { constructor() { - super(); - // List of views subscribed to model updates this.views = []; @@ -676,8 +673,6 @@ export class Model extends Eventable // Load the JSON state into the model load(state) { - this.emit('loading'); - // Current playback position this.playPos = 0;