|
1 | 1 | # ReactFire |
2 | 2 |
|
3 | | -ReactFireMixin is an officially supported [ReactJS](http://facebook.github.io/react/) mixin |
4 | | -for [Firebase](http://www.firebase.com/). Firebase provides your React app with a |
5 | | -persistent, realtime backend to effortlessly keep all of your clients in sync! |
| 3 | +[](https://travis-ci.org/firebase/reactfire) |
| 4 | +[](http://badge.fury.io/gh/firebase%2Freactfire) |
6 | 5 |
|
7 | | -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! |
| 6 | +[ReactJS](http://facebook.github.io/react/) is a framework for building large, complex user interfaces. [Firebase](http://www.firebase.com/) complements it perfectly by providing an easy-to-use, realtime data source for populating the `state` of React components. With ReactFire, it only takes a few lines of JavaScript to integrate Firebase into React apps via the `ReactFireMixin`. |
8 | 7 |
|
9 | | -## Usage |
| 8 | +[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! |
10 | 9 |
|
11 | | -The ReactFireMixin can be added to your project in three ways: |
| 10 | +## Downloading ReactFire |
12 | 11 |
|
13 | | -* Manually copy ReactFireMixin.js from GitHub to you local directory. |
14 | | -* Use bower: `bower install ReactFire` |
15 | | -* Use npm: `npm install reactfire` |
| 12 | +In order to use the `ReactFireMixin` in your project, you need to include the following files in your HTML: |
16 | 13 |
|
17 | | -To use the ReactFireMixin in a React component, add it to the component's mixins property: |
| 14 | +```html |
| 15 | +<!-- React JS --> |
| 16 | +<script src="http://fb.me/react-0.10.0.min.js"></script> |
| 17 | +<script src="http://fb.me/JSXTransformer-0.10.0.js"></script> |
18 | 18 |
|
19 | | - var ExampleComponent = React.createClass({ |
20 | | - mixins: [ReactFireMixin], |
21 | | - ... |
22 | | - }); |
| 19 | +<!-- Firebase --> |
| 20 | +<script src="https://cdn.firebase.com/js/client/1.0.17/firebase.js"></script> |
23 | 21 |
|
24 | | -## API Reference |
| 22 | +<!-- ReactFire --> |
| 23 | +<script src="https://cdn.firebase.com/libs/reactfire/0.1.6/reactfire.min.js"></script> |
| 24 | +``` |
25 | 25 |
|
26 | | -###bindAsArray(firebaseRef, bindVar) |
| 26 | +Use the URL above to download both the minified and non-minifed versions of ReactFire from the Firebase CDN. You can also download them from the `/dist/` directory of this GitHub repository. [Firebase](https://www.firebase.com/docs/web-quickstart.html) and [React](http://facebook.github.io/react/downloads.html) can be downloaded directly from their respective websites. |
27 | 27 |
|
28 | | -Creates a binding between Firebase and the inputted bind variable as an array. The Firebase |
29 | | -reference will be stored in this.firebaseRefs[bindVar]. |
| 28 | +You can also install ReactFire via npm or Bower and the dependencies will be downloaded automatically: |
30 | 29 |
|
31 | | - this.bindAsArray(new Firebase("https://<YOUR_FIREBASE>/"), "items"); |
| 30 | +```bash |
| 31 | +$ npm install reactfire --save |
| 32 | +``` |
32 | 33 |
|
33 | | -###bindAsObject(firebaseRef, bindVar) |
| 34 | +```bash |
| 35 | +$ bower install reactfire --save |
| 36 | +``` |
34 | 37 |
|
35 | | -Creates a binding between Firebase and the inputted bind variable as an object. The Firebase |
36 | | -reference will be stored in this.firebaseRefs[bindVar]. |
| 38 | +## Getting Started with Firebase |
37 | 39 |
|
38 | | - this.bindAsObject(new Firebase("https://<YOUR_FIREBASE>/"), "items"); |
| 40 | +ReactFire requires Firebase in order to store data. You can [sign up here](https://www.firebase.com/signup/) for a free account. |
39 | 41 |
|
40 | | -###unbind(bindVar) |
| 42 | +## Usage |
41 | 43 |
|
42 | | -Removes the binding between Firebase and the inputted bind variable. This removes the stored |
43 | | -Firebase reference in this.firebaseRefs[bindVar] and cleans up any event handlers associated |
44 | | -with that Firebase reference. |
| 44 | +To use the `ReactFireMixin` in a React component, add it to the component's mixins property: |
45 | 45 |
|
46 | | - this.unbind("items"); |
| 46 | +```javascript |
| 47 | +var ExampleComponent = React.createClass({ |
| 48 | + mixins: [ReactFireMixin], |
| 49 | + ... |
| 50 | +}); |
| 51 | +``` |
47 | 52 |
|
48 | | -## Contributing |
| 53 | +The following APIs will then be available from the `this` object inside of `ExampleComponent`. |
49 | 54 |
|
50 | | -Interested in manually debugging from source or submitting a pull request? Follow the steps |
51 | | -below. |
| 55 | +## API Reference |
52 | 56 |
|
53 | | -### Install Dependencies |
| 57 | +### bindAsArray(firebaseRef, bindVar) |
54 | 58 |
|
55 | | -```bash |
56 | | -$ git clone https://github.com/firebase/ReactFire.git # clone this repository |
57 | | -$ npm install # install local NPM build / test dependencies |
| 59 | +Creates a binding between Firebase and the inputted bind variable as an array. The Firebase reference will be stored in `this.firebaseRefs[bindVar]`. |
| 60 | + |
| 61 | +```javascript |
| 62 | +this.bindAsArray(new Firebase("https://<YOUR_FIREBASE>/"), "items"); |
| 63 | +``` |
| 64 | + |
| 65 | +### bindAsObject(firebaseRef, bindVar) |
| 66 | + |
| 67 | +Creates a binding between Firebase and the inputted bind variable as an object. The Firebase reference will be stored in `this.firebaseRefs[bindVar]`. |
| 68 | + |
| 69 | +```javascript |
| 70 | +this.bindAsObject(new Firebase("https://<YOUR_FIREBASE>/"), "items"); |
58 | 71 | ``` |
59 | 72 |
|
60 | | -### Compile |
| 73 | +### unbind(bindVar) |
| 74 | + |
| 75 | +Removes the binding between Firebase and the inputted bind variable. This removes the stored Firebase reference in `this.firebaseRefs[bindVar]` and cleans up any event handlers associated with that Firebase reference. |
| 76 | + |
| 77 | +```javascript |
| 78 | +this.unbind("items"); |
| 79 | +``` |
| 80 | + |
| 81 | +## Contributing |
| 82 | + |
| 83 | +If you'd like to contribute to ReactFire, you'll need to run the following commands to get your environment set up: |
61 | 84 |
|
62 | 85 | ```bash |
63 | | -$ gulp |
| 86 | +$ git clone https://github.com/firebase/reactfire.git |
| 87 | +$ npm install -g gulp # globally intall gulp task runnger |
| 88 | +$ npm install # install local npm build / test dependencies |
| 89 | +$ bower install # install local JavaScript dependencies |
| 90 | +$ gulp watch # watch for source file changes |
64 | 91 | ``` |
65 | 92 |
|
66 | | -## License |
| 93 | +`gulp watch` will watch for changes in the `/src/` directory and lint, concatenate, and minify the source files when a change occurs. The output files - `reactfire.js` and `reactfire.min.js` - are written to the `/dist/` directory. |
67 | 94 |
|
68 | | -[Firebase MIT License](http://firebase.mit-license.org) |
| 95 | +You can run the test suite by navigating to `file:///path/to/tests/TestRunner.html` or run the tests via the command line using `gulp test`. |
0 commit comments