@@ -7,6 +7,7 @@ var autoId = require('firebase-auto-ids');
77var Query = require ( './query' ) ;
88var Snapshot = require ( './snapshot' ) ;
99var Queue = require ( './queue' ) . Queue ;
10+ var Timestamp = require ( './timestamp' ) ;
1011var utils = require ( './utils' ) ;
1112var Auth = require ( './firebase-auth' ) ;
1213var validate = require ( './validators' ) ;
@@ -186,11 +187,11 @@ MockFirebase.prototype.update = function (changes, callback) {
186187 self . _defer ( 'update' , _ . toArray ( arguments ) , function ( ) {
187188 if ( ! err ) {
188189 var base = self . getData ( ) ;
189- var data = _ . isObject ( base ) ? base : { } ;
190+ var data = _ . isPlainObject ( base ) ? base : { } ;
190191 // operate as a multi-set
191192 _ . keys ( changes ) . forEach ( function ( key ) {
192193 var val = changes [ key ] ;
193- _ . set ( data , key . replace ( / ^ \/ / , '' ) . replace ( / \/ / g, '.' ) , _ . isObject ( val ) ? utils . updateToRtdbObject ( val ) : val ) ;
194+ _ . set ( data , key . replace ( / ^ \/ / , '' ) . replace ( / \/ / g, '.' ) , _ . isPlainObject ( val ) ? utils . updateToRtdbObject ( val ) : val ) ;
194195 } ) ;
195196 data = utils . removeEmptyRtdbProperties ( data ) ;
196197 self . _dataChanged ( data ) ;
@@ -444,16 +445,16 @@ MockFirebase.prototype._dataChanged = function (unparsedData) {
444445 var data = utils . cleanData ( unparsedData ) ;
445446
446447 if ( utils . isServerTimestamp ( data ) ) {
447- data = utils . getServerTime ( ) ;
448+ data = Timestamp . fromMillis ( utils . getServerTime ( ) ) ;
448449 }
449450
450451 if ( pri !== this . priority ) {
451452 this . _priChanged ( pri ) ;
452453 }
453454 if ( ! _ . isEqual ( data , this . data ) ) {
454455 // _.keys() in Lodash 3 automatically coerces non-object to object
455- var oldKeys = _ . isObject ( this . data ) ? _ . keys ( this . data ) . sort ( ) : [ ] ;
456- var newKeys = _ . isObject ( data ) ? _ . keys ( data ) . sort ( ) : [ ] ;
456+ var oldKeys = _ . isPlainObject ( this . data ) ? _ . keys ( this . data ) . sort ( ) : [ ] ;
457+ var newKeys = _ . isPlainObject ( data ) ? _ . keys ( data ) . sort ( ) : [ ] ;
457458 var keysToRemove = _ . difference ( oldKeys , newKeys ) ;
458459 var keysToChange = _ . difference ( newKeys , keysToRemove ) ;
459460 var events = [ ] ;
@@ -462,22 +463,22 @@ MockFirebase.prototype._dataChanged = function (unparsedData) {
462463 self . _removeChild ( key , events ) ;
463464 } ) ;
464465
465- if ( ! _ . isObject ( data ) ) {
466+ if ( ! _ . isPlainObject ( data ) ) {
466467 events . push ( false ) ;
467468 this . data = data ;
468469 }
469470 else {
470471 keysToChange . forEach ( function ( key ) {
471472 var childData = unparsedData [ key ] ;
472473 if ( utils . isServerTimestamp ( childData ) ) {
473- childData = utils . getServerTime ( ) ;
474+ childData = Timestamp . fromMillis ( utils . getServerTime ( ) ) ;
474475 }
475476 self . _updateOrAdd ( key , childData , events ) ;
476477 } ) ;
477478 }
478479
479480 // update order of my child keys
480- if ( _ . isObject ( this . data ) )
481+ if ( _ . isPlainObject ( this . data ) )
481482 this . _resort ( ) ;
482483
483484 // trigger parent notifications after all children have
@@ -488,7 +489,7 @@ MockFirebase.prototype._dataChanged = function (unparsedData) {
488489
489490MockFirebase . prototype . _priChanged = function ( newPriority ) {
490491 if ( utils . isServerTimestamp ( newPriority ) ) {
491- newPriority = utils . getServerTime ( ) ;
492+ newPriority = Timestamp . fromMillis ( utils . getServerTime ( ) ) ;
492493 }
493494 this . priority = newPriority ;
494495 if ( this . parent ) {
@@ -573,7 +574,7 @@ MockFirebase.prototype._triggerAll = function (events) {
573574} ;
574575
575576MockFirebase . prototype . _updateOrAdd = function ( key , data , events ) {
576- var exists = _ . isObject ( this . data ) && this . data . hasOwnProperty ( key ) ;
577+ var exists = _ . isPlainObject ( this . data ) && this . data . hasOwnProperty ( key ) ;
577578 if ( ! exists ) {
578579 return this . _addChild ( key , data , events ) ;
579580 }
@@ -583,7 +584,7 @@ MockFirebase.prototype._updateOrAdd = function (key, data, events) {
583584} ;
584585
585586MockFirebase . prototype . _addChild = function ( key , data , events ) {
586- if ( ! _ . isObject ( this . data ) ) {
587+ if ( ! _ . isPlainObject ( this . data ) ) {
587588 this . data = { } ;
588589 }
589590 this . _addKey ( key ) ;
@@ -610,7 +611,7 @@ MockFirebase.prototype._removeChild = function (key, events) {
610611
611612MockFirebase . prototype . _updateChild = function ( key , data , events ) {
612613 var cdata = utils . cleanData ( data ) ;
613- if ( _ . isObject ( this . data ) && _ . has ( this . data , key ) && ! _ . isEqual ( this . data [ key ] , cdata ) ) {
614+ if ( _ . isPlainObject ( this . data ) && _ . has ( this . data , key ) && ! _ . isEqual ( this . data [ key ] , cdata ) ) {
614615 this . data [ key ] = cdata ;
615616 var c = this . child ( key ) ;
616617 c . _dataChanged ( data ) ;
@@ -629,7 +630,7 @@ MockFirebase.prototype._nextErr = function (type) {
629630} ;
630631
631632MockFirebase . prototype . _hasChild = function ( key ) {
632- return _ . isObject ( this . data ) && _ . has ( this . data , key ) ;
633+ return _ . isPlainObject ( this . data ) && _ . has ( this . data , key ) ;
633634} ;
634635
635636MockFirebase . prototype . _childData = function ( key ) {
@@ -695,7 +696,7 @@ function extractName(path) {
695696}
696697
697698function render ( datum ) {
698- if ( datum && _ . isObject ( datum ) ) {
699+ if ( datum && _ . isPlainObject ( datum ) ) {
699700 var keys = _ . keys ( datum ) ;
700701
701702 if ( _ . every ( keys , RegExp . prototype . test . bind ( / ^ \d + $ / ) ) ) {
0 commit comments