@@ -45,7 +45,15 @@ var currentUser = {
45
45
this . subscribers [ observerId ] = callbacks ;
46
46
var id ;
47
47
48
- if ( Parse . User . current ( ) ) {
48
+ var current = null ;
49
+ try {
50
+ // Attempt to get the user synchronously, if it's in cache
51
+ current = Parse . User . current ( ) ;
52
+ } catch ( e ) {
53
+ // Using an asynchronous storage with no cache
54
+ // Fail over to the currentAsync() fetch
55
+ }
56
+ if ( current ) {
49
57
id = new Id ( '_User' , Parse . User . current ( ) . id ) ;
50
58
if ( ! ObjectStore . getLatest ( id ) ) {
51
59
ObjectStore . storeObject ( flatten ( Parse . User . current ( ) ) ) ;
@@ -74,31 +82,32 @@ var currentUser = {
74
82
} ,
75
83
76
84
update: function ( changes : { [ key : string ] : any } ) {
77
- var current = Parse . User . current ( ) ;
78
- if ( current !== null ) {
79
- for ( var attr in changes ) {
80
- if ( attr !== 'id' &&
81
- attr !== 'objectId' &&
82
- attr !== 'className' &&
83
- attr !== 'sessionToken' &&
84
- attr !== 'createdAt' &&
85
- attr !== 'updatedAt' ) {
86
- current . set ( attr , changes [ attr ] ) ;
85
+ Parse . User . currentAsync ( ) . then ( ( current ) => {
86
+ if ( current !== null ) {
87
+ for ( var attr in changes ) {
88
+ if ( attr !== 'id' &&
89
+ attr !== 'objectId' &&
90
+ attr !== 'className' &&
91
+ attr !== 'sessionToken' &&
92
+ attr !== 'createdAt' &&
93
+ attr !== 'updatedAt' ) {
94
+ current . set ( attr , changes [ attr ] ) ;
95
+ }
87
96
}
97
+ Parse . CoreManager . getUserController ( ) . setCurrentUser ( current ) ;
88
98
}
89
- Parse . CoreManager . getUserController ( ) . setCurrentUser ( current ) ;
90
- }
91
- for ( var oid in this . subscribers ) {
92
- var latest = null ;
93
- if ( current ) {
94
- latest = ObjectStore . getLatest ( new Id ( '_User' , current . id ) ) ;
95
- if ( latest === null ) {
96
- latest = flatten ( current ) ;
97
- ObjectStore . storeObject ( latest ) ;
99
+ for ( var oid in this . subscribers ) {
100
+ var latest = null ;
101
+ if ( current ) {
102
+ latest = ObjectStore . getLatest ( new Id ( '_User' , current . id ) ) ;
103
+ if ( latest === null ) {
104
+ latest = flatten ( current ) ;
105
+ ObjectStore . storeObject ( latest ) ;
106
+ }
98
107
}
108
+ this . subscribers [ oid ] . onNext ( latest ) ;
99
109
}
100
- this . subscribers [ oid ] . onNext ( latest ) ;
101
- }
110
+ } ) ;
102
111
}
103
112
} ;
104
113
0 commit comments