i’m developing three constructs which may be of use to other module developers:
imagine you want to store 10,000 objects. putting them all in one directory becomes inefficient. PrefixTree creates a small folder tree based on key prefix. For instance, where the PrefixTree has depth 3, the path “tree/foobar” will be stored as “tree/f/o/o/_bar”. the nice thing about PrefixTree is that it’s transparent. you put it in front of a baseClient, and it translates keys to paths and paths back to keys. The depth of the tree is adjusted automatically; whenever a certain leaf becomes too busy, it starts growing subfolders.
even when using promises, coding with asynchronous functions can be verbose and cumbersome. If all you want to do is store something and retrieve it, then use a SyncedVar. it has a synchronous set() method and a synchronous get() method. SyncedVar uses asynchronous synchronisation for write, and change events for read. just make sure you wait for the initial sync to be ready before calling get(), or it will throw an exception.
get(key) and a synchronous
set(key, val) function. internally it uses a PrefixTree to make sure you can store loads of keys in it without bogging down the sync cycle.
these utils are still under development, i’m using them in the contacts and money modules. I’ll publish all of it when it’s ready.