This repository was archived by the owner on Aug 23, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1
1
import findKey from '../utils/find-key' ;
2
2
import _get from '../utils/get' ;
3
3
import iteratee from '../utils/iteratee' ;
4
+ import isMulti from '../utils/is-multi' ;
4
5
5
6
const defaultStrategy = {
6
7
get : _get ,
@@ -38,8 +39,12 @@ function createTrack(s = defaultStrategy) {
38
39
fullPath += `.${ subPath } ` ;
39
40
} ) ;
40
41
42
+ if ( isMulti ( childModel ) && predicates . length < childModelPaths . length ) {
43
+ fullPath += '[]' ;
44
+ }
45
+
41
46
return isPartial
42
- ? [ parentModel , fullPath ] . join ( '.' )
47
+ ? ` ${ parentModel } . ${ fullPath } `
43
48
: fullPath ;
44
49
} ;
45
50
} ;
Original file line number Diff line number Diff line change @@ -140,4 +140,25 @@ describe('tracking', () => {
140
140
assert . equal ( tracker ( quizState ) , 'quiz.questions.0.choices.1' ) ;
141
141
} ) ;
142
142
} ) ;
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
+ } ) ;
143
164
} ) ;
You can’t perform that action at this time.
0 commit comments