PrefixTree

A PrefixTree is a transparent layer on top of a (scoped) baseClient.  It allows you to write as many documents as you want (tested up to about 20,000) without using any slashes in their paths.  So basically it’s then a key-value store, and it will “feel” like these documents are all in the base folder.  In reality, PrefixTree creates a folder tree based on key prefixes, and translates keyToPath when going from your module code to the baseClient, and pathToKey when coming back from the baseClient to your module (e.g. in change events).

To use it, simply construct it from a BaseClient, for instance the privateClient which you receive when calling defineModule:

var prefixTree = new PrefixTree(privClient);

Then, you can replace all the calls you would usually do to the privClient, and do them to the prefixTree instead. storeObject/getObject, storeFile/getFile, remove, and on are all available. getListing and getAll are not, because they operate on folders, and PrefixTree exposes a non-hierarchical key-value store.

To receive one change event for each item currently in the store (e.g. to populate an in-memory representation), you can call:

prefixTree.fireInitial()

Summary
PrefixTreeA PrefixTree is a transparent layer on top of a (scoped) baseClient.
Functions
setMaxLeavesControl the internal maxLeaves variable.
getFileThe equivalent of BaseClient.getFile
storeFileThe equivalent of BaseClient.storeFile
getObjectThe equivalent of BaseClient.getObject
removeThe equivalent of BaseClient.remove
storeObjectThe equivalent of BaseClient.storeObject
onThe equivalent of BaseClient.on
fireInitialWill trigger one change event for each document currently in the tree.

Functions

setMaxLeaves

setMaxLeaves: function(val)

Control the internal maxLeaves variable.  To get a small tree with large folders, choose a high value.  If you prefer a large tree with small folders, choose a low value.  This influences the ideal number of documents (tree leaves) in any folder, it does not limit the number of subfolders.  By default, maxLeaves = 5.

Parameters

valnumber, the value to set maxLeaves to.

getFile

getFile: function(key)

The equivalent of BaseClient.getFile

Parameters

keystring, the key, corresponding to the path (should not contain slashes).

Returns

A promise like the one from BaseClient.getFile.

storeFile

storeFile: function(mimeType,
key,
body)

The equivalent of BaseClient.storeFile

Parameters

mimeTypestring, like for BaseClient.storeFile
keystring, the key, corresponding to the path (should not contain slashes).
bodystring or ArrayBuffer, like for BaseClient.storeFile

Returns

A promise like the one from BaseClient.storeFile.

getObject

getObject: function(key)

The equivalent of BaseClient.getObject

Parameters

keystring, the key, corresponding to the path (should not contain slashes).

Returns

A promise like the one from BaseClient.getObject.

remove

remove: function(key)

The equivalent of BaseClient.remove

Parameters

keystring, the key, corresponding to the path (should not contain slashes).

Returns

A promise like the one from BaseClient.remove.

storeObject

storeObject: function(typeAlias,
key,
obj)

The equivalent of BaseClient.storeObject

Parameters

typeAliasstring, like for BaseClient.storObject
keystring, the key, corresponding to the path (should not contain slashes).
bodyobject, like for BaseClient.storeObject

Returns

A promise like the one from BaseClient.storeFile.

on

on: function(event,
cb)

The equivalent of BaseClient.on

Parameters

eventNamestring, like for BaseClient.on
cbfunction, like for BaseClient.on

Returns

A promise like the one from BaseClient.getObject, except that the event will contain a ‘key’ field, corresponding to the path.

fireInitial

fireInitial: function(dirs)

Will trigger one change event for each document currently in the tree.  These events will have origin ‘local’.

Parameters

dirsto be left undefined
setMaxLeaves: function(val)
Control the internal maxLeaves variable.
getFile: function(key)
The equivalent of BaseClient.getFile
storeFile: function(mimeType,
key,
body)
The equivalent of BaseClient.storeFile
getObject: function(key)
The equivalent of BaseClient.getObject
remove: function(key)
The equivalent of BaseClient.remove
storeObject: function(typeAlias,
key,
obj)
The equivalent of BaseClient.storeObject
on: function(event,
cb)
The equivalent of BaseClient.on
fireInitial: function(dirs)
Will trigger one change event for each document currently in the tree.
Close