Skip to content

Commit

Permalink
[BUGFIX release] Allows @each to work with arrays that contain falsy …
Browse files Browse the repository at this point in the history
…values

This matches the original behavior as seen in the each_proxy.
  • Loading branch information
Chris Garrett committed Oct 9, 2019
1 parent f786e42 commit 8efb331
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/@ember/-internals/metal/lib/chain-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,14 @@ export function getChainTagsForKey(obj: any, path: string) {
for (let i = 0; i < arrLength; i++) {
let item = objectAt(current as Array<any>, i);

assert(
`When using @each to observe the array \`${current.toString()}\`, the items in the array must be objects`,
typeof item === 'object'
);
if (item) {
assert(
`When using @each to observe the array \`${current.toString()}\`, the items in the array must be objects`,
typeof item === 'object'
);

chainTags.push(tagForProperty(item, segment));
chainTags.push(tagForProperty(item, segment));
}
}

// Push the tag for the array length itself
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,28 @@ moduleFor(
assert.deepEqual(n.normalized, []);
}

['@test @each works on array with falsy values'](assert) {
let obj = EmberObject.extend({
falsy: [null, undefined, false, '', 0, {}],
truthy: [true, 'foo', 123],

falsyComputed: computed('[email protected]', () => {
assert.ok(true, 'falsy computed');
}),

truthyComputed: computed('[email protected]', () => {
assert.ok(true, 'truthy computed');
}),
}).create();

// should throw no errors
obj.falsyComputed;

expectAssertion(() => {
obj.truthyComputed;
}, /When using @each to observe the array `true,foo,123`, the items in the array must be objects/);
}

['@test @each works with array-likes'](assert) {
class ArrayLike {
constructor(arr = []) {
Expand Down

0 comments on commit 8efb331

Please sign in to comment.