Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to persist value to localStorage #3

Open
positlabs opened this issue Feb 12, 2016 · 2 comments
Open

Option to persist value to localStorage #3

positlabs opened this issue Feb 12, 2016 · 2 comments

Comments

@positlabs
Copy link

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
Copy link
Owner

lo-th commented Feb 12, 2016

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

@coderofsalvation
Copy link

coderofsalvation commented Jul 14, 2019

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) })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants