-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow merging invalid changesets (#74)
- Loading branch information
1 parent
41a5878
commit 85337fc
Showing
6 changed files
with
62 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { keys } = Object; | ||
|
||
/** | ||
* Merges all sources together, excluding keys in excludedKeys. | ||
* | ||
* @param {Array[String]} excludedKeys | ||
* @param {...Object} sources | ||
* | ||
* @return {Object} | ||
*/ | ||
export default function objectWithout(excludedKeys, ...sources) { | ||
return sources.reduce((acc, source) => { | ||
keys(source) | ||
.filter((key) => excludedKeys.indexOf(key) === -1 || !source.hasOwnProperty(key)) | ||
.forEach((key) => acc[key] = source[key]); | ||
return acc; | ||
}, {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ember-changeset/utils/object-without'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import objectWithout from 'dummy/utils/object-without'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Utility | object without'); | ||
|
||
test('it exludes the given keys from all merged objects', function(assert) { | ||
let objA = { name: 'Ivan' }; | ||
let objB = { name: 'John' }; | ||
let objC = { age: 27 }; | ||
let objD = objectWithout([ 'age' ], objA, objB, objC); | ||
|
||
assert.deepEqual(objD, { name: 'John' }, 'result only contains name'); | ||
assert.deepEqual(objA.name, 'Ivan', 'does not mutate original object'); | ||
assert.deepEqual(objC.age, 27, 'does not mutate original object'); | ||
}); |