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-array-computed-macros

v1.3.0

Published

This addon is supplemental to the already existing computed macros existing in Ember.js

Downloads

32

Readme

ember-array-computed-macros

npm version Build Status Ember Observer Score

Macros

This addon is supplemental to the already existing array computed macros existing in Ember.js

maxBy(listProperty, valueProperty)

Takes all values of valueProperty from listProperty and then picks the maximum value from that.

Example:

var ContactList = Ember.Component.extend({
  highestAge: maxBy('people', 'age')
});

const myContactList = ContactList.create({
  people: [
    { first: 'Tom', last: 'Dale', age: 21 },
    { first: 'Yehuda', last: 'Katz', age: 42 }
  ]
}).

myContactList.get('highestAge') // returns 42

minBy(listPropery, valueProperty)

See maxBy, except it takes the minimum value instead of the maximum.

orderBy(listProperty, ...sortProperties)

Takes a listProperty and returns that list sorted by the sortProperties. Append :desc to the sort property to sort in reverse order for that property.

import Ember from 'ember';
import { map } from 'ember-array-computed-macros';

export default Ember.Component.extend({
  names: [
    { first: 'Tom', last: 'Dale', age: 21 },
    { first: 'Yehuda', last: 'Katz', age: 42 }
  ],
  orderedNames: orderBy('names', 'last', 'first'. 'age:desc')
});

There is also a variant for groupBy that works with a dynamic list of sortProperties called groupByComputedProperty:

import Ember from 'ember';
import { map } from 'ember-array-computed-macros';

export default Ember.Component.extend({
  names: [
    { first: 'Tom', last: 'Dale', age: 21 },
    { first: 'Yehuda', last: 'Katz', age: 42 }
  ],

  nameOrdering: ['last', 'first', 'age:desc'],
  orderedNames: orderByComputedProperty('names', 'nameOrdering')
});

groupBy(listProperty, valueProperty)

Pushes all items in listProperty that have the same value at valueProperty into an array.

var ContactList = Ember.Component.extend({
  groupedByAge: groupBy('people', 'age')
});

const myContactList = ContactList.create({
  people: [
    { first: 'Tom', last: 'Dale', age: 21 },
    { first: 'Yehuda', last: 'Katz', age: 42 },
    { first: 'Robert', last: 'Jackson', age: 42 },
    { first: 'Stefan', last: 'Penner', age 33 }
  ]
}).

myContactList.get('groupedByAge') // returns:
//[
//  [
//    { first: 'Tom', last: 'Dale', age: 21 }
//  ],
//  [
//    { first: 'Yehuda', last: 'Katz', age: 42 },
//    { first: 'Robert', last: 'Jackson', age: 42 }
//  ],
//  [
//    { first: 'Stefan', last: 'Penner', age 33 }
//  ]
//]

sumBy(listProperty, valueProperty)

Takes all values of valueProperty from listProperty and then sums those values.

Example:

var ContactList = Ember.Component.extend({
  collectiveAge: sumBy('people', 'age')
});

const myContactList = ContactList.create({
  people: [
    { first: 'Tom', last: 'Dale', age: 21 },
    { first: 'Yehuda', last: 'Katz', age: 42 }
  ]
}).

myContactList.get('collectiveAge') // returns 53

meanBy(listProperty, valueProperty)

Takes all values of valueProperty from listProperty and calculate their arithmetic mean value.

Example:

var ContactList = Ember.Component.extend({
  averageAge: meanBy('people', 'age')
});

const myContactList = ContactList.create({
  people: [
    { first: 'Tom', last: 'Dale', age: 21 },
    { first: 'Yehuda', last: 'Katz', age: 42 }
  ]
}).

myContactList.get('collectiveAge') // returns 31.5

reverse(listProperty)

Reverses the array at listProperty with Array.prototype.reverse.

everyBy(listPropery, valueProperty)

Takes all values of valueProperty from listProperty and then checks if all of those values are truthy.

anyBy(listProperty, valueProperty)

Takes all values of valueProperty from listProperty and then checks if any of those values are truthy.

From Ember.js

The addon re-exports all array computed macros from Ember.js for convenience.

  • map
  • mapBy
  • filter
  • filterBy
  • min
  • max
  • sum
  • sort

Use with decorators

import Ember from 'ember';
import { map } from 'ember-array-computed-macros/decorators';

export default Ember.Component.extend({
  names: [
    { first: 'Tom', last: 'Dale' },
    { first: 'Yehuda', last: 'Katz' }
  ],
  
  @mapBy('names', 'first')
  firstNames
});

Installation

  • git clone this repository
  • npm install
  • bower install

Running

  • ember server
  • Visit your app at http://localhost:4200.

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.