Skip to content

Commit c5c602b

Browse files
author
Jacob Wenger
committed
Merge pull request #2 from firebase/gulp
Added gulp integration to smooth out release process
2 parents d49b3fe + 0c02dec commit c5c602b

14 files changed

+196
-103
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
node_modules
12
bower_components
23
firebase.json

.jshintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"bitwise": true,
3+
"curly": true,
4+
"eqeqeq": true,
5+
"forin": true,
6+
"freeze": true,
7+
"indent": 2,
8+
"latedef": true,
9+
"quotmark": "double",
10+
"strict": true,
11+
"trailing": true,
12+
"undef": true,
13+
"unused": true
14+
}

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
v0.1.3
2+
-------------
3+
Release Date: 2014-05-02
4+
5+
* Bug fix for misnamed variable in _toArray() method (submitted by @danielmahal)
6+
* Added gulp integration to lint, minify, and test code
7+
18
v0.1.2
29
-------------
310
Release Date: 2014-05-02

README.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
ReactFire
2-
=========
1+
# ReactFire
32

43
ReactFireMixin is an officially supported [ReactJS](http://facebook.github.io/react/) mixin
54
for [Firebase](http://www.firebase.com/). Firebase provides your React app with a
65
persistent, realtime backend to effortlessly keep all of your clients in sync!
76

87
Read our [blog post](https://firebase.com/blog/2014-05-01-using-firebase-with-react.html) on using Firebase with React and check out our [live Todo app demo](https://reactfiretodoapp.firebaseapp.com/) to get started!
98

10-
Usage
11-
-----
9+
## Usage
10+
1211
The ReactFireMixin can be added to you project in two ways:
1312

1413
* Manually copy ReactFireMixin.js from GitHub to you local directory.
@@ -21,8 +20,8 @@ To use the ReactFireMixin in a React component, add it to the component's mixins
2120
...
2221
});
2322

24-
API Reference
25-
-------------
23+
## API Reference
24+
2625
###bindAsArray(firebaseRef, bindVar)
2726

2827
Creates a binding between Firebase and the inputted bind variable as an array. The Firebase
@@ -45,6 +44,24 @@ with that Firebase reference.
4544

4645
this.unbind("items");
4746

48-
License
49-
-------
50-
[MIT](http://firebase.mit-license.org)
47+
## Contributing
48+
49+
Interested in manually debugging from source or submitting a pull request? Follow the steps
50+
below.
51+
52+
### Install Dependencies
53+
54+
```bash
55+
$ git clone https://github.com/firebase/ReactFire.git # clone this repository
56+
$ npm install # install local NPM build / test dependencies
57+
```
58+
59+
### Compile
60+
61+
```bash
62+
$ gulp
63+
```
64+
65+
## License
66+
67+
[Firebase MIT License](http://firebase.mit-license.org)

ReactFireMixin.js

Lines changed: 0 additions & 78 deletions
This file was deleted.

bower.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "ReactFire",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"homepage": "https://github.com/firebase/ReactFire",
55
"authors": [
66
"jacobawenger <jacob@firebase.com>"
77
],
88
"description": "Firebase mixin for ReactJS",
9-
"main": "ReactFireMixin.js",
9+
"main": "js/ReactFireMixin.min.js",
1010
"keywords": [
1111
"react",
1212
"firebase"
@@ -15,6 +15,8 @@
1515
"ignore": [
1616
"**/.*",
1717
"./CHANGELOG.md",
18+
"./gulpfile.js",
19+
"./package.json",
1820
"examples",
1921
"node_modules",
2022
"bower_components"

examples/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
ReactFire Examples
2-
==================
1+
# ReactFire Examples
32

43
Have you come up with a cool example that uses the ReactFireMixin? Submit a pull request and share
54
it with everyone else by putting in this /examples/ directory. Please make sure to include a README.md

examples/todoApp/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
ReactFire Todo App Example
2-
==========================
1+
# ReactFire Todo App Example
32

4-
Live Demo
5-
---------
3+
## Live Demo
64
You can view a live version of this demo [here](https://reactfiretodoapp.firebaseapp.com/).
75

8-
Setup Instructions
9-
--------------------
6+
## Setup Instructions
7+
108
To run this example locally, either download the whole ReactFire repo or just this /todoApp/
119
directory. From the /todoApp/ directory, install the needed dependencies via bower:
1210

@@ -22,8 +20,8 @@ $ python -m SimpleHTTPServer 8080
2220

2321
Now you should be able to visit the example in the browser of your choice at [http://127.0.0.1:8080/](http://127.0.0.1:8080/).
2422

25-
Description
26-
-----------
23+
## Description
24+
2725
This example shows three different ways to make a Todo app using React. It is adapted from the
2826
Todo app example on the [ReactJS homepage](http://facebook.github.io/react/). There are three
2927
different versions of the Todo app example:
@@ -37,6 +35,6 @@ made to this example are persistent.
3735
3. __ReactFireMixin:__ A version of the first example which uses the ReactFireMixin. Changes made to
3836
this example are persistent.
3937

40-
Walkthrough
41-
-----------
38+
## Walkthrough
39+
4240
To learn more about how this example works, see the [blog post on the official Firebase blog](https://www.firebase.com/blog/2014-05-01-using-firebase-with-react.html).

examples/todoApp/bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
"dependencies": {
2424
"react": "~0.10.0",
2525
"firebase": "~1.0.12",
26-
"ReactFire": "~0.1.2"
26+
"ReactFire": "~0.1.3"
2727
}
2828
}

examples/todoApp/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<script src="bower_components/firebase/firebase.js"></script>
1212

1313
<!-- ReactFireMixin -->
14-
<script src="bower_components/ReactFire/ReactFireMixin.js"></script>
14+
<script src="bower_components/ReactFire/js/ReactFireMixin.min.js"></script>
1515

1616
<!-- Custom JS -->
1717
<script type="text/jsx" src="js/todoAppOriginal.js"></script>

gulpfile.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var gulp = require("gulp");
2+
var jshint = require("gulp-jshint");
3+
var uglify = require("gulp-uglify");
4+
var extReplace = require("gulp-ext-replace");
5+
6+
gulp.task("scripts", function() {
7+
// Load the code, and process it.
8+
var code = gulp.src("js/ReactFireMixin.js")
9+
.pipe(jshint())
10+
.pipe(jshint.reporter("jshint-stylish"))
11+
.pipe(uglify())
12+
.pipe(extReplace(".min.js"))
13+
.pipe(gulp.dest("js"));
14+
});
15+
16+
gulp.task("default", ["scripts"]);

js/ReactFireMixin.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
var ReactFireMixin;
2+
3+
(function() {
4+
"use strict";
5+
6+
ReactFireMixin = {
7+
/********************/
8+
/* MIXIN LIFETIME */
9+
/********************/
10+
/* Initializes the Firebase binding refs array */
11+
componentWillMount: function() {
12+
this.firebaseRefs = {};
13+
},
14+
15+
/* Removes any remaining Firebase bindings */
16+
componentWillUnmount: function() {
17+
for (var key in this.firebaseRefs) {
18+
if (this.firebaseRefs.hasOwnProperty(key)) {
19+
this.unbind(key);
20+
}
21+
}
22+
},
23+
24+
25+
/*************/
26+
/* BINDING */
27+
/*************/
28+
/* Creates a binding between Firebase and the inputted bind variable as an array */
29+
bindAsArray: function(firebaseRef, bindVar) {
30+
this._bind(firebaseRef, bindVar, true);
31+
},
32+
33+
/* Creates a binding between Firebase and the inputted bind variable as an object */
34+
bindAsObject: function(firebaseRef, bindVar) {
35+
this._bind(firebaseRef, bindVar, false);
36+
},
37+
38+
/* Creates a binding between Firebase and the inputted bind variable as either an array or object */
39+
_bind: function(firebaseRef, bindVar, bindAsArray) {
40+
this.firebaseRefs[bindVar] = firebaseRef;
41+
firebaseRef.on("value", function(dataSnapshot) {
42+
var newState = {};
43+
if (bindAsArray) {
44+
newState[bindVar] = this._toArray(dataSnapshot.val());
45+
}
46+
else {
47+
newState[bindVar] = dataSnapshot.val();
48+
}
49+
this.setState(newState);
50+
}.bind(this));
51+
},
52+
53+
/* Removes the binding between Firebase and the inputted bind variable */
54+
unbind: function(bindVar) {
55+
this.firebaseRefs[bindVar].off("value");
56+
delete this.firebaseRefs[bindVar];
57+
},
58+
59+
60+
/*************/
61+
/* HELPERS */
62+
/*************/
63+
/* Returns true if the inputted object is a JavaScript array */
64+
_isArray: function(obj) {
65+
return (obj && typeof obj === "object" && obj instanceof Array);
66+
},
67+
68+
/* Converts a Firebase object to a JavaScript array */
69+
_toArray: function(obj) {
70+
var out = [];
71+
if (obj) {
72+
if (this._isArray(obj)) {
73+
out = obj;
74+
}
75+
else if (typeof(obj) === "object") {
76+
for (var key in obj) {
77+
if (obj.hasOwnProperty(key)) {
78+
out.push(obj[key]);
79+
}
80+
}
81+
}
82+
}
83+
return out;
84+
}
85+
};
86+
})();

js/ReactFireMixin.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "ReactFire",
3+
"description": "Firebase mixin for ReactJS",
4+
"main": "ReactFireMixin.js",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/firebase/ReactFire.git"
8+
},
9+
"bugs": {
10+
"url": "https://github.com/firebase/ReactFire/issues"
11+
},
12+
"private": true,
13+
"licenses": [
14+
{
15+
"type": "MIT",
16+
"url": "http://firebase.mit-license.org/"
17+
}
18+
],
19+
"version": "0.1.3",
20+
"dependencies": {
21+
"firebase": "~1.0.11"
22+
},
23+
"devDependencies": {
24+
"gulp": "^3.5.6",
25+
"gulp-uglify": "^0.2.1",
26+
"gulp-jshint": "^1.5.1",
27+
"gulp-ext-replace": "0.0.5",
28+
"jshint-stylish": "^0.2.0"
29+
}
30+
}

0 commit comments

Comments
 (0)