Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 6d635ad

Browse files
committed
Fixing track for multi-value models. Fixes #682
1 parent 0009e61 commit 6d635ad

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/utils/track.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import findKey from '../utils/find-key';
22
import _get from '../utils/get';
33
import iteratee from '../utils/iteratee';
4+
import isMulti from '../utils/is-multi';
45

56
const defaultStrategy = {
67
get: _get,
@@ -38,8 +39,12 @@ function createTrack(s = defaultStrategy) {
3839
fullPath += `.${subPath}`;
3940
});
4041

42+
if (isMulti(childModel) && predicates.length < childModelPaths.length) {
43+
fullPath += '[]';
44+
}
45+
4146
return isPartial
42-
? [parentModel, fullPath].join('.')
47+
? `${parentModel}.${fullPath}`
4348
: fullPath;
4449
};
4550
};

test/tracking-spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,25 @@ describe('tracking', () => {
140140
assert.equal(tracker(quizState), 'quiz.questions.0.choices.1');
141141
});
142142
});
143+
144+
describe('multiple levels of tracking with multi-value models', () => {
145+
it('should ignore final set of brackets if following args mismatch count', () => {
146+
const testState = {
147+
foo: [
148+
{
149+
id: 1,
150+
bar: [
151+
{
152+
id: 2,
153+
multiple: ['a', 'b', 'c'],
154+
},
155+
],
156+
},
157+
],
158+
};
159+
160+
const tracker = track('foo[].bar[].multiple[]', { id: 1 }, { id: 2 });
161+
assert.equal(tracker(testState), 'foo.0.bar.0.multiple[]');
162+
});
163+
});
143164
});

0 commit comments

Comments
 (0)