1.3.1 • Published 3 years ago
@joaomelo/stores v1.3.1
stores utils for firebase firestore with optional vue helpers
tr;tl
at the application start desired collections are declared. the library will hold a global store with data and mutation for each one.
this stores are scoped to current user while querying and setting.
the library provide helpers to return reactive computations over one or more of those stores.
getting started
to use it as a vue plugin go with
// index.js
import { stores } from '@joaomelo/stores/vue';
const connection = { ... };
const collections = ['todos', 'notes']
...
app.use(stores, { connection, collections });
// some-component.vue
import { useStores } from '@joaomelo/stores/vue';
const { todos } = useStores(); // <- todos is reactive
...
<div v-for="item in todos.items">
{{ item.text }}
</div>
if dealing with vanilla js or other frameworks
import { createStores } from '@joaomelo/stores/vue';
const connection = { ... };
const collections = ['todos', 'notes']
const stores = createStores({ connection, collections });
const { todos } = stores;
todos.subscribe((items) => ...)
for each collection you pass it will create a store with:
- the same collections name
items
property with an array os the collection recordssubscribe
method to receive updates- methods for mutations:
set
,update
anddel