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

34 lines
865 B
JavaScript
Raw Normal View History

2019-09-17 21:50:46 +02:00
import { Model } from 'framework/model';
2019-09-15 14:16:32 +02:00
import { SettingsStore } from 'comp/settings/settings-store';
2016-03-27 14:57:22 +02:00
2019-09-17 21:50:46 +02:00
class RuntimeDataModel extends Model {
constructor() {
super();
this.on('change', () => this.save());
}
2016-03-27 14:57:22 +02:00
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-09-17 21:50:46 +02:00
}
2019-08-18 10:17:09 +02:00
save() {
2019-09-17 21:50:46 +02:00
console.log('save', this);
// SettingsStore.save('runtime-data', this);
2016-03-27 14:57:22 +02:00
}
2019-09-17 21:50:46 +02:00
}
RuntimeDataModel.defineModelProperties({}, { extensions: true });
2016-03-27 14:57:22 +02:00
2019-09-17 21:50:46 +02:00
const instance = new RuntimeDataModel();
window.RuntimeDataModel = instance;
2016-03-27 14:57:22 +02:00
2019-09-17 21:50:46 +02:00
export { instance as RuntimeDataModel };