Giter VIP home page Giter VIP logo

backbone.collectionfilter's Introduction

Backbone.CollectionFilter

given a collection and a filter (and optional comparator) return a collection that mimics it's parent only with a filtered set of models.

Use

var EnhancedCollection = Backbone.Collection.extend({
	enhance: true
});

var myCollection = new EnhancedCollection();

var notGreenCollection = new Backbone.CollectionFilter(myCollection, function(child) {
	return child.get('color') !== 'green';
});

the filtered collection will inherit all functions and bind them to the original collection except on, off, trigger, at and pluck. It will even return the paramaters set on the parent collection (e.g. notGreenCollection.enhance === true) unless you set the parameter on the instance (so make sure you use setters, e.g. notGreenCollection.setEnhance(false) instead of notGreenCollection.enhance = false).

##BOUNS!##

added in multifilter.js which requires CF but makes it easy to add mutiple filters on and off a collection:

var filters = {
	isGreen: function(model) {
		return model.get('color') == 'green';
	},
	isSquare: function(model) {
		return model.get('shape') == 'square';
	}
};

myCollection = Multifilter(myCollection, filters);

myCollection.addFilter('isGreen'); // now only greens will show
myCollection.addFilter('isSquare'); // now only green squares
myCollection.removeFilter('isGreen'); // now only squares

#Changelog

##v1.1.0

add in options simple that will only filter the changes - use only for filter functions that rely on the model change

##v1.0.3

functions are now dynamically bound, only resolve function to bind when called

##v1.0.2

  • can pass in extra events to redo filter on

##v1.0.1

  • give new events array
  • only redo fiter on certain events

##v1.0.0

-initial versioning

backbone.collectionfilter's People

Contributors

rhysbrettbowen avatar volh avatar

Stargazers

Robert Marshall Adams avatar Tomislav Pavlović avatar  avatar Matt Cooper avatar Michał Ka avatar Michał avatar  avatar Florian Kissling avatar Chris Simpkins avatar Matt Daubert avatar  avatar Fabien Franzen avatar Jonathan Nuñez avatar  avatar Uros Gruber avatar  avatar Sven Lito avatar Jonathan Barratt avatar

Watchers

 avatar

Forkers

monwater

backbone.collectionfilter's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.