Skip to content
This repository was archived by the owner on Aug 25, 2018. It is now read-only.

Commit 518c2d1

Browse files
committed
Merge pull request #120 from firebase/docs-update
Docs update
2 parents 56f3eb5 + 80cb2eb commit 518c2d1

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

README.md

+36-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Play around with our [realtime Todo App demo](https://backbonefire.firebaseapp.c
1313
## Basic Usage
1414
Using BackboneFire collections and models is very similar to the regular ones in Backbone. To setup with BackboneFire use `Backbone.Firebase` rather than just `Backbone`.
1515

16+
**Note: A `Backbone.Firebase.Model` should not be used with a `Backbone.Firebase.Collection`. Use a regular
17+
`Backbone.Model` with a `Backbone.Firebase.Collection`.**
18+
1619
```javascript
1720
// This is a plain old Backbone Model
1821
var Todo = Backbone.Model.extend({
@@ -129,11 +132,29 @@ You may also apply an `orderByChild` or some other
129132
[query](https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries) on a
130133
reference and pass it in:
131134

135+
### Queries
136+
132137
```javascript
133138
var TodoList = Backbone.Firebase.Collection.extend({
134139
url: new Firebase('https://<your-firebase>.firebaseio.com/todos').orderByChild('importance')
135140
});
136141
```
142+
143+
### url as a function
144+
145+
The `url` property can be set with a function. This function must return a Firebase ref or a url.
146+
147+
```javascript
148+
var TodoList = Backbone.Firebase.Collection.extend({
149+
url: function() {
150+
return new Firebase(...);
151+
}
152+
});
153+
```
154+
155+
156+
### initialize function
157+
137158
Any models added to the collection will be synchronized to the provided Firebase. Any other clients
138159
using the Backbone binding will also receive `add`, `remove` and `changed` events on the collection
139160
as appropriate.
@@ -199,12 +220,26 @@ may extend this object, and must provide a Firebase URL or a Firebase reference
199220
property.
200221

201222
```javascript
202-
var MyTodo = Backbone.Firebase.Model.extend({
223+
var Todo = Backbone.Firebase.Model.extend({
203224
url: "https://<your-firebase>.firebaseio.com/mytodo"
204225
});
205226
```
206227
You may apply query methods as with `Backbone.Firebase.Collection`.
207228

229+
### urlRoot
230+
The `urlRoot` property can be used to dynamically set the Firebase reference from the model's id.
231+
232+
```javascript
233+
var Todo = Backbone.Firebase.Model.extend({
234+
urlRoot: 'https://<your-firebase>.firebaseio.com/todos'
235+
});
236+
237+
// The url for this todo will be https://<your-firebase>.firebaseio.com/todos/1
238+
var todo = new Todo({
239+
id: 1
240+
});
241+
```
242+
208243
**BE AWARE!** You do not need to call any functions that will affect _remote_ data. If autoSync is enabled and you call
209244
`save()` or `fetch()` on the model, **the library will ignore it silently**.
210245

0 commit comments

Comments
 (0)