Skip to content
This repository was archived by the owner on Jan 26, 2021. It is now read-only.

Commit 80c04f8

Browse files
committed
Get current user working in RN, bump to 0.5.0
1 parent 1f19ff2 commit 80c04f8

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parse-react",
3-
"version": "0.4.3",
3+
"version": "0.5.0",
44
"description": "Use Parse data in React applications",
55
"homepage": "https://github.com/ParsePlatform/ParseReact",
66
"keywords": [
@@ -17,7 +17,7 @@
1717
"bugs": "https://github.com/ParsePlatform/ParseReact/issues",
1818
"files": [
1919
"index.js",
20-
"class.js",
20+
"react-native.js",
2121
"lib/",
2222
"LICENSE",
2323
"README.md"

src/LocalSubscriptions.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ var currentUser = {
4545
this.subscribers[observerId] = callbacks;
4646
var id;
4747

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) {
4957
id = new Id('_User', Parse.User.current().id);
5058
if (!ObjectStore.getLatest(id)) {
5159
ObjectStore.storeObject(flatten(Parse.User.current()));
@@ -74,31 +82,32 @@ var currentUser = {
7482
},
7583

7684
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+
}
8796
}
97+
Parse.CoreManager.getUserController().setCurrentUser(current);
8898
}
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+
}
98107
}
108+
this.subscribers[oid].onNext(latest);
99109
}
100-
this.subscribers[oid].onNext(latest);
101-
}
110+
});
102111
}
103112
};
104113

0 commit comments

Comments
 (0)