99 findValue,
1010} = require ( './utils' ) ;
1111
12+ const recursiveToPointer = value => {
13+ if ( _ . isObject ( value ) ) {
14+ if ( value . _toPointer ) return value . _toPointer ( ) ;
15+ return _ . mapObject ( value , recursiveToPointer ) ;
16+ }
17+ if ( _ . isArray ( value ) ) return value . map ( recursiveToPointer ) ;
18+ return value ;
19+ } ;
20+
1221const RESERVED_KEYS = [ 'objectId' , 'createdAt' , 'updatedAt' ] ;
1322const checkReservedKey = key => {
1423 if ( RESERVED_KEYS . indexOf ( key ) !== - 1 ) {
@@ -311,10 +320,6 @@ module.exports = function(AV) {
311320 dirty : function ( attr ) {
312321 this . _refreshCache ( ) ;
313322
314- return this . _dirty ( ) ;
315- } ,
316-
317- _dirty : function ( attr ) {
318323 var currentChanges = _ . last ( this . _opSetQueue ) ;
319324
320325 if ( attr ) {
@@ -567,8 +572,7 @@ module.exports = function(AV) {
567572 ! ( value instanceof AV . Object ) &&
568573 ! ( value instanceof AV . File )
569574 ) {
570- value = value . toJSON ? value . toJSON ( ) : value ;
571- var json = JSON . stringify ( value ) ;
575+ var json = JSON . stringify ( recursiveToPointer ( value ) ) ;
572576 if ( this . _hashedJSON [ key ] !== json ) {
573577 var wasSet = ! ! this . _hashedJSON [ key ] ;
574578 this . _hashedJSON [ key ] = json ;
@@ -593,16 +597,15 @@ module.exports = function(AV) {
593597 AV . _arrayEach ( this . _opSetQueue , function ( opSet ) {
594598 var op = opSet [ key ] ;
595599 if ( op ) {
596- const [ value , actualTarget , actualKey ] = findValue (
600+ const [ value , actualTarget , actualKey , firstKey ] = findValue (
597601 self . attributes ,
598602 key
599603 ) ;
600604 setValue ( self . attributes , key , op . _estimate ( value , self , key ) ) ;
601605 if ( actualTarget && actualTarget [ actualKey ] === AV . Op . _UNSET ) {
602606 delete actualTarget [ actualKey ] ;
603- } else {
604- self . _resetCacheForKey ( key ) ;
605607 }
608+ self . _resetCacheForKey ( firstKey ) ;
606609 }
607610 } ) ;
608611 } ,
@@ -1604,7 +1607,7 @@ module.exports = function(AV) {
16041607 AV . Object . _findUnsavedChildren = function ( objects , children , files ) {
16051608 AV . _traverse ( objects , function ( object ) {
16061609 if ( object instanceof AV . Object ) {
1607- if ( object . _dirty ( ) ) {
1610+ if ( object . dirty ( ) ) {
16081611 children . push ( object ) ;
16091612 }
16101613 return ;
0 commit comments