AriaFallah / mobx-store

A data store with declarative querying, observable state, and easy undo/redo.
MIT License
282 stars 9 forks source link

A question on IndexedDB #22

Closed giacomorebonato closed 8 years ago

giacomorebonato commented 8 years ago

It seems to me that localStorage is always mentioned for data persistence in a browser.
What is the reason why nobody talks about IndexedDB?
Do the benchmark discourage the use? I love this project and MobX and I hope I can contribute.

AriaFallah commented 8 years ago

Oh well to be honest I haven't heard about it until now. I guess one huge reason it's not used is browser support http://caniuse.com/#feat=indexeddb.

Also localstorage is only in the repo and in the examples because I needed it for myself, not because I recommend it over anything else. It's really trivial to implement if you look at the source: https://github.com/AriaFallah/mobx-store/blob/master/src/localstorage.js

// @flow

function read(source: string) {
  const data = localStorage.getItem(source)
  if (data) {
    return JSON.parse(data)
  }
  return {}
}

function write(dest: string, store: Object) {
  return localStorage.setItem(dest, JSON.stringify(store.toJs()))
}

export default { read, write }

I hope that answers your questions.

giacomorebonato commented 8 years ago

Yes, thank you!