Skip to content

Commit 1f1bd2d

Browse files
author
Chris Raynor
committed
Merge pull request #93 from firebase/jw-remove-rsvp
Removed RSVP dependency and made Firebase a peer dependency
2 parents 5261038 + f1a553f commit 1f1bd2d

File tree

8 files changed

+101
-73
lines changed

8 files changed

+101
-73
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
node_js:
33
- '0.12'
4-
- stable
4+
#- stable
55
sudo: false
66
before_install:
77
- export DISPLAY=:99.0

README.md

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# GeoFire for JavaScript — Realtime location queries with Firebase
22

33
[![Build Status](https://travis-ci.org/firebase/geofire-js.svg?branch=master)](https://travis-ci.org/firebase/geofire-js)
4-
[![Coverage Status](https://img.shields.io/coveralls/firebase/geofire-js.svg?branch=master&style=flat)](https://coveralls.io/r/firebase/geofire-js)
4+
[![Coverage Status](https://coveralls.io/repos/github/firebase/geofire-js/badge.svg?branch=master)](https://coveralls.io/github/firebase/geofire-js?branch=master)
55
[![Version](https://badge.fury.io/gh/firebase%2Fgeofire-js.svg)](http://badge.fury.io/gh/firebase%2Fgeofire-js)
66

77
GeoFire is an open-source library that allows you to store and query a set of keys based on their
@@ -50,56 +50,35 @@ using Security and Firebase Rules.
5050

5151
## Upgrading GeoFire
5252

53-
### Upgrading from GeoFire 2.x.x to 3.x.x
54-
55-
GeoFire 3.x has the same API as 2.x but uses a different underlying data structure to store its
56-
location data. If you are currently using 2.x and want to upgrade to 3.x, you must run the
57-
[GeoFire 3.x migration script](https://github.com/firebase/geofire-js/blob/master/migration/migrateToV3.js)
58-
on your Firebase database. This Node.js script only needs to be run one time and should take only a few seconds
59-
to minutes depending on the size of your data. To run the script, copy the files in this repo's
60-
`/migration/` folder to your machine and run the following commands:
61-
62-
```bash
63-
$ npm install # install local npm dependencies
64-
$ node migrateToV3.js # display usage instructions
65-
```
66-
67-
### Upgrading from GeoFire 3.0.x to 3.1.x
68-
69-
With the release of GeoFire 3.1.0, this library now uses [the new query functionality found in
70-
Firebase 2.0.0](https://www.firebase.com/blog/2014-11-04-firebase-realtime-queries.html). As a
71-
result, you will need to upgrade to Firebase 2.x.x and add a new `.indexOn` rule to your Security
72-
and Firebase Rules to get the best performance. You can view [the updated rules here](./examples/securityRules/rules.json)
73-
and [read our docs for more information about indexing your data](https://www.firebase.com/docs/security/guide/indexing-data.html).
53+
Using an older version of GeoFire and want to upgrade to the latest version? Check out our
54+
[migration guides](./migration) to find out how!
7455

7556

7657
## Downloading GeoFire
7758

7859
In order to use GeoFire in your project, you need to include the following files in your HTML:
7960

8061
```html
81-
<!-- RSVP -->
82-
<script src="rsvp.min.js"></script>
83-
8462
<!-- Firebase -->
85-
<script src="https://cdn.firebase.com/js/client/2.2.5/firebase.js"></script>
63+
<script src="https://cdn.firebase.com/js/client/2.4.1/firebase.js"></script>
8664

8765
<!-- GeoFire -->
88-
<script src="https://cdn.firebase.com/libs/geofire/3.2.4/geofire.min.js"></script>
66+
<script src="https://cdn.firebase.com/libs/geofire/4.0.0/geofire.min.js"></script>
8967
```
9068

9169
Use the URL above to download both the minified and non-minified versions of GeoFire from the
9270
Firebase CDN. You can also download them from the
9371
[releases page of this GitHub repository](https://github.com/firebase/geofire-js/releases).
94-
[Firebase](https://www.firebase.com/docs/web/quickstart.html?utm_source=geofire-js) and
95-
[RSVP](https://github.com/tildeio/rsvp.js/) can be downloaded directly from their respective websites.
9672

97-
You can also install GeoFire via npm or Bower and its dependencies will be downloaded automatically:
73+
You can also install GeoFire via npm or Bower. If downloading via npm, you will have to install
74+
Firebase separately (because it is a peer dependency to GeoFire):
9875

9976
```bash
100-
$ npm install geofire --save
77+
$ npm install geofire firebase --save
10178
```
10279

80+
On Bower, the Firebase dependency will be downloaded automatically:
81+
10382
```bash
10483
$ bower install geofire --save
10584
```
@@ -393,9 +372,13 @@ var distance = GeoFire.distance(location1, location2); // distance === 12378.53
393372

394373
## Promises
395374

396-
GeoFire uses promises when writing and retrieving data. Promises represent the result of a potentially long-running operation and allow code to run asynchronously. Upon completion of the operation, the promise will be "resolved" / "fulfilled" with the operation's result. This result will be passed to the function defined in the promise's `then()` method.
375+
GeoFire uses promises when writing and retrieving data. Promises represent the result of a potentially
376+
long-running operation and allow code to run asynchronously. Upon completion of the operation, the
377+
promise will be "resolved" / "fulfilled" with the operation's result. This result will be passed to
378+
the function defined in the promise's `then()` method.
397379

398-
GeoFire uses the lightweight RSVP.js library to provide an implementation of JavaScript promises. If you are unfamiliar with promises, please refer to the [RSVP.js documentation](https://github.com/tildeio/rsvp.js/). Here is a quick example of how to consume a promise:
380+
If you are unfamiliar with promises, check out [this blog post](http://www.html5rocks.com/en/tutorials/es6/promises).
381+
Here is a quick example of how to consume a promise:
399382

400383
```JavaScript
401384
promise.then(function(result) {

bower.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
"changelog.txt"
3434
],
3535
"dependencies": {
36-
"firebase": "2.x.x",
37-
"rsvp": "3.1.x"
36+
"firebase": "^2.4.0"
3837
},
3938
"devDependencies": {
40-
"jasmine": "~2.0.0"
39+
"jasmine": "~2.0.0",
40+
"rsvp": "^3.1.0"
4141
}
4242
}

build/header

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,5 @@
1010
* License: MIT
1111
*/
1212

13-
// Include RSVP if this is being run in node
14-
if (typeof module !== "undefined" && typeof process !== "undefined") {
15-
var RSVP = require("rsvp");
16-
}
17-
1813
var GeoFire = (function() {
19-
"use strict";
14+
"use strict";

migration/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Upgrading GeoFire
2+
3+
Below are instructions for migrating from one version of GeoFire to another. If you are upgrading
4+
several versions at once, make sure you follow the migration instructions for all upgrades.
5+
6+
7+
## Upgrading from GeoFire `3.x.x` to `4.x.x`
8+
9+
Let's start off with the good news: RSVP is no longer required required at all to run GeoFire! That
10+
means you can remove RSVP entirely if you aren't using it elsewhere in your project.
11+
12+
The slightly bad news is that you may need to upgrade your Firebase dependency because GeoFire now
13+
uses [the new promises functionality found in Firebase `2.4.0`](https://www.firebase.com/blog/2016-01-21-keeping-our-promises.html).
14+
Thankfully, upgrading should be as easy as upgrading the Firebase version you are using to `2.4.0`
15+
or higher (if it isn't already).
16+
17+
For you folks using GeoFire with npm, there is one more change you may have to make. With this
18+
release `firebase` is now a peer dependency of `geofire` instead of a regular dependency. As such,
19+
you will need to make sure `firebase` is listed as a regular dependency alongside `geofire` in your
20+
`package.json` (if it isn't already):
21+
22+
```js
23+
// package.json with GeoFire 3.x.x
24+
{
25+
// ...
26+
"dependencies": {
27+
"geofire": "^3.0.0"
28+
},
29+
// ...
30+
}
31+
32+
// package.json with GeoFire 4.x.x
33+
{
34+
// ...
35+
"dependencies": {
36+
"firebase": "^2.4.0",
37+
"geofire": "^4.0.0"
38+
},
39+
// ...
40+
}
41+
```
42+
43+
44+
## Upgrading from GeoFire `3.0.x` to `3.1.x`
45+
46+
With the release of GeoFire `3.1.0`, GeoFire now uses [the new query functionality found in Firebase
47+
`2.0.0`](https://www.firebase.com/blog/2014-11-04-firebase-realtime-queries.html). As a
48+
result, you will need to upgrade to Firebase `2.x.x` and add a new `.indexOn` rule to your Security
49+
and Firebase Rules to get the best performance. You can view [the updated rules here](../examples/securityRules/rules.json)
50+
and [read our docs for more information about indexing your data](https://www.firebase.com/docs/security/guide/indexing-data.html).
51+
52+
53+
## Upgrading from GeoFire `2.x.x` to `3.x.x`
54+
55+
GeoFire `3.x.x` has the same API as `2.x.x` but uses a different underlying data structure to store
56+
its location data. If you are currently using `2.x.x` and want to upgrade to `3.x.x`, you must run
57+
the [GeoFire 3.x migration script](./migrateToV3.js) on your Firebase database. This Node.js script
58+
only needs to be run one time and should take only a few seconds to minutes depending on the size of
59+
your data. To run the script, copy the files in this repo's `/migration` folder to your machine and
60+
run the following commands:
61+
62+
```bash
63+
$ npm install firebase rsvp # install needed dependencies
64+
$ node migrateToV3.js # display usage instructions
65+
```
66+

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"README.md",
2727
"package.json"
2828
],
29-
"dependencies": {
30-
"firebase": "2.x.x",
31-
"rsvp": "3.1.x"
29+
"dependencies": {},
30+
"peerDependencies": {
31+
"firebase": "^2.4.0"
3232
},
3333
"devDependencies": {
3434
"coveralls": "2.11.4",

src/geoFire.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,7 @@ var GeoFire = function(firebaseRef) {
6060
}
6161
});
6262

63-
return new RSVP.Promise(function(resolve, reject) {
64-
function onComplete(error) {
65-
if (error !== null) {
66-
reject("Error: Firebase synchronization failed: " + error);
67-
}
68-
else {
69-
resolve();
70-
}
71-
}
72-
73-
_firebaseRef.update(newData, onComplete);
74-
});
63+
return _firebaseRef.update(newData);
7564
};
7665

7766
/**
@@ -84,16 +73,13 @@ var GeoFire = function(firebaseRef) {
8473
*/
8574
this.get = function(key) {
8675
validateKey(key);
87-
return new RSVP.Promise(function(resolve, reject) {
88-
_firebaseRef.child(key).once("value", function(dataSnapshot) {
89-
if (dataSnapshot.val() === null) {
90-
resolve(null);
91-
} else {
92-
resolve(decodeGeoFireObject(dataSnapshot.val()));
93-
}
94-
}, function (error) {
95-
reject("Error: Firebase synchronization failed: " + error);
96-
});
76+
return _firebaseRef.child(key).once("value").then(function(dataSnapshot) {
77+
var snapshotVal = dataSnapshot.val();
78+
if (snapshotVal === null) {
79+
return null;
80+
} else {
81+
return decodeGeoFireObject(snapshotVal);
82+
}
9783
});
9884
};
9985

tests/specs/common.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,15 @@ function generateRandomString() {
7272

7373
/* Returns the current data in the Firebase */
7474
function getFirebaseData() {
75-
return new RSVP.Promise(function(resolve, reject) {
76-
firebaseRef.once("value", function(dataSnapshot) {
77-
resolve(dataSnapshot.exportVal());
78-
});
75+
return firebaseRef.once("value").then(function(dataSnapshot) {
76+
return dataSnapshot.exportVal();
7977
});
8078
};
8179

8280

8381
/* Returns a promise which is fulfilled after the inputted number of milliseconds pass */
8482
function wait(milliseconds) {
85-
return new RSVP.Promise(function(resolve, reject) {
83+
return new RSVP.Promise(function(resolve) {
8684
var timeout = window.setTimeout(function() {
8785
window.clearTimeout(timeout);
8886
resolve();

0 commit comments

Comments
 (0)