Skip to content

Commit 8fa9418

Browse files
author
Robert Jackson
committed
Use sessionStorage to make development simpler...
1 parent 9fd16ef commit 8fa9418

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

app/services/graph.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
import Ember from 'ember';
2+
import config from '../config/environment';
23
import heimdallGraph from 'heimdalljs-graph';
34

45
const {
56
getOwner
67
} = Ember;
78

9+
const STORAGE_KEY = `${config.storageVersion}_graph-data`;
10+
811
export default Ember.Service.extend({
12+
init() {
13+
this._super(...arguments);
14+
15+
let data = sessionStorage.getItem(STORAGE_KEY);
16+
if (data) {
17+
this.setGraph(JSON.parse(data));
18+
}
19+
},
20+
921
setGraph(data) {
1022
let graph = heimdallGraph.loadFromJSON(data);
1123

24+
sessionStorage.setItem(STORAGE_KEY, JSON.stringify(data));
25+
1226
this.set('data', data);
1327
this.set('graph', graph);
1428
},

config/environment.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ module.exports = function(environment) {
2020
APP: {
2121
// Here you can pass flags/options to your application instance
2222
// when it is created
23-
}
23+
},
24+
25+
// bump this when making incompatible changes in
26+
// localstorage / sessionStorage data formats
27+
storageVersion: 2
2428
};
2529

2630
if (environment === 'development') {

0 commit comments

Comments
 (0)