keeweb/app/scripts/models/runtime-data-model.js

31 lines
745 B
JavaScript
Raw Normal View History

2019-09-15 14:16:32 +02:00
import Backbone from 'backbone';
import { SettingsStore } from 'comp/settings/settings-store';
2016-03-27 14:57:22 +02:00
2017-01-31 07:50:28 +01:00
const RuntimeDataModel = Backbone.Model.extend({
2016-03-27 14:57:22 +02:00
defaults: {},
2019-08-18 10:17:09 +02:00
initialize() {
2016-03-27 14:57:22 +02:00
this.listenTo(this, 'change', this.save);
},
2019-08-18 10:17:09 +02:00
load() {
return SettingsStore.load('runtime-data').then(data => {
if (data) {
2019-01-06 23:33:09 +01:00
if (data.cookies) {
2019-01-06 23:34:39 +01:00
// we're not using cookies here now
2019-01-06 23:33:09 +01:00
delete data.cookies;
}
2019-08-16 23:05:39 +02:00
this.set(data, { silent: true });
}
});
},
2019-08-18 10:17:09 +02:00
save() {
2016-03-27 14:57:22 +02:00
SettingsStore.save('runtime-data', this.attributes);
}
});
RuntimeDataModel.instance = new RuntimeDataModel();
2019-09-15 14:16:32 +02:00
export { RuntimeDataModel };