Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

backbone-cappedcollection

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone-cappedcollection

Capped Collections for BackboneJS

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Backbone Capped Collections Build Status

Capped Collections for BackboneJS

Getting Started

Install the module with: npm install backbone-cappedcollection

Client-side

<script type="text/javascript" src="underscore.js"></script>
<script type="text/javascript" src="backbone.js"></script>
<script type="text/javascript" src="lib/index.js"></script>
<script type="text/javascript">
var myColl = new Backbone.CappedCollection([
  {name: "Twitter", url: "http://twitter.com/FGRibreau"}, // Will be removed
  {name: "Bringr",  url: "http://brin.gr"},
  {name: "Redsmin", url: "http://redsmin.com"},
], {
  // {optional} Capped Collection size (default. 5)
  cap:2,
  // {optional} From where should it start to remove elements, "first" or "last" (default. first)
  capRemove:'first'
});

myColl.length; // == 2

myColl.add({name: "Github", url: "http://github.com"});
myColl.add({name: "NodeJS", url: "http://nodejs.org/"});

myColl.length; // == 2

myColl.toJSON(); // [{"name":"Github","url":"http://github.com"},{"name":"NodeJS","url":"http://nodejs.org/"}]

// Other Backbone methods (.add, .reset, ...) should work as expected as well.
</script>

Server-side (NodeJS)

var Backbone = require('backbone');
// Wrap it
Backbone = require('backbone-cappedcollection')(Backbone);

// [... same as the client-side code above ...]

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.

Release History

v0.1.0 - First commit

License

Copyright (c) 2013 Francois-Guillaume Ribreau Licensed under the MIT license.

FAQs

Package last updated on 28 Jan 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc