Posts

Showing posts with the label API

Asynchronous Storage For All Browsers

I have finally implemented and successfully tested the IndexedDB fallback for Firefox so that now every browser, old or new, should be able to use this interface borrowed from localStorage API but made asynchronous. Asynchronous Key/Value Pairs The main purpose of this asyncStorage API is to store large amount of data as string , including base64 version of images or other files. As it is, usually, values are the bottleneck, RAM consumption speaking, while keys are rarely such big problem. However, while keys are retrieved asynchronously and in a non-blocking way, but kept in memory, respective values are always retrieved asynchronously in order to do not fill the available amount of RAM for our Web Application. Database Creation/Connection Nothing more than ... asyncStorage.create("my_db_name", function (db, numberOfItems) { // do stuff with the asyncStorage }); Storing An Item As it is for localStorage, but async asyncStorage.create("my_db_name", function (d...

On EventEmitter In node.js

Today I had a whole node.js session and I have spent a bit of time looking at current EventEmitter implementation. I have twitted already that it sucks as it is, and while it's really trivial to implement the same for any browser , I believe many mistakes have been made about the API . Here the list: on() is a shortcut for addListener but there is no off() as removeListener's shortcut (inconsistent) add/removeListener is not DOM friendly, we cannot reuse an EventEmitter in the browser without double checking if those methods exist removeAllListeners() accepts no arguments and cleans up the whole emitter but there is no way to retrieve all listeners via listeners() passing no arguments (again, inconsistent) there's no possibility to use handleEvent property, as already defined in the EventListener , once again objects are not reusable between client and server no duplicated checks for both addListener and removeListener, this is totally inconsistent against DOM Event...