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

Commit

Permalink
Get current user working in RN, bump to 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewimm committed Sep 12, 2015
1 parent 1f19ff2 commit 80c04f8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parse-react",
"version": "0.4.3",
"version": "0.5.0",
"description": "Use Parse data in React applications",
"homepage": "https://github.com/ParsePlatform/ParseReact",
"keywords": [
Expand All @@ -17,7 +17,7 @@
"bugs": "https://github.com/ParsePlatform/ParseReact/issues",
"files": [
"index.js",
"class.js",
"react-native.js",
"lib/",
"LICENSE",
"README.md"
Expand Down
53 changes: 31 additions & 22 deletions src/LocalSubscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ var currentUser = {
this.subscribers[observerId] = callbacks;
var id;

if (Parse.User.current()) {
var current = null;
try {
// Attempt to get the user synchronously, if it's in cache
current = Parse.User.current();
} catch(e) {
// Using an asynchronous storage with no cache
// Fail over to the currentAsync() fetch
}
if (current) {
id = new Id('_User', Parse.User.current().id);
if (!ObjectStore.getLatest(id)) {
ObjectStore.storeObject(flatten(Parse.User.current()));
Expand Down Expand Up @@ -74,31 +82,32 @@ var currentUser = {
},

update: function(changes: { [key: string]: any }) {
var current = Parse.User.current();
if (current !== null) {
for (var attr in changes) {
if (attr !== 'id' &&
attr !== 'objectId' &&
attr !== 'className' &&
attr !== 'sessionToken' &&
attr !== 'createdAt' &&
attr !== 'updatedAt') {
current.set(attr, changes[attr]);
Parse.User.currentAsync().then((current) => {
if (current !== null) {
for (var attr in changes) {
if (attr !== 'id' &&
attr !== 'objectId' &&
attr !== 'className' &&
attr !== 'sessionToken' &&
attr !== 'createdAt' &&
attr !== 'updatedAt') {
current.set(attr, changes[attr]);
}
}
Parse.CoreManager.getUserController().setCurrentUser(current);
}
Parse.CoreManager.getUserController().setCurrentUser(current);
}
for (var oid in this.subscribers) {
var latest = null;
if (current) {
latest = ObjectStore.getLatest(new Id('_User', current.id));
if (latest === null) {
latest = flatten(current);
ObjectStore.storeObject(latest);
for (var oid in this.subscribers) {
var latest = null;
if (current) {
latest = ObjectStore.getLatest(new Id('_User', current.id));
if (latest === null) {
latest = flatten(current);
ObjectStore.storeObject(latest);
}
}
this.subscribers[oid].onNext(latest);
}
this.subscribers[oid].onNext(latest);
}
});
}
};

Expand Down

0 comments on commit 80c04f8

Please sign in to comment.