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

js-list-container

v0.91.22

Published

An evented array list container that augments the standard javascript array without altering the array prototype. Events fire when the list changes or when a contained model is updated.

Downloads

27

Readme

#List Container


An evented array list container that augments the standard javascript array without altering the array prototype. Events fire when the array changes or when a contained value or model changes.

NPM version Build Status Dependency Status

Overview

A simple wrapper/container for array lists that provides a base class to extend without modifying the javascript Array prototype.

Installation

npm install js-list-container --save

API

Instance Methods

  • push/pop
  • shift/unshift
  • forEach
  • forEachIndex - iterator with index
  • size
  • clear
  • getList / setList
  • sort
  • setSorter
  • updateModel - will trigger data model change event
  • stringify

Instance Attributes

  • lastRefresh
  • lastChangeDate - updated by container with push/pop/etc

Class Methods

  • extend
  • parse

Events

  • onListChange - whenever the list size changes
  • onDataChange - when a contained object changed through updateModel()

Use

Simple use without extension...

const ListContainer = require('js-list-container');
const options = {
	list:require('./list.json'),
	lastRefresh:new Date()
};
	
const container = new ListContainer( options );
container.size() === options.list.length;
	
container.forEach(item => {
	console.log( item );
});

Simple extension use case...

const MyCollection = function(options) {
	const container = this;
	
	ListContainer.extend( this, options );
	
	this.getItem = function(index) {
		var list = container.getList();
		
		return list[ index ];
	};
};

const collection = new MyCollection( opts );
	
collection.push( { id:1, created:new Date() } );
collection.push( { id:2, created:new Date() } );
	
collection.size() === 2;
	
let item = collection.getItem( 1 );
item.id === 2;	

Evented Example

const dash = require('lodash');
const ListContainer = require('js-list-container');
const options = {
	list:require('./list.json'),
	lastRefresh:new Date()
};
	
const container = new ListContainer( options );
container.onListChange(function() {
    console.log( 'list changed: ', container.lastChangeDate );
});

container.onDataChange(function(oldValue, newValue) {
	console.log( 'data changed: ', container.lastChangeDate );
});

// copy of one of the contained models
let originalModel = container.getList()[ 3 ],
	changeModel = dash.clone( original );

changeModel.title = 'My New Title';

// do the change will file a data change event and return true
container.updateModel( originalModel, changeModel ) === true;

// this will fire a list change event
let popped = container.pop();

// this will also fire a list change event
container.clear();

// this will not fire a data change event
container.updateModel( originalModel, changeModel ) === false;

Tests

All objects are tested using gulp and mocha. You can run tests by doing this:

	make test

    // or
    
    make watch
    
    // or

    make test

    // or

    npm test

copyright © 2014-2016 rain city software | version 0.91.22