Skip to content

Commit

Permalink
Beta 1
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Jun 28, 2018
1 parent eaf0a05 commit 1050082
Show file tree
Hide file tree
Showing 18 changed files with 22,389 additions and 59 deletions.
10 changes: 7 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"presets": ["env"],
"plugins": ["babel-plugin-transform-object-rest-spread"]
}
"presets": [
["env", {
"modules": false
}]
],
"plugins": ["external-helpers", "babel-plugin-transform-object-rest-spread"]
}
53 changes: 44 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,46 @@

Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!

WIP
<WIP> This is a work in progress but is fully functional.

## First alpha works!
Includes:
## Beta version usable!

What it does:

- Setup logic to connect vuex module with firebase collection.
- Handy actions for the CRUD logic of your firebase collection.

Todo:

- Refinements
- Documentation
- Better documentation

### Table of contents

<!-- TOC -->

- [Motivation](#motivation)
- [Installation](#installation)
- [Setup](#setup)
- [Config options](#config-options)
- [Usage](#usage)
- [Automatic 2-way sync](#automatic-2-way-sync)
- [Editing](#editing)
- [Fetching](#fetching)
- [Custom state/getters/mutations/actions](#custom-stategettersmutationsactions)
- [Feedback](#feedback)

<!-- /TOC -->

## Motivation

Get all the firebase boilerplate installed for you in one vuex module.

## Installation

```bash
npm i --save vuex-easy-firestore
```

## Setup
The configuration as seen below is how you set up vuex-easy-firestore. This is to be repeated for each firestore collection you want to sync.

Expand All @@ -46,6 +55,10 @@ const config = {
// this is the state property where your docs will end up inside the module
firestorePath: 'users/{userId}/favourites',
// this is the firestore collection path to your documents. You can use `{userId}` which will be replaced with `Firebase.auth().uid`
firestoreRefType: 'collection', // or 'doc'
// depending if what you want to sync is a whole collection or a single doc
vuexUserPath: '',
// the path where your firebase user gets saved in vuex. Required to be able to have reactivity after login.
// SEE `src/module/defaultConfig` for more!
}
// do the magic 🧙🏻‍♂️
Expand All @@ -59,7 +72,7 @@ store: {

### Config options

About the config file, better documentation will follow. For now see `src/module/defaultConfig` for all possibilities.
About the config file, better documentation will follow. For now see [src/module/defaultConfig](https://github.com/mesqueeb/VuexEasyFirestore/blob/master/src/module/defaultConfig.js) for a list with all possibilities.

You can also add other state/getters/mutations/actions to the module that will be generated. See [Custom state/getters/mutations/actions](#custom-stategettersmutationsactions) for details.

Expand All @@ -75,7 +88,10 @@ dispatch('user/favourites/openDBChannel')
.catch(console.error)
```

To automatically edit your vuex store & have firebase always in sync you just need to use the actions that were set up for you.
Doesn't require any callback. The results will be saved in your vuex store at the path you have set:<br>
`moduleNameSpace` + `docsStateProp` which is in this example 'user/favourites/docs'.

To automatically edit your vuex store & have firebase always in sync you just need to use the actions that were set up for you:

### Editing

Expand All @@ -91,17 +107,25 @@ dispatch('user/favourites/delete', id)

With just the commands above you have complete in-sync vuex store & firestore!

You can also access the `set` action through `store.set(path, doc)`. So for the example above that would be: `store.set('user/favourites', doc)`.

For this shortcut usage, add the npm module 'vuex-easy-access' and check its [documentation](https://github.com/mesqueeb/VuexEasyAccess)!

### Fetching

Say that you have a default filter set on the documents you are syncing when you `openDBChannel` (see above). And at some points you want to get extra documents with other filters. (eg. archived posts) In this case you can use the fetch action to retrieve documents from the same firestore path your module is synced to:

```js
// Fetch docs
// @params {array} whereFilters an array of arrays with the filters you want. eg. `[['field', '==', false], ...]`
// @params {array} orderBy the params of the firebase collection().orderBy() eg. `['created_date']`
// @returns the docs
dispatch('user/favourites/fetch', {whereFilters = [], orderBy = []})
.then(console.log)
// you have to manually write the logic for what you want to do with the fetched documents.
.catch(console.error)
```

You only ever need to use the 5 actions above. You can look at `src/module/actions` for what's more under the hood.

### Custom state/getters/mutations/actions

You can add other stuff in your firestore module as you normally would by adding it in your config file.
Expand All @@ -114,3 +138,14 @@ const vuexEasyFirestoreConfig = {
actions: {}, // extra actions
}
```

## Feedback

Do you have questions, comments, suggestions or feedback? Or any feature that's missing that you'd love to have? Feel free to open an issue! ♥

Also check out the sister vuex-plugin [Vuex Easy Access](https://github.com/mesqueeb/VuexEasyAccess)!

--

Happy Vuexing!<br>
-Luca Ban
45 changes: 45 additions & 0 deletions build/rollup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// ------------------------------------------------------------------------------------------
// setup
// ------------------------------------------------------------------------------------------
import resolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import { uglify } from 'rollup-plugin-uglify'

const pkg = require('../package.json')
const external = Object.keys(pkg.dependencies || {})
const name = 'index'
const className = name.replace(/(^\w|-\w)/g, c => c.replace('-', '').toUpperCase())

function output (ext, format = 'umd') {
return {
name: className,
file: `dist/${name}.${ext}`,
format: format,
sourcemap: true,
exports: 'named',
}
}

// ------------------------------------------------------------------------------------------
// build
// ------------------------------------------------------------------------------------------
const umd = {
input: 'src/index.js',
external,
output: output('js'),
plugins: [
resolve(),
commonjs(),
babel({
exclude: 'node_modules/**' // only transpile our source code
})
]
}

const min = Object.assign({}, umd, {
output: output('min.js'),
plugins: [...umd.plugins, uglify()]
})

export default [umd, min]
Loading

0 comments on commit 1050082

Please sign in to comment.