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

ember-crossfilter

v0.2.5

Published

Instead of using Ember DataStore, EmberCrossfilter provides a basic architecture for creating Ember models with Crossfilter; which allows for much quicker sorting and filtering.

Downloads

2

Readme

Ember Crossfilter

Install via npm: npm install ember-crossfilter

Both Ember DS and native JavaScript filtering methods are slow in comparison to Crossfilter. However, Crossfilter is not the easiest to get started with, and people starting out with Crossfilter find themselves in a pickle. That's why I've created a facade for working with Crossfilter with Ember. If you wish to go with your own implementation, then EmberCrossfilter also serves as a nice reference, and an example of a good implementation.

Out of the box, EmberCrossfilter provides:

  • Create simple filters, such as ranges, custom callbacks, exact matches;
  • Create more complicated boolean filters, such as OR/AND (filterAnd/filterOr);
  • Ability to determine which filters are active;
  • Find the highest/lowest values quickly (top/bottom);
  • Naturally sort an array using the sort object, and modify using the sortContent method;
  • Ability to extend EmberCrossfilter by accessing the _crossfilter property;

Methods

EmberCrossfilter provides a simple interface with a minimal footprint.

It exposes the following public methods:

  • isActiveFilter(key, value) – whether a filter is currently active, with an optional value parameter for specificity.
  • addFilter(key, value) – add a new filter to filter against;
  • addRecord(record) – adds an individual record to the collection;
  • addRecords(records) – adds many records;
  • deleteRecord(record) – deletes a record by the primaryKey;
  • deleteRecords(records) – deletes many records;
  • removeFilter(key, value) – remove a filter that's already been applied using addFilter;
  • clearAllFilters – clears all of the applied filters;
  • sortContent(property, isAscending) – filters the content based on a property from the model;
  • top(property, count) – a helper method for finding the highest value of property;
  • bottom(property, count) – same as above, but the lowest value;

Timing

If you'd like to see the timing outputs in your console, simply set allowDebugging to true in your controller that implements the EmberCrossfilter mixin, and you'll see how long various operations took in milliseconds.

Sorting

To set the default sorting direction for when EmberCrossfilter is initialised, you can supply a sort object in your controller.

The following will sort descending by the name property:

sort: { sortProperty: 'name', isAscending: false }

If you'd like to trigger sorting updates from your controllers/views, then you can invoke the sortContent method with the property, and the direction (ascending/descending), and EmberCrossfilter will update the sort object for you to reflect the changes.

The following will change the sorting to sort ascending by the age property:

sortContent('age', true);

Updates

EmberCrossfilter doesn't provide any mechanism for determining if the content has been updated. If you'd like to know when an update has occurred, then you can observer the content.length property on your controller.

Extras: Crossfilter's Missing Child

When using Crossfilter, it became apparent that comparing two arrays was naturally slow in Crossfilter, such as when you had [1, 2, 3] and you wanted only models with those values set. EmberCrossfilter rectifies that issue by offering a bitwise solution (filterAnd/filterOr) which does all the hard-work for you. It can be configured to use OR/AND.

AND (filterAnd)

If you've set ['Italy', 'Russia'] then a model must have BOTH of these values to be considered valid.

  • Valid: ['Italy', 'Russia', 'Spain']
  • Invalid: ['Italy', 'Brazil', 'India']

OR (filterOr)

In this case if you've set ['Italy', 'Russia'], then a model can have either or both of these to be considered valid.

  • Valid: ['Italy', 'Haiti']
  • Invalid: ['Portugal', 'Latvia']