Skip to content

Commit a80360b

Browse files
authored
Merge pull request #9 from florianbepunkt/master
fix presence() syntax
2 parents 50b709f + 1f1b7f1 commit a80360b

File tree

5 files changed

+142
-55
lines changed

5 files changed

+142
-55
lines changed

android/src/main/java/io/fullstack/firestack/database/FirestackDatabase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,16 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
286286
});
287287
}
288288

289+
@ReactMethod
290+
public void goOnline() {
291+
mFirebaseDatabase.goOnline();
292+
}
293+
294+
@ReactMethod
295+
public void goOffline() {
296+
mFirebaseDatabase.goOffline();
297+
}
298+
289299
private void handleCallback(
290300
final String methodName,
291301
final Callback callback,

ios/Firestack/FirestackDatabase.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ - (void) addEventHandler:(NSString *) eventName
5656
@"snapshot": props
5757
}];
5858
};
59-
6059
id errorBlock = ^(NSError * _Nonnull error) {
6160
NSLog(@"Error onDBEvent: %@", [error debugDescription]);
6261
[self getAndSendDatabaseError:error withPath: _path];
6362
};
64-
6563
int eventType = [self eventTypeFromName:eventName];
6664
FIRDatabaseHandle handle = [_query observeEventType:eventType
6765
withBlock:withBlock
@@ -139,7 +137,6 @@ - (NSDictionary *) snapshotToDict:(FIRDataSnapshot *) snapshot
139137
[dict setValue:snapshot.key forKey:@"key"];
140138
NSDictionary *val = snapshot.value;
141139
[dict setObject:val forKey:@"value"];
142-
143140
// Snapshot ordering
144141
NSMutableArray *childKeys = [NSMutableArray array];
145142
if (snapshot.childrenCount > 0) {
@@ -152,13 +149,11 @@ - (NSDictionary *) snapshotToDict:(FIRDataSnapshot *) snapshot
152149
[childKeys addObject:child.key];
153150
}
154151
}
155-
156152
[dict setObject:childKeys forKey:@"childKeys"];
157153
[dict setValue:@(snapshot.hasChildren) forKey:@"hasChildren"];
158154
[dict setValue:@(snapshot.exists) forKey:@"exists"];
159155
[dict setValue:@(snapshot.childrenCount) forKey:@"childrenCount"];
160156
[dict setValue:snapshot.priority forKey:@"priority"];
161-
162157
return dict;
163158
}
164159

@@ -171,7 +166,6 @@ - (NSDictionary *) getAndSendDatabaseError:(NSError *) error
171166
@"msg": [error debugDescription]
172167
};
173168
[self sendJSEvent:DATABASE_ERROR_EVENT title:DATABASE_ERROR_EVENT props: evt];
174-
175169
return evt;
176170
}
177171

@@ -471,7 +465,6 @@ - (id) init
471465
{
472466
FirestackDBReference *ref = [self getDBHandle:path modifiers:modifiers modifiersString:modifiersString];
473467
[ref addEventHandler:eventName];
474-
475468
callback(@[[NSNull null], @{
476469
@"status": @"success",
477470
@"handle": path
@@ -495,7 +488,6 @@ - (id) init
495488
{
496489
NSString *key = [self getDBListenerKey:path withModifiers:modifiersString];
497490
FirestackDBReference *ref = [_dbReferences objectForKey:key];
498-
499491
if (ref != nil) {
500492
if (eventName == nil || [eventName isEqualToString:@""]) {
501493
[ref cleanup];
@@ -507,7 +499,6 @@ - (id) init
507499
}
508500
}
509501
}
510-
511502
callback(@[[NSNull null], @{
512503
@"result": @"success",
513504
@"handle": path,
@@ -559,6 +550,16 @@ - (id) init
559550
}];
560551
}
561552

553+
RCT_EXPORT_METHOD(goOffline)
554+
{
555+
[FIRDatabase database].goOffline;
556+
}
557+
558+
RCT_EXPORT_METHOD(goOnline)
559+
{
560+
[FIRDatabase database].goOnline;
561+
}
562+
562563
- (FIRDatabaseReference *) getPathRef:(NSString *) path
563564
{
564565
return [[[FIRDatabase database] reference] child:path];
@@ -612,4 +613,5 @@ - (NSString *) getDBListenerKey:(NSString *) path
612613
return @[DATABASE_DATA_EVENT, DATABASE_ERROR_EVENT];
613614
}
614615

616+
615617
@end

lib/modules/database/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ export default class Database extends Base {
203203
return path.join('-');
204204
}
205205

206+
goOnline() {
207+
FirestackDatabase.goOnline();
208+
}
209+
210+
goOffline() {
211+
FirestackDatabase.goOffline();
212+
}
213+
206214
get namespace(): string {
207215
return 'firestack:database';
208216
}

lib/modules/presence.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class PresenceRef extends ReferenceBase {
77
super(presence.firestack);
88

99
this.presence = presence;
10-
const db = this.firestack.database;
10+
const db = this.firestack.database();
1111
this.ref = ref;
1212
this.lastOnlineRef = this.ref.child('lastOnline');
1313

@@ -84,7 +84,7 @@ export default class Presence extends Base {
8484
const path = this.path.concat(key);
8585
const pathKey = this._presenceKey(path);
8686
if (!this.instances[pathKey]) {
87-
const _ref = this.firestack.database.ref(pathKey);
87+
const _ref = this.firestack.database().ref(pathKey);
8888
this.log.debug('Created new presence object for ', pathKey);
8989
const inst = new PresenceRef(this, _ref, path);
9090

package.json

Lines changed: 111 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,98 @@
11
{
2-
"name": "react-native-firestack",
3-
"version": "2.3.3",
4-
"author": "Ari Lerner <ari@fullstack.io> (https://fullstackreact.com)",
5-
"description": "A firebase v3 adapter",
6-
"main": "index",
7-
"scripts": {
8-
"start": "node node_modules/react-native/local-cli/cli.js start",
9-
"build": "./node_modules/.bin/babel --source-maps=true --out-dir=dist .",
10-
"dev": "npm run compile -- --watch",
11-
"lint": "eslint ./src",
12-
"publish_pages": "gh-pages -d public/",
13-
"test": "./node_modules/.bin/mocha",
14-
"watchcpx": "node ./bin/watchCopy"
2+
"_args": [
3+
[
4+
{
5+
"raw": "https://github.com/Salakar/react-native-firestack",
6+
"scope": null,
7+
"escapedName": null,
8+
"name": null,
9+
"rawSpec": "https://github.com/Salakar/react-native-firestack",
10+
"spec": "git+https://github.com/Salakar/react-native-firestack.git",
11+
"type": "hosted",
12+
"hosted": {
13+
"type": "github",
14+
"ssh": "git@github.com:Salakar/react-native-firestack.git",
15+
"sshUrl": "git+ssh://git@github.com/Salakar/react-native-firestack.git",
16+
"httpsUrl": "git+https://github.com/Salakar/react-native-firestack.git",
17+
"gitUrl": "git://github.com/Salakar/react-native-firestack.git",
18+
"shortcut": "github:Salakar/react-native-firestack",
19+
"directUrl": "https://raw.githubusercontent.com/Salakar/react-native-firestack/master/package.json"
20+
}
21+
},
22+
"/Users/floriannorbertbepunkt/Dropbox/Dropbox Arbeit/Mister Bishop Studios/Roomary/roomary"
23+
]
24+
],
25+
"_from": "git+https://github.com/Salakar/react-native-firestack.git",
26+
"_id": "react-native-firestack@2.3.3",
27+
"_inCache": true,
28+
"_location": "/react-native-firestack",
29+
"_phantomChildren": {},
30+
"_requested": {
31+
"raw": "https://github.com/Salakar/react-native-firestack",
32+
"scope": null,
33+
"escapedName": null,
34+
"name": null,
35+
"rawSpec": "https://github.com/Salakar/react-native-firestack",
36+
"spec": "git+https://github.com/Salakar/react-native-firestack.git",
37+
"type": "hosted",
38+
"hosted": {
39+
"type": "github",
40+
"ssh": "git@github.com:Salakar/react-native-firestack.git",
41+
"sshUrl": "git+ssh://git@github.com/Salakar/react-native-firestack.git",
42+
"httpsUrl": "git+https://github.com/Salakar/react-native-firestack.git",
43+
"gitUrl": "git://github.com/Salakar/react-native-firestack.git",
44+
"shortcut": "github:Salakar/react-native-firestack",
45+
"directUrl": "https://raw.githubusercontent.com/Salakar/react-native-firestack/master/package.json"
46+
}
1547
},
16-
"repository": {
17-
"type": "git",
18-
"url": "https://github.com/fullstackreact/react-native-firestack.git"
48+
"_requiredBy": [
49+
"#USER",
50+
"/"
51+
],
52+
"_resolved": "git+https://github.com/Salakar/react-native-firestack.git#50b709f91cf4e9fd141ef94964405f88d4d2779d",
53+
"_shasum": "05959e918292eeb9d6a3c39d9afb493ad11d5348",
54+
"_shrinkwrap": null,
55+
"_spec": "https://github.com/Salakar/react-native-firestack",
56+
"_where": "/Users/floriannorbertbepunkt/Dropbox/Dropbox Arbeit/Mister Bishop Studios/Roomary/roomary",
57+
"author": {
58+
"name": "Ari Lerner",
59+
"email": "ari@fullstack.io",
60+
"url": "https://fullstackreact.com"
61+
},
62+
"bugs": {
63+
"url": "https://github.com/fullstackreact/react-native-firestack/issues"
64+
},
65+
"dependencies": {
66+
"bows": "^1.6.0",
67+
"es6-symbol": "^3.1.0"
68+
},
69+
"description": "A firebase v3 adapter",
70+
"devDependencies": {
71+
"babel-eslint": "^7.0.0",
72+
"babel-jest": "^14.1.0",
73+
"babel-preset-react-native": "^1.9.0",
74+
"cpx": "^1.5.0",
75+
"debug": "^2.2.0",
76+
"enzyme": "^2.4.1",
77+
"eslint": "^3.8.1",
78+
"eslint-config-airbnb": "^12.0.0",
79+
"eslint-plugin-flowtype": "^2.20.0",
80+
"eslint-plugin-import": "^2.0.1",
81+
"eslint-plugin-jsx-a11y": "^2.2.3",
82+
"eslint-plugin-react": "^6.4.1",
83+
"flow-bin": "^0.35.0",
84+
"jest": "^14.1.0",
85+
"jest-react-native": "^14.1.3",
86+
"mocha": "^3.0.2",
87+
"react": "^15.3.0",
88+
"react-dom": "^15.3.0",
89+
"react-native-mock": "^0.2.6",
90+
"react-test-renderer": "^15.3.0",
91+
"should": "^11.1.0",
92+
"sinon": "^2.0.0-pre.2"
1993
},
94+
"gitHead": "50b709f91cf4e9fd141ef94964405f88d4d2779d",
95+
"homepage": "https://github.com/fullstackreact/react-native-firestack#readme",
2096
"jest": {
2197
"preset": "jest-react-native",
2298
"setupFiles": [],
@@ -27,18 +103,27 @@
27103
"./node_modules/react-addons-test-utils"
28104
]
29105
},
30-
"license": "ISC",
31106
"keywords": [
32107
"react",
33108
"react-native",
34109
"react-native-firestack",
35110
"firestack",
36111
"firebase"
37112
],
113+
"license": "ISC",
114+
"main": "index",
115+
"name": "react-native-firestack",
116+
"optionalDependencies": {},
38117
"peerDependencies": {
39118
"react": "*",
40119
"react-native": "*"
41120
},
121+
"readme": "# Firestack\n\nFirestack makes using the latest [Firebase](http://firebase.com) with React Native straight-forward.\n\n```\nnpm i react-native-firestack --save\n```\n\n[![Gitter](https://badges.gitter.im/fullstackreact/react-native-firestack.svg)](https://gitter.im/fullstackreact/react-native-firestack?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)\n[![npm version](https://img.shields.io/npm/v/react-native-firestack.svg)](https://www.npmjs.com/package/react-native-firestack)\n[![License](https://img.shields.io/npm/l/react-native-firestack.svg)](/LICENSE)\n\nFirestack is a _light-weight_ layer sitting on-top of the native Firebase libraries for both iOS and Android which mirrors the React Native JS api as closely as possible.\n\nFeaturing; authentication, storage, real-time database, presence, analytics, cloud messaging, remote configuration, redux support and more!\n\n## Firestack vs Firebase JS lib\n\nAlthough the [Firebase](https://www.npmjs.com/package/firebase) JavaScript library will work with React Native, it is mainly designed for the web. \n\nThe native SDK's are much better for performance compared to the web SDK. The web SDK will run on the same thread as your apps ([JS thread](https://facebook.github.io/react-native/docs/performance.html#javascript-frame-rate)) therefore limiting your JS framerate, potentially affecting things touch events and transitions/animations.\n\nThe native SDK's also contains functionality that the web SDK's do not, for example [Analytics](/docs/api/analytics.md) and [Remote Config](/docs/api/remote-config.md).\n\n## Example app\n\nWe have a working application example available in at [fullstackreact/FirestackApp](https://github.com/fullstackreact/FirestackApp). Check it out for more details about how to use Firestack.\n\n## Documentation\n\n* Installation\n * [iOS](docs/installation.ios.md)\n * [Android](docs/installation.android.md)\n* [Firebase Setup](docs/firebase-setup.md)\n* API\n * [Authentication](docs/api/authentication.md)\n * [Analytics](docs/api/analytics.md)\n * [Storage](docs/api/storage.md)\n * [Realtime Database](docs/api/database.md)\n * [Presence](docs/api/presence.md)\n * [ServerValue](docs/api/server-value.md)\n * [Cloud Messaging](docs/api/cloud-messaging.md)\n * [Remote Config](docs/api/remote-config.md)\n * [Events](docs/api/events.md)\n* [Redux](docs/redux.md)\n\n## Contributing\n\nFor a detailed discussion of how Firestack works as well as how to contribute, check out our [contribution guide](https://github.com/fullstackreact/react-native-firestack/blob/master/Contributing.md).\n",
122+
"readmeFilename": "README.md",
123+
"repository": {
124+
"type": "git",
125+
"url": "git+https://github.com/fullstackreact/react-native-firestack.git"
126+
},
42127
"rnpm": {
43128
"commands": {
44129
"prelink": "node_modules/react-native-firestack/bin/prepare.sh",
@@ -51,32 +136,14 @@
51136
"packageInstance": "new FirestackPackage()"
52137
}
53138
},
54-
"devDependencies": {
55-
"babel-eslint": "^7.0.0",
56-
"babel-jest": "^14.1.0",
57-
"babel-preset-react-native": "^1.9.0",
58-
"cpx": "^1.5.0",
59-
"debug": "^2.2.0",
60-
"enzyme": "^2.4.1",
61-
"eslint": "^3.8.1",
62-
"eslint-config-airbnb": "^12.0.0",
63-
"eslint-plugin-flowtype": "^2.20.0",
64-
"eslint-plugin-import": "^2.0.1",
65-
"eslint-plugin-jsx-a11y": "^2.2.3",
66-
"eslint-plugin-react": "^6.4.1",
67-
"flow-bin": "^0.35.0",
68-
"jest": "^14.1.0",
69-
"jest-react-native": "^14.1.3",
70-
"mocha": "^3.0.2",
71-
"react": "^15.3.0",
72-
"react-dom": "^15.3.0",
73-
"react-native-mock": "^0.2.6",
74-
"react-test-renderer": "^15.3.0",
75-
"should": "^11.1.0",
76-
"sinon": "^2.0.0-pre.2"
139+
"scripts": {
140+
"build": "babel --source-maps=true --out-dir=dist .",
141+
"dev": "npm run compile -- --watch",
142+
"lint": "eslint ./src",
143+
"publish_pages": "gh-pages -d public/",
144+
"start": "node node_modules/react-native/local-cli/cli.js start",
145+
"test": "mocha",
146+
"watchcpx": "node ./bin/watchCopy"
77147
},
78-
"dependencies": {
79-
"bows": "^1.6.0",
80-
"es6-symbol": "^3.1.0"
81-
}
148+
"version": "2.3.3"
82149
}

0 commit comments

Comments
 (0)