@@ -21,7 +21,9 @@ import {
21
21
newRxTypeError
22
22
} from '../rx-error' ;
23
23
import {
24
- clone , now , LOCAL_PREFIX
24
+ clone ,
25
+ now ,
26
+ LOCAL_PREFIX
25
27
} from '../util' ;
26
28
27
29
import type {
@@ -114,7 +116,9 @@ const RxLocalDocumentPrototype: any = {
114
116
this : any ,
115
117
changeEvent : RxChangeEvent
116
118
) {
117
- if ( changeEvent . documentId !== this . primary ) return ;
119
+ if ( changeEvent . documentId !== this . primary ) {
120
+ return ;
121
+ }
118
122
switch ( changeEvent . operation ) {
119
123
case 'UPDATE' :
120
124
const newData = clone ( changeEvent . documentData ) ;
@@ -202,12 +206,10 @@ const RxLocalDocumentPrototype: any = {
202
206
. then ( ( res : any ) => {
203
207
const endTime = now ( ) ;
204
208
newData . _rev = res . rev ;
205
- this . _dataSync$ . next ( newData ) ;
206
-
207
209
const changeEvent = new RxChangeEvent (
208
210
'UPDATE' ,
209
211
this . id ,
210
- clone ( this . _data ) ,
212
+ clone ( newData ) ,
211
213
isRxDatabase ( this . parent ) ? this . parent . token : this . parent . database . token ,
212
214
isRxCollection ( this . parent ) ? this . parent . name : null ,
213
215
true ,
@@ -294,8 +296,9 @@ RxLocalDocument.create = (id: string, data: any, parent: any) => {
294
296
* throws if already exists
295
297
*/
296
298
function insertLocal ( this : any , id : string , data : any ) : Promise < RxLocalDocument > {
297
- if ( isRxCollection ( this ) && this . _isInMemory )
299
+ if ( isRxCollection ( this ) && this . _isInMemory ) {
298
300
return this . _parentCollection . insertLocal ( id , data ) ;
301
+ }
299
302
300
303
data = clone ( data ) ;
301
304
@@ -326,15 +329,16 @@ function insertLocal(this: any, id: string, data: any): Promise<RxLocalDocument>
326
329
* overwrites existing if exists
327
330
*/
328
331
function upsertLocal ( this : any , id : string , data : any ) : Promise < RxLocalDocument > {
329
- if ( isRxCollection ( this ) && this . _isInMemory )
332
+ if ( isRxCollection ( this ) && this . _isInMemory ) {
330
333
return this . _parentCollection . upsertLocal ( id , data ) ;
334
+ }
331
335
332
336
return this . getLocal ( id )
333
- . then ( ( existing : any ) => {
337
+ . then ( ( existing : RxDocument ) => {
334
338
if ( ! existing ) {
335
339
// create new one
336
- const doc = this . insertLocal ( id , data ) ;
337
- return doc ;
340
+ const docPromise = this . insertLocal ( id , data ) ;
341
+ return docPromise ;
338
342
} else {
339
343
// update existing
340
344
data . _rev = existing . _data . _rev ;
0 commit comments