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 🙏

© 2025 – Pkg Stats / Ryan Hefner

chale

v1.1.0

Published

A collection of data models

Downloads

445

Readme

Chale

NPM

This is a base class for managing a collection of models. It's designed to be used with Merstone models models, but the only opiniated piece of design is that the models it works with must have an id and a cid property and be an event emitter.

If you are used to Backbone, throw your notion of collections out of the window. In my opinion, Backbone Collections couple the two very distinct roles of a) managing a collection of models in an interface and b) the CRUD actions of entities over a RESTy AJAX API. Chale collections just deal with a) and I prefer to use a service for persistence.

Chale collections inherit their eventy behaviour from node event emitter.

Browser support

If you need IE8 support you need to include es5-shim and es5-sham to polyfill the ES5 features that this module uses.

Installation

npm install --save chale

Usage

//
// Constructor
//

var Collection = require('chale')
  , Model = require('merstone')
  , c = new Collection(serviceLocator, {})

//
// Adding, getting and removing
//

c.add(new Model(serviceLocator, { _id: '123' }))
c.get('123')
c.remove('123')
c.reset([ new Model(serviceLocator, { _id: '234' }), new Model(serviceLocator, { _id: '345' }) ])
c.at(5) // Retrieves model at the given index

// Array methods
// The following array methods are copied onto the Collection prototype.
// These work on the collection.models array:

c.forEach(…)
c.map(…)
c.filter(…)
c.reduce(…)
c.reduceRight(…)
c.every(…)
c.some(…)
c.concat(…)
c.slice(…)

// Length property
c.length

//
// Events
//

c.on('add', function (model) {
  console.log('A model was added: id=' + model.id)
})

c.on('remove', function (model) {
  console.log('A model was removed: id=' + model.id)
})

c.on('reset', function (models) {
  console.log('The collection was reset with ' + models.length + ' models')
})

//
// Propagating model events
//

// By default 'change' and 'reset' events are propagated from models
c.on('model:change', function (model) {})
c.on('model:reset', function (model) {})

// Propagate more events by telling the
// constructor what you want to listen to
var c = new Collection({}, [], [ 'change', 'reset', 'flip', 'flop' ])
c.on('model:flip', function (model, …) {})

//
// Serialisation
//

// Creates a deep clone of the collection's models
c.toJSON()

The name?

I've made a bunch of MVC-like components. I named each one after villages on the Isle of Wight (where I live) beginning with the same letter as the thing it represents.

See also Ventnor views and Merstone models.

Credits

Licence

Copyright (c) 2014, Ben Gourley

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.