|
6 | 6 | [](https://github.com/Rekord/rekord/blob/master/LICENSE) |
7 | 7 | []() |
8 | 8 |
|
9 | | -A rekord binding to firebase - implementing Rekord.rest & Rekord.live. |
| 9 | +A rekord binding to firebase - implementing Rekord.rest (Rekord.live & Rekord.store implicitly) |
10 | 10 |
|
11 | 11 | The easiest way to install is by using bower via `bower install rekord-firebase`. |
12 | 12 |
|
13 | | -- `rekord-firebase.js` is `3.6KB` (`0.8KB` gzipped) |
14 | | -- `rekord-firebase.min.js` is `1.3KB` (`0.5KB` gzipped) |
| 13 | +- `rekord-firebase.js` is `5.6KB` (`1.1KB` gzipped) |
| 14 | +- `rekord-firebase.min.js` is `1.9KB` (`0.7KB` gzipped) |
| 15 | + |
| 16 | +### Example Usage |
| 17 | + |
| 18 | +```javascript |
| 19 | +var fire = firebase.database(); |
| 20 | + |
| 21 | +// Executed after options are applied but before the store, rest, & live |
| 22 | +// implementations are added. It's good to prepare your database in this |
| 23 | +// function so if you switch backends there's only one place you need to do so. |
| 24 | +// You can also pass a prepare function as a Rekord option. |
| 25 | +Rekord.Database.Defaults.prepare = function(db, options) { |
| 26 | + db.api = options.api || fire.ref( options.name ); |
| 27 | +}; |
| 28 | + |
| 29 | +// Default behavior |
| 30 | +var TaskList = Rekord({ |
| 31 | + name: 'task_list', |
| 32 | + field: ['name', 'done'] |
| 33 | +}); |
| 34 | + |
| 35 | +// Override (or default behavior if prepare method isn't used like above) |
| 36 | +var Task = Rekord({ |
| 37 | + name: 'task', |
| 38 | + api: fire.ref('task'), |
| 39 | + field: ['name', 'done', 'task_list_id'] |
| 40 | +}); |
| 41 | + |
| 42 | +// Or dynamically return a firebase reference |
| 43 | +var Item = Rekord({ |
| 44 | + name: 'item', |
| 45 | + fields: ['name', 'list_id'], |
| 46 | + // for all, create, update, remove & query (when getQueryFirebase is not given) |
| 47 | + getFirebase: function(model, database) { |
| 48 | + // model is undefined for all() and query() functions |
| 49 | + return fire.ref( 'list/' + model.list_id + '/items' ); |
| 50 | + }, |
| 51 | + // for query |
| 52 | + getQueryFirebase: function(url, data) { |
| 53 | + return fire.ref( url ); |
| 54 | + } |
| 55 | + // which reference to listen to for child events |
| 56 | + getLiveFirebase: function(database) { |
| 57 | + return fire.ref( database.name ); |
| 58 | + } |
| 59 | +}); |
| 60 | + |
| 61 | +``` |
0 commit comments