|
1 | | -# `@posva/vuefire-core` |
| 1 | +# Vuefire Core |
2 | 2 |
|
3 | | -> TODO: description |
| 3 | +> Core logic used for vuefire and vuexfire |
4 | 4 |
|
5 | | -## Usage |
| 5 | +This library is intended for internal usage. You are free to use it to create your own plugins but keep in mind that the main target is a Vue plugin |
| 6 | + |
| 7 | +## Installation |
6 | 8 |
|
| 9 | +```sh |
| 10 | +npm i @posva/vuefire-core |
7 | 11 | ``` |
8 | | -const vuefireCore = require('@posva/vuefire-core'); |
9 | 12 |
|
10 | | -// TODO: DEMONSTRATE API |
| 13 | +## Usage |
| 14 | + |
| 15 | +```js |
| 16 | +import { bindCollection, bindDocument, walkSet } from '@posva/vuefire-core' |
| 17 | + |
| 18 | +// create an object of operations |
| 19 | +const ops = { |
| 20 | + set: (target, path, value) => walkSet(target, path, value), |
| 21 | + add: (array, index, data) => array.splice(index, 0, data), |
| 22 | + remove: (array, index) => array.splice(index, 1), |
| 23 | +} |
| 24 | +const vm = new Vue({ |
| 25 | + // options |
| 26 | +}) |
| 27 | + |
| 28 | +const resolve = data => { |
| 29 | + console.log('reference bound:', data) |
| 30 | +} |
| 31 | + |
| 32 | +const reject = err => { |
| 33 | + console.log('error binding reference:', err) |
| 34 | +} |
| 35 | + |
| 36 | +// unbind is a function that tears down all listeners |
| 37 | +const unbindItems = bindCollection( |
| 38 | + { |
| 39 | + // vm could be just an object |
| 40 | + vm, |
| 41 | + // key set on vm |
| 42 | + key: 'items', |
| 43 | + ops, |
| 44 | + collection: db.collection('items'), |
| 45 | + // this is to enable Promise based APIs |
| 46 | + // callback on success |
| 47 | + resolve, |
| 48 | + // callback on error |
| 49 | + reject, |
| 50 | + }, |
| 51 | + // default options |
| 52 | + { |
| 53 | + maxRefDepth: 2, |
| 54 | + } |
| 55 | +) |
| 56 | + |
| 57 | +const unbindItem = bindDocument( |
| 58 | + { |
| 59 | + // same options as bindCollection except for collection -> document |
| 60 | + document: db.collection('items').doc('0'), |
| 61 | + }, |
| 62 | + options |
| 63 | +) |
| 64 | + |
| 65 | +unbindItems() |
| 66 | +bindCollection({ |
| 67 | + // bind a different collection |
| 68 | + key: 'items', |
| 69 | +}) |
11 | 70 | ``` |
| 71 | + |
| 72 | +## License |
| 73 | + |
| 74 | +[MIT](http://opensource.org/licenses/MIT) |
0 commit comments