npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

backbone.drowsy.encorelab

v0.2.6

Published

Backbone Model for use with DrowsyDromedary (MongoDB) as a backend

Downloads

1

Readme

Backbone.Drowsy

Backbone.js Model + Collection classes for use with the DrowsyDromedary REST interface for MongoDB.

Usage

var myDrowsyServer = new Drowsy.Server('http://localhost:9292');
var myDatabase = myDrowsyServer.database('example_db');

// extend a base Drowsy.Document (i.e. Backbone.Model) for your needs
var MyModel = myDatabase.Document('example_collection').extend({
    foobar: function() {
      return this.get('foo') * 2;
    }
  });
  
var doc = new MyModel();
doc.on('sync', function (d) {
  console.log("Doc is: "+d.toJSON());
});

doc.set('blah', 'moo');
doc.save();

doc.foobar();

// extend a base Drowsy.Collection for your needs
var MyCollection = myDatabase.Collection('example_collection').extend({
  model: MyModel
});

var coll = new MyCollection();
coll.fetch();


// you can also fetch the list of databases on a server
myDrowsyServer.databases(function (dbs) {
  (dbs[0] instanceof Drowsy.Database) === true
});

// and fetch the list of collections in a database
myDatabase.collections(function (colls) {
  (colls[0] instanceof Drowsy.Collection) == true
});

See the example and test directories for more details.

Authentication

For basic HTTP authentication, run the following code prior to sending out any requests:

var username = "foo";
var password = "bar";

Backbone.$.ajaxSetup({
  beforeSend: function(xhr) {
    return xhr.setRequestHeader('Authorization', 
        'Basic ' + btoa(username + ':' + password));
  }
});

See the AJAX configuration options for jQuery or Zepto, dependin on which Backbone sync backend you're using.

Automatically Broadcasting Changes

Backbone.Drowsy can automatically broadcast changes to Documents and Collections through WakefulWeasel (i.e. using Faye). To enable Wakeful functionality, load the wakeful.js script:

<script src="wakeful.js"></script>

Then call the Wakeful.wake() method on a Drowsy.Document or Drowsy.Collection instance, like so:

var doc = new MyModel();

var weaselUrl = "http://localhost:7777/faye";

doc.wake(weaselUrl);

.wake() imbues the Document or Collection with special Backbone.sync behaviour that automatically broadcasts changes to a Document or Collection to all other Documents or Collections using that URL.

For example, calling doc.save() would automatically push doc's state to any other doc with the same URL (i.e. to other browsers/clients).

TODO: write some more usage examples

In the meantime, see https://github.com/zuk/Backbone.Drowsy/blob/master/test/wakeful.test.coffee#L320

Browser or Node.js?

Backbone.Drowsy should work both in a browser and under node.js.

Running Tests/Specs

With node, cd into the Backbone.Drowsy directory, then install dependencies using:

npm install

You should now be able to run all tests in test/ by running the following in the root Backbone.Drowsy directory:

cake test

By default the tests run against http://localhost:9292 for DrowsyDromedary and http://localhost:7777/faye for WakefulWeasel. To test against a different DrowsyDromedary and WakefulWeasel instance, set the DROWSY_URL and WEASEL_URL environment variables, like this:

DROWSY_URL=http://drowsy.example.com WEASEL_URL=http://weasel.example.com/faye cake test

You can also run the tests in the browser:

First, make sure the Backbone.Drowsy directory is accessible via a web browser. For example, you can serve the directory contents with Ruby's WEBrick. Just run the following in the root Backbone.Drowsy directory:

ruby -r webrick -e "s = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"

Then point your browser to http://localhost:8000/test.