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-socketio

v0.2.1

Published

Realtime two-way data-binding of Backbone model and collection data to a webserver via Socket.io.

Downloads

6

Readme

backbone-socketio Build Status

Realtime two-way data-binding of Backbone model and collection data to a webserver via Socket.io. Makes realtime, collaborative editing in Backbone applications (hopefully) much simpler.

Getting Started

Server

Install the module: npm install backbone-socketio.

Server-side event listeners are added by injecting the Socket.io module as a dependency:

var io = require('socket.io');
require('backbone-socketio').init(io);
// continue to do your normal socket.io stuff here

Client

The only dependencies the client has are Underscore and Backbone.js. Using Cocktail to apply mixins to models or collections will make for a much nicer experience, but is not required.

Install the client-side code using Bower:

bower install backbone-socketio

or by downloading the minified file and hosting it on your server or CDN.

Include the file: <script src="/bower_components/backbone-socketio/client/backbone-socketio.min.js"></script>

And mix the event listeners in using Cocktail, or manually with extend.

With Cocktail:

var socket = io.connect('http://localhost:3000'),
    backboneMixins = new BackboneSocketio(socket),
    MyModel, MyCollection;

MyModel = Backbone.Model.extend({ /* normal model init code here */ });
Cocktail.mixin(MyModel, backboneMixins.mixins.model);

MyCollection = Backbone.Collection.extend({ /* normal collection init code here */ });
Cocktail.mixin(MyCollection, backboneMixins.mixins.collection);

Without Cocktail:

var socket = io.connect('http://localhost:3000'),
    backboneMixins = new BackboneSocketio(socket),
    SocketModel = Backbone.Model.extend(backboneMixins.mixins.model),
    SocketCollection = Backbone.Collection.extend(backboneMixins.mixins.collection),
    MyModel, MyCollection;

MyModel = SocketModel.extend({
    // normal model init code here
    initialize: function () {
        // if you need an initialize method make sure you call the parent's
        // initialize function
        MyModel.__super__.initialize.call(this);
    }
});

MyCollection = SocketCollection.extend({
    // normal collection init code here
    initialize: function () {
        // if you need an initialize method make sure you call the parent's
        // initialize function
        MyCollection.__super__.initialize.call(this);
    }
});

This will set up listeners on all the necessary change events on models and collections then publish those changes down to the server. The server will then broadcast those changes back out to all other clients connected to the same socket and update the data in their corresponding models and collections.

Handling any DOM manipulation necessary to reflect changes in your views is up to you.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt. grunt will run unit tests and JSHint.

Release History

0.2.1

  • Added minified version of client file with source map file
  • Only a model's changed data is sent over socket rather than entire model's JSON
  • Reorganized file structure
  • Rewrote unit tests using Mocha

0.2.0

  • Support for Backbone.Collection sort events
  • Minor bug fixes

0.1.0

Basic proof of concept. Full support for add and remove (collection) and change (model) events.

TODOs/wish list

  • Put server component on NPM
  • Make client component work with Bower
  • Account/room-specific events
  • Server-side hooks to run custom code in response to change events
  • Probably a lot of other things I can't remember right now

License

Copyright (c) 2013-2014 Josh Mock

Licensed under the MIT license.

Bitdeli Badge