1

ModelStorageDelegate

Objective
  • ModelCookieDelegate
  1. function ModelStorageDelegate(mode = 'session') {
  2.     if (! (mode == 'session' || mode == 'local'))
  3.         throw new TypeError();
  4.  
  5.     this._storage = mode == 'local' ? localStorage : sessionStorage;
  6. }
  7.  
  8. ModelStorageDelegate.prototype = Object.create(Objective.prototype);
  9.  
  10. Object.defineProperty(ModelStorageDelegate.prototype, 'constructor', { value: ModelStorageDelegate, enumerable: false, writable: true });
  11.  
  12. ModelStorageDelegate.prototype.isSaved = function(model) {
  13.     return this._storage.getItem(model.name) !== null;
  14. }
  15.  
  16. ModelStorageDelegate.prototype.readIn = function(model) {
  17.     let json = this._storage.getItem(model.name);
  18.  
  19.     if (json !== null)
  20.         model.set(JSON.parse(json));
  21. }
  22.  
  23. ModelStorageDelegate.prototype.writeOut = function(model) {
  24.     this._storage.setItem(model.name, JSON.stringify(model.get()));
  25.  
  26.     model.changed = false;
  27. }
  28.  
  29. ModelStorageDelegate.prototype.clearSave = function(model) {
  30.     this._storage.removeItem(model.name);
  31. }
SEE ALSO

ModelCookieDelegate, Model, Editor

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].