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

29 lines
678 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() {
2020-06-01 16:53:51 +02:00
return SettingsStore.load('runtime-data').then((data) => {
if (data) {
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:56:58 +02:00
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 };