News for hackers. Stuff that matters.
Re:Basil.js – Smart persistence layer by mrinterweb on Saturday July 26, 2014 @02:04PM (#8090291)
I would recommend Mozilla's 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.
Re:Basil.js – Smart persistence layer by Tyrant505 on Saturday July 26, 2014 @02:08PM (#8090305)
Thank you for breaking it down like this. I never saw it layed out ~specifically like this.
Re:Basil.js – Smart persistence layer by mixonic on Saturday July 26, 2014 @09:24AM (#8089660)
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.

Re:Basil.js – Smart persistence layer by vivab0rg on Saturday July 26, 2014 @10:17AM (#8089777)
This. I recently moved to localForage[1] and have been mostly satisfied so far. Thanks Mozilla!

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

Re:Basil.js – Smart persistence layer by cobalt2760 on Saturday July 26, 2014 @10:51AM (#8089841)
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)
Re:Basil.js – Smart persistence layer by nawitus on Saturday July 26, 2014 @12:12PM (#8090025)
That's a good point. The same issue seems to exist with almost every JavaScript function interface. Whether or not a function is synchronous or asynchronous seems to be an implementation detail (at least in theory), but that fact must be exposed in the function interface.

I think the main issue is actually with language design. Callbacks and promises are not decent ways to handle asynchronity in my opinion. Perhaps it could be abstracted away in the language itself in a way that the function interface would be identical for both "sync" and async functions..

Re:Basil.js – Smart persistence layer by ef4 on Saturday July 26, 2014 @06:02PM (#8090965)
I came here to say the exact same thing.

Even if you're using synchronous storage, wrap it in an asynchronous API and save yourself a world of hurt later.

Re:Basil.js – Smart persistence layer by prayerslayer on Saturday July 26, 2014 @12:20PM (#8090041)
What about lawnchair?

http://brian.io/lawnchair/

Re:Basil.js – Smart persistence layer by rectangletangle on Saturday July 26, 2014 @05:22PM (#8090848)
Lol, I made a library a while back that does the same thing (https://github.com/rectangletangle/jSave). Maybe it's a sign that a larger project needs to be started?
Re:Basil.js – Smart persistence layer by jonahx on Saturday July 26, 2014 @01:37PM (#8090237)
So is this wrapper over cookie and localStorage that takes care of browser differences and idiosyncrasies for you? Or is it more than that?
Re:Basil.js – Smart persistence layer by cobalt2760 on Saturday July 26, 2014 @02:22PM (#8090341)
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
Re:Basil.js – Smart persistence layer by thomasjonas on Saturday July 26, 2014 @01:22PM (#8090202)
There's a project with the same name out there: 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...
Re:Basil.js – Smart persistence layer by notduncansmith on Saturday July 26, 2014 @02:58PM (#8090432)
Do lots of searching before naming your projects, I suppose. Surely he could have used Rosemary.js, or Herb.js, or Bayleaf.js?
Re:Basil.js – Smart persistence layer by gcb0 on Saturday July 26, 2014 @11:31PM (#8091874)
or something even remotely related to ... who knows... data storage?
Re:Basil.js – Smart persistence layer by notduncansmith on Sunday July 27, 2014 @08:41AM (#8092581)
Bah, ridiculous! Clearly you haven't received the memo, all Javascript libraries are named exclusively by dart-board now.
Re:Basil.js – Smart persistence layer by cobalt2760 on Saturday July 26, 2014 @09:01AM (#8089625)
That seems promising. Would be great to have FIFO and LIFO storage mechanism here like in redis!
Re:Basil.js – Smart persistence layer by nawitus on Saturday July 26, 2014 @12:13PM (#8090027)
Why do you need a mechanism for that instead of using arrays?
Re:Basil.js – Smart persistence layer by cobalt2760 on Saturday July 26, 2014 @12:21PM (#8090046)
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.
Re:Basil.js – Smart persistence layer by nawitus on Saturday July 26, 2014 @03:46PM (#8090548)
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).
Re:Basil.js – Smart persistence layer by owenversteeg on Saturday July 26, 2014 @11:38PM (#8091885)
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.
Re:Basil.js – Smart persistence layer by thrush on Saturday July 26, 2014 @02:33PM (#8090371)
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).
Re:Basil.js – Smart persistence layer by elwell on Saturday July 26, 2014 @04:28PM (#8090669)
Maybe I'm being dumb, but I think this could benefit from the inclusion of a Why? section.
Re:Basil.js – Smart persistence layer by iamkoby on Saturday July 26, 2014 @11:18AM (#8089893)
looks great!