Skip to content

Commit

Permalink
Moving away from callback-based model loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlitty committed Jun 18, 2021
1 parent 22ddf46 commit ef93697
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 49 deletions.
26 changes: 0 additions & 26 deletions public/eventable.js

This file was deleted.

33 changes: 16 additions & 17 deletions public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions public/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit ef93697

Please sign in to comment.