lo-th / uil

simple javascript ui
http://lo-th.github.io/uil/
MIT License
555 stars 50 forks source link

Option to persist value to localStorage #3

Open positlabs opened 8 years ago

positlabs commented 8 years ago

For convenience, it would be nice to have persistent values on controls. When the user reloads the page, the values can be loaded back in from localStorage.

ui.add('title', { name:'Title', persist: true});

lo-th commented 8 years ago

yes sound like saving systeme, have to make some research about

coderofsalvation commented 5 years ago

I'm not sure whether datastorage needs to be part of an ui-library. Why not just use the callbacks. For example, something like this:

var data = {}

function load(){
  var d = window.localStorage.getItem('data')
  if( d ) data = JSON.parse(d)
}

function save(key,value){ // key will be preloaded by bind(..) later
  data[key] = value
  window.localStorage.setItem('data', JSON.stringify(data) )
}

// init UIL
load()
for( var key in data )
  ui.add(i,{name:key, value: data[key], callback: save.bind(null,key) })