File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
packages/@posva/vuefire-core Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,17 @@ describe('refs in documents', () => {
80
80
expect ( vm . arr ) . toEqual ( { refs : [ b . path , c . path ] } )
81
81
} )
82
82
83
+ it ( 'keeps correct elements in array of references when removing in the middle' , async ( ) => {
84
+ const arr = collection . doc ( )
85
+ vm . arr = null
86
+
87
+ await arr . update ( { refs : [ a , b , c ] } )
88
+ await bind ( 'arr' , arr , { maxRefDepth : 0 } )
89
+ await arr . update ( { refs : [ a , c ] } )
90
+
91
+ expect ( vm . arr ) . toEqual ( { refs : [ a . path , c . path ] } )
92
+ } )
93
+
83
94
it ( 'binds refs on documents' , async ( ) => {
84
95
// create an empty doc and update using the ref instead of plain data
85
96
await item . update ( { ref : c } )
@@ -124,7 +135,7 @@ describe('refs in documents', () => {
124
135
} )
125
136
} )
126
137
127
- it . only ( 'does not lose empty references in arrays of objects when updating a property' , async ( ) => {
138
+ it ( 'does not lose empty references in arrays of objects when updating a property' , async ( ) => {
128
139
const emptyItem = collection . doc ( )
129
140
await item . update ( { todos : [ { ref : emptyItem } ] , toggle : true } )
130
141
await bind ( 'item' , item )
Original file line number Diff line number Diff line change @@ -64,7 +64,14 @@ export function extractRefs(
64
64
} else if ( isDocumentRef ( ref ) ) {
65
65
// allow values to be null (like non-existant refs)
66
66
// TODO: better typing since this isObject shouldn't be necessary but it doesn't work
67
- data [ key ] = typeof oldDoc === 'object' && key in oldDoc ? oldDoc [ key ] : ref . path
67
+ data [ key ] =
68
+ typeof oldDoc === 'object' &&
69
+ key in oldDoc &&
70
+ // only copy refs if they were refs before
71
+ // https://github.com/vuejs/vuefire/issues/831
72
+ typeof oldDoc [ key ] != 'string'
73
+ ? oldDoc [ key ]
74
+ : ref . path
68
75
// TODO: handle subpathes?
69
76
refs [ path + key ] = ref
70
77
} else if ( Array . isArray ( ref ) ) {
You can’t perform that action at this time.
0 commit comments