
Basil.js – Smart persistence layer - guillaumepotier
https://github.com/Wisembly/basil.js
======
mrinterweb
I would recommend Mozilla's localforage
[https://github.com/mozilla/localForage](https://github.com/mozilla/localForage).
Basil.js takes care of abstracting cookie, session, memory, and localstorage
storage options, but localforage provides an abstraction for localStorage,
WebSQL, or IndexedDB. With modern applications I find that I often want more
storage available. Cookie storage is limited at 4Kb, localStorage (5Mb),
sessionStorage (same as localStorage), IndexedDB (50Mb), and WebSQL (50Mb).
Localforage will automatically select the best available storage system for
the browser. While WebSQL and IndexedDB allow for advanced queries,
localforage must cater to the lowest common denominator, localStorage key
value pairs. While being restricted to key value pair storage, this is often
not a big concern considering how different the WebSQL and IndexedDB APIs are.

~~~
Tyrant505
Thank you for breaking it down like this. I never saw it layed out
~specifically like this.

------
mixonic
Synchronous persistence APIs should be considered dangerous. Often they solve
the immediate problem, but when you eventually need to move to an async
storage solution (and in JavaScript any significantly complex task eventually
becomes async) you are left with code that presumes sync behavior. This makes
it difficult to refactor.

Providing an API with callbacks or better yet promises forces you to write
future-safe code.

~~~
vivab0rg
This. I recently moved to localForage[1] and have been mostly satisfied so
far. Thanks Mozilla!

[1]:
[http://mozilla.github.io/localForage/](http://mozilla.github.io/localForage/)

~~~
cobalt2760
It might be a little bit "overkill" when you just want to perform storage only
on client device no? (Basil aim is not to override backend storage like REST
APIs)

------
prayerslayer
What about lawnchair?

[http://brian.io/lawnchair/](http://brian.io/lawnchair/)

------
rectangletangle
Lol, I made a library a while back that does the same thing
([https://github.com/rectangletangle/jSave](https://github.com/rectangletangle/jSave)).
Maybe it's a sign that a larger project needs to be started?

------
jonahx
So is this wrapper over cookie and localStorage that takes care of browser
differences and idiosyncrasies for you? Or is it more than that?

~~~
cobalt2760
It also ensure you that your usage of localstorage won't ever throw exceptions
and break all your thread in the case of cookie-less anonymized sessions

------
thomasjonas
There's a project with the same name out there:
[http://basiljs.ch/](http://basiljs.ch/) This made me wonder: how to deal with
similar named open source projects? Although the goals of both projects aren't
related in any sense it could cause for some confusion...

~~~
notduncansmith
Do lots of searching before naming your projects, I suppose. Surely he could
have used Rosemary.js, or Herb.js, or Bayleaf.js?

~~~
gcb0
or something even remotely related to ... who knows... data storage?

~~~
notduncansmith
Bah, ridiculous! Clearly you haven't received the memo, all Javascript
libraries are named exclusively by dart-board now.

------
cobalt2760
That seems promising. Would be great to have FIFO and LIFO storage mechanism
here like in redis!

~~~
nawitus
Why do you need a mechanism for that instead of using arrays?

~~~
cobalt2760
Instead of getting an array from storage, pushing a new item inside and then
storing it again, it could be nice to have directly this small mechaniam built
in to avoid this logic in the application.

~~~
nawitus
Hmm, that's true. The library could monkey patch .push (etc.), but it wouldn't
support setting the property directly with [index] (until Object.observe is
mainstream enough).

------
owenversteeg
Love the name. (For those that don't get the joke, basil is an extremely
persistent, almost weedlike plant.) That said, I think an async solution would
be better, like localforage.

------
thrush
Great idea. The next progression would be cross browser benchmarks, and
perhaps something suitable for browser extensions (unless this already works
for that use case).

------
elwell
Maybe I'm being dumb, but I think this could benefit from the inclusion of a
_Why?_ section.

------
iamkoby
looks great!

