JSFiddle - React, Tailwind, and code Playground

by Chase Wilson

JavaScript

(function (win, doc){
  var timeouts = {}
  var Model.Local = new Class({
     Extends: Model
    ,initialize: function (localKey, data) {
      this.localKey = String(localKey)
      var localData = localStorage.getItem( this.localKey ) || {}

      this.parent( Object.extend(data,localData) )
    }
    ,set: function () {
      this.parent(arguments)
      clearTimeout(timeouts[this.localKey])
      timeouts[this.localKey] = setTimeout(this.save,100)
    }
    ,save: function () {
      localStorage.setItem( this.localKey, JSON.stringify( this.get('data') ) );
    }
  })
}(window, document))