GithubHelp home page GithubHelp logo

mydb-client's Introduction

This repository is no longer maintained

mydb-client

MyDB client component.

Installation

$ npm install mydb-client

Compile with browserify.

Example

var mydb = require('mydb')('mydb.host.com');
mydb.get('/woot/woot');

API

Manager([url|options])

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.

Manager#get(url)

Creates a Document by subscribing to the supplied url. Supplying a url is optional, if a vanilla document is desired. See Document#load below.

Document

Each document represents a subscription to a given resource URL.

Document#$manager()

Returns the associated manager.

Document#$sid()

Returns the sebscription id.

Document#$readyState()

  • unloaded: no subscription (default when no url was provided)
  • loading: loading a resource
  • loaded: resource is loaded
  • unloading: subscription is being destroyed

Document#$url()

Returns the url this document is loaded from / loading.

Document#load(url[, fn])

Loads a document from the given URL. If fn is supplied, it's passed to ready.

Document#reload([fn])

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.

Document#ready(fn)

Calls the supplied fn when the resource is loaded. If the resource is already loaded, the function is fired on the next tick.

Document#get(key[, fn])

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.

Document#on(key[, op], fn)

Subscribes to changes for the given key.

  • If no operator is supplied, fn gets called upon any operation.
  • Operations that don't change the document are ignored by mongo-query.
  • If an operation is supplied as the second parameter, the first parameter of the event callback will be the value property of the log object. For example, if the operation is a $push, the value that's pushed is the first parameter.
  • Otherwise, the first parameter is always the new value of the given key (after). For example, if the operation is acting on an array, like pushing, pulling or popping, you will still get the reference to the entire array.
  • The second parameter of the event callback is always the log object returned by mongo-query.

Document#upon(key, fn)

Calls ready, then calls fn with the initial value of the given key, and subscribes to subsequent change events for key.

Document#each(key, fn)

Calls ready, then calls fn for each value of the array found under key.

Document#destroy(fn)

Destroys this subscription. fn gets called when the unsubscription for the current id is confirmed.

License

MIT

mydb-client's People

Contributors

belcherj avatar coreh avatar matthewmueller avatar nulltask avatar rauchg avatar tj avatar tootallnate avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.