Skip to content

Commit 2f977e0

Browse files
committed
docs(core): complete README
1 parent cbf754f commit 2f977e0

File tree

1 file changed

+68
-5
lines changed

1 file changed

+68
-5
lines changed
Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,74 @@
1-
# `@posva/vuefire-core`
1+
# Vuefire Core
22

3-
> TODO: description
3+
> Core logic used for vuefire and vuexfire
44
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
68

9+
```sh
10+
npm i @posva/vuefire-core
711
```
8-
const vuefireCore = require('@posva/vuefire-core');
912

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+
})
1170
```
71+
72+
## License
73+
74+
[MIT](http://opensource.org/licenses/MIT)

0 commit comments

Comments
 (0)