Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update babel and rename contains => includes #2

Merged
merged 3 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![npm version](https://badge.fury.io/js/ember-macaroni.svg)](http://badge.fury.io/js/ember-macaroni) [![Build Status](https://travis-ci.org/poteto/ember-macaroni.svg?branch=master)](https://travis-ci.org/poteto/ember-macaroni) [![Ember Observer Score](http://emberobserver.com/badges/ember-macaroni.svg)](http://emberobserver.com/addons/ember-macaroni)

Keep your app code DRY and copypasta free with computed property <strong>mac</strong>a<strong>ro</strong>ni<strong>s</strong> (macros) for Ember.js 1.13.x and greater.
Keep your app code DRY and copypasta free with computed property <strong>mac</strong>a<strong>ro</strong>ni<strong>s</strong> (macros) for Ember.js 1.13.x and greater.

## Why
Computed property macros (CPM) are great for DRYing up your code, and Ember.js ships with a [few handy computed macros](http://emberjs.com/api/classes/Ember.computed.html). This addon adds a few more functional-style macros, and can be thought of as the "lodash equivalent" of Ember CPM libraries.
Expand Down Expand Up @@ -49,7 +49,7 @@ export default Ember.Component.extend({
- [rejectFromCollectionByKey](#rejectfromcollectionbykey)
- [rejectFromCollectionByValue](#rejectfromcollectionbyvalue)
- [filterFromCollectionByKey](#filterfromcollectionbykey)
- [filterFromCollectionByContains](#filterfromcollectionbycontains)
- [filterFromCollectionByIncludes](#filterfromcollectionbyincludes)
- [collectionWithoutKey](#collectionwithoutkey)
- [reduceCollectionByKey](#reducecollectionbykey)
* [Truth](#truth)
Expand All @@ -76,7 +76,7 @@ Returns the first item with a property matching the passed value from a dependen
- `@param {String} propName` The key name for the property to find by
- `@param {String} valueKey` The key name that returns the value to find

```js
```js
Ember.Object.extend({
items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }],
selectedId: 1,
Expand All @@ -94,7 +94,7 @@ Returns the first item with a property matching the passed value.
- `@param {String} propName` The key name for the property to find by
- `@param {*} value` The value to match`

```js
```js
Ember.Object.extend({
items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }],
selectedItem: findFromCollectionByValue('items', 'id', 1) // { id: 1, name: 'foo' }
Expand Down Expand Up @@ -156,7 +156,7 @@ Ember.Object.extend({

**[⬆ back to top](#available-macros)**

#### `filterFromCollectionByContains`
#### `filterFromCollectionByIncludes`

Returns an array with just the items that are contained in another array.

Expand All @@ -168,7 +168,7 @@ Returns an array with just the items that are contained in another array.
Ember.Object.extend({
items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }],
selectedId: 1,
selectedItem: filterFromCollectionByContains('items', 'id', [1]) // [{ id: 1, name: 'foo' }]
selectedItem: filterFromCollectionByIncludes('items', 'id', [1]) // [{ id: 1, name: 'foo' }]
});
```

Expand Down
6 changes: 3 additions & 3 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import findFromCollectionByValue from './macros/collection/find-from-collection-
import rejectFromCollectionByKey from './macros/collection/reject-from-collection-by-key';
import rejectFromCollectionByValue from './macros/collection/reject-from-collection-by-value';
import filterFromCollectionByKey from './macros/collection/filter-from-collection-by-key';
import filterFromCollectionByContains from './macros/collection/filter-from-collection-by-contains';
import filterFromCollectionByIncludes from './macros/collection/filter-from-collection-by-includes';
import collectionWithoutKey from './macros/collection/collection-without-key';
import reduceCollectionByKey from './macros/collection/reduce-collection-by-key';

Expand All @@ -24,7 +24,7 @@ export {
rejectFromCollectionByKey,
rejectFromCollectionByValue,
filterFromCollectionByKey,
filterFromCollectionByContains,
filterFromCollectionByIncludes,
collectionWithoutKey,
reduceCollectionByKey,
getPropertiesByKeys,
Expand All @@ -44,7 +44,7 @@ export default {
rejectFromCollectionByKey,
rejectFromCollectionByValue,
filterFromCollectionByKey,
filterFromCollectionByContains,
filterFromCollectionByIncludes,
collectionWithoutKey,
reduceCollectionByKey,
getPropertiesByKeys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ const {
* Ember.Object.extend({
* items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }],
* selectedId: 1,
* selectedItem: filterFromCollectionByContains('items', 'id', [1]) // [{ id: 1, name: 'foo' }]
* selectedItem: filterFromCollectionByIncludes('items', 'id', [1]) // [{ id: 1, name: 'foo' }]
* });
*
* @param {String} collectionKey The key name for the collection
* @param {String} propName The key name for the property to filter by
* @param {Array} values The array of values to filter
*/
export default function filterFromCollectionByContains(collectionKey, propName, values = []) {
export default function filterFromCollectionByIncludes(collectionKey, propName, values = []) {
return computed(`${collectionKey}.@each.${propName}`, {
get() {
return emberArray(get(this, collectionKey))
.filter((item) => emberArray(values).contains(get(item, propName)));
.filter((item) => emberArray(values).includes(get(item, propName)));
}
});
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ember-cli-app-version": "^1.0.0",
"ember-cli-content-security-policy": "0.4.0",
"ember-cli-dependency-checker": "^1.3.0",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-htmlbars-inline-precompile": "^1.0.0",
"ember-cli-inject-live-reload": "^1.4.0",
"ember-cli-jshint": "^1.0.0",
"ember-cli-qunit": "^2.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Ember from 'ember';
import { module, test } from 'qunit';
import { filterFromCollectionByContains } from 'ember-macaroni';
import { filterFromCollectionByIncludes } from 'ember-macaroni';

const {
Object: EmberObject,
get
} = Ember;

module('ember-macaroni/collection - filterFromCollectionByContains');
module('ember-macaroni/collection - filterFromCollectionByIncludes');

test('#filterFromCollectionByContains filters a collection by an array of values for a given property', (assert) => {
test('#filterFromCollectionByIncludes filters a collection by an array of values for a given property', (assert) => {
assert.expect(1);

const expectedResult = [
Expand All @@ -22,7 +22,7 @@ test('#filterFromCollectionByContains filters a collection by an array of values
{ name: 'Jake', type: 'adventureTime' }
];
const Tommy = EmberObject.extend({
friends: filterFromCollectionByContains('characters', 'type', ['rugrats', 'RUGRATS'])
friends: filterFromCollectionByIncludes('characters', 'type', ['rugrats', 'RUGRATS'])
});
const subject = Tommy.create({ characters });
const result = get(subject, 'friends');
Expand Down