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-collection-proxy

v0.2.5

Published

Create a read-only copy of a backbone collection that stays in sync with the original

Downloads

8,049

Readme

backbone-collection-proxy

Build Status

Create a read-only copy of a backbone collection that stays in sync with the original collection as it's modified, and forwards all of the original collection's events through the proxy.

var original = new Backbone.Collection([ /* ... */ ]);

// Create a new object that will be a read-only proxy of the original model
var proxy = {};
proxyCollection(original, proxy);

// Now we can read values using Backbone.Collection methods on the proxy object
proxy.length === original.length;
proxy.map(function(model) { /* ... */ });
// etc

Why?

This module is somewhat useless on it's own, but it's intended to provide as much of the Backbone.Collection interface to a read-only proxy, so that I can modify and manipulate the proxied collection and expose those changes to the library consumer.

Usage

The following methods are not available on the proxy:

  • add
  • create
  • remove
  • set
  • reset
  • sort
  • parse
  • sync
  • fetch
  • push
  • pop
  • shift
  • unshift

Additionally, there is no access to the following properties:

  • comparator
  • model
  • url

All other collection methods should work and return the same result as if they were called on the original collection.

Events

Note that events fired on the proxied collection will not also be fired on the original collection. Certain events fired on the original collection will be forwarded to the proxied collection. These events are:

  • add
  • remove
  • reset
  • sort
  • destroy
  • change
  • change:[attribute]

References to the original collection passed as arguments in these events will be replaced with a reference to the proxy collection.

Installation

Usage with Browserify

Install with npm, use with Browserify

> npm install backbone-collection-proxy

and in your code

var proxyCollection = require('backbone-collection-proxy');

Usage with Bower

Install with Bower:

bower install backbone-collection-proxy

The component can be used as a Common JS module, an AMD module, or a global.

Usage as browser global

You can include backbone-sorted-collection.js directly in a script tag. Make sure that it is loaded after underscore and backbone. It's exported as SortedCollection on the global object.

<script src="underscore.js"></script>
<script src="backbone.js"></script>
<script src="backbone-collection-proxy.js"></script>

Testing

Install Node (comes with npm) and Bower.

From the repo root, install the project's development dependencies:

npm install
bower install

Testing relies on the Karma test-runner. If you'd like to use Karma to automatically watch and re-run the test file during development, it's easiest to globally install Karma and run it from the CLI.

npm install -g karma
karma start

To run the tests in Firefox, just once, as CI would:

npm test

If you make any changes you will have to re-build the UMD module that the tests runs against. You can do this by running grunt. You need to install the grunt command line tools globally by running

npm install -g grunt-cli

and then running the following command with no arguments to build

grunt

License

MIT