MyDB client component
MyDB client component.
$ npm install mydb-client
Compile with browserify.
var mydb = require('mydb')('mydb.host.com');
mydb.get('/woot/woot');
Connects to the mydb server
listening on url
.
If a parameter is not supplied it will connect to window.location
Alternatively, an engine.io client options object can be supplied.
Creates a Document
by subscribing to the supplied url
.
Supplying a url
is optional, if a vanilla document is desired. See
Document#load
below.
Each document represents a subscription to a given resource URL.
Returns the associated manager.
Returns the sebscription id.
unloaded
: no subscription (default when no url
was provided)loading
: loading a resourceloaded
: resource is loadedunloading
: subscription is being destroyedReturns the url
this document is loaded from / loading.
Loads a document from the given URL. If fn
is supplied, it's passed
to ready
.
Reloads from the URL that was previously given to Document#load
. Useful if a given endpoint can return different documents depending on the circumstances. Example: a /me
route that returns the currently signed-in user.
Calls the supplied fn
when the resource is loaded. If the resource
is already loaded, the function is fired on the next tick.
Returns the value of the given key
, which can use dot
notation.
It throws if the document is not loaded.
If fn
is supplied, ready
is called first, and the value is passed
to the callback.
Subscribes to changes for the given key
.
fn
gets called upon any operation.value
propertylog
object. For example, if the operation is a $push
, theafter
). For example, if the operation is acting on an array,log
objectCalls ready
, then calls fn
with the initial value of the given
key
, and subscribes to subsequent change events for key
.
Calls ready
, then calls fn
for each value of the array found under
key
.
Destroys this subscription. fn
gets called when the unsubscription
for the current id is confirmed.
MIT