Skip to content

Commit

Permalink
use objectlike when building virtual gets - refs #3333
Browse files Browse the repository at this point in the history
  • Loading branch information
evs-chris committed May 5, 2020
1 parent 28c41ef commit cc1fe62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/model/ModelBase.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { escapeKey, unescapeKey } from 'shared/keypaths';
import { addToArray, removeFromArray } from 'utils/array';
import { isArray, isObject, isFunction } from 'utils/is';
import { isArray, isObject, isObjectLike, isFunction } from 'utils/is';
import bind from 'utils/bind';
import { create, keys as objectKeys } from 'utils/object';

Expand Down Expand Up @@ -97,7 +97,7 @@ export default class ModelBase {

getVirtual(shouldCapture) {
const value = this.get(shouldCapture, { virtual: false });
if (isObject(value)) {
if (isObjectLike(value)) {
const result = isArray(value) ? [] : create(null);

let keys = objectKeys(value);
Expand Down
15 changes: 15 additions & 0 deletions tests/browser/computations.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,4 +1417,19 @@ export default function() {
t.ok(!div.classList.contains('foo'));
t.ok(!div.classList.contains('bar'));
});

test(`pattern computeds in an array come out in a virtual get (#3333)`, t => {
const r = new Ractive({
target: fixture,
template: `{{#each things}}{{.foo}} {{.bar}}{{/each}}`,
data: { things: [{ foo: 1 }] },
computed: {
'things.*.bar'() {
return 2;
}
}
});

t.deepEqual(r.get('things', { virtual: true }), [{ foo: 1, bar: 2 }]);
});
}

0 comments on commit cc1fe62

Please sign in to comment.