All Projects → posva → Vuexfire

posva / Vuexfire

Licence: mit
Check

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vuexfire

Vue Memo
Using Vue.js for memo web App. webpack, vuex, vue-router, Firebase.
Stars: ✭ 88 (-84.67%)
Mutual labels:  firebase, vuex
Buefy Shop
A sample shop built with Nuxt, Stripe, Firebase and Serverless Functions
Stars: ✭ 207 (-63.94%)
Mutual labels:  firebase, vuex
Bento Starter
🍱 Full-Stack solution to quickly build PWA applications with Vue.js and Firebase
Stars: ✭ 1,519 (+164.63%)
Mutual labels:  firebase, vuex
Vue Trello
Trello clone with Vue.js for educational purposes
Stars: ✭ 185 (-67.77%)
Mutual labels:  firebase, vuex
Vuetify Chat
A chat built with Vue + Vuex + Vuetify + Firebase
Stars: ✭ 338 (-41.11%)
Mutual labels:  firebase, vuex
Vue Pomo
A progressive web app for the Pomodoro Technique, built with Vue 2.0, Vuex and Firebase.
Stars: ✭ 51 (-91.11%)
Mutual labels:  firebase, vuex
Todo Vue
Code for YouTube series on building a Todo App in Vue.js
Stars: ✭ 199 (-65.33%)
Mutual labels:  firebase, vuex
Vue Firebase Starter
boilerplate of vue/vuex/vue(x)-router, with sass/prerendering, muse-ui, and firebase/firebaseui
Stars: ✭ 43 (-92.51%)
Mutual labels:  firebase, vuex
Vuefire
🔥 Firebase bindings for Vue.js & Vuex
Stars: ✭ 3,234 (+463.41%)
Mutual labels:  firebase, vuex
Vue Firebase Auth Vuex
Vue Firebase🔥 Authentication with Vuex
Stars: ✭ 248 (-56.79%)
Mutual labels:  firebase, vuex
Vuex Easy Firestore
Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!
Stars: ✭ 224 (-60.98%)
Mutual labels:  firebase, vuex
Nuxt Firebase Sns Example
Nuxt v2 & Firebase(Hosting / Functions SSR / Firestore), Google Auth SNS Example.
Stars: ✭ 485 (-15.51%)
Mutual labels:  firebase, vuex
Beauty
👙 VUE + VUEX + FIREBASE + BULMA … 实现的 SPA SSR 同构项目 - Tinder美女/豆瓣美女合集
Stars: ✭ 433 (-24.56%)
Mutual labels:  firebase, vuex
Meal Prep
Source code for a 4-part series I wrote about Vue, Vue Router, Vuex and Vuetify
Stars: ✭ 496 (-13.59%)
Mutual labels:  firebase, vuex
Vue Quasar Admin
Vue 2.0 admin-dashboard based on Quasar-Framework
Stars: ✭ 516 (-10.1%)
Mutual labels:  vuex
Firebase Action
GitHub Action for interacting with Firebase
Stars: ✭ 554 (-3.48%)
Mutual labels:  firebase
Tamiat
⛵️ Vuejs and Firebase based CMS
Stars: ✭ 510 (-11.15%)
Mutual labels:  firebase
Flank
🚤 Massively parallel Android and iOS test runner for Firebase Test Lab
Stars: ✭ 509 (-11.32%)
Mutual labels:  firebase
Firebaseandroidchat
Chat with features : Login with Google | Send Photo Camera | Send Photo Gallery | Send Location
Stars: ✭ 571 (-0.52%)
Mutual labels:  firebase
Vue Mintshop
🍖 🍉 使用 ES6 + Mock.js + vue2.0 全家桶开发的前后端分离的外卖App。开发文档、流程完整详尽,非常适合作为个人练手项目。
Stars: ✭ 552 (-3.83%)
Mutual labels:  vuex

This package has been moved to vuejs/vuefire repository.


VuexFire Build Status npm package coverage size

SSR ready Firebase binding for Vuex

Supports only Vue 2, Vuex 2 and Firebase JavaScript SDK 2/3/4/5. If you need an older version check the v1 branch: npm i -D [email protected]

Installation

  1. Using a CDN:
<script src="https://unpkg.com/[email protected]"></script>
  1. In module environments, e.g CommonJS:
npm install vue firebase [email protected] --save

Usage

Add the mutations to your root Store and make sure to define the property you want to bind in the state first:

import { firebaseMutations } from 'vuexfire'
const store = new Vuex.Store({
  state: {
    todos: [], // Will be bound as an array
    user: null // Will be bound as an object
  },
  mutations: {
    // your mutations
    ...firebaseMutations
  }
})

It works with modules as well, but you don't need to add the mutations there:

const store = new Vuex.Store({
  modules: {
    todos: {
      state: {
        todos: [], // Will be bound as an array
        user: null // Will be bound as an object
      },
    }
  }
})

In order to use VuexFire, you have to enhance actions. This action enhancer takes the actual action and enhances it with two additional parameters in the context, bindFirebaseRef and unbindFirebaseRef:

import { firebaseAction } from 'vuexfire'

const setTodosRef = firebaseAction(({ bindFirebaseRef, unbindFirebaseRef }, { ref }) => {
  // this will unbind any previously bound ref to 'todos'
  bindFirebaseRef('todos', ref)
  // you can unbind any ref easily
  unbindFirebaseRef('user')
})

Access it as a usual piece of the state:

const Component = {
  template: '<div>{{ todos }}</div>',
  computed: Vuex.mapState(['todos']),
  created () {
    this.$store.dispatch('setTodosRef', db.collection('todos'))
  }
}

Browser support

VuexFire requires basic WeakMap support, which means that if you need to support any of these browsers:

  • IE < 11
  • Safari < 7.1
  • Android < 5.0

You'll have to include a polyfill. You can use Benvie/WeakMap.

You can find more information about WeakMap support here.

How does it work?

VuexFire uses multiple global mutations prefixed by vuexfire/ to call the actual mutations to modify objects and arrays. It listens for updates to your firebase database and commits mutations to sync your state. Thanks to the action enhancer firebaseAction, it gets access to the local state and commit so it works with modules too 👍

Examples

You can check out a complete example in the /examples directory.

API

firebaseMutations

This object contains VuexFire internal mutations. They are all prefixed by vuexfire/. This object must be added in the root Store mutations object.

bindFirebaseRef(key, ref)

Only available inside of an enhanced action

Binds a firebase reference to a property in the state. If there was already another reference bound to the same property, it unbinds it first.

bindFirebaseRef('todos', ref)

Returns a promise which will resolve when the data is ready, or throw an error if something goes wrong:

bindFirebaseRef('todos', ref).then(() => {
  commit('setTodosLoaded', true)
}).catch((err) => {
  console.log(err)
})

unbindFirebaseRef(key)

Only available inside of an enhanced action

Unbinds a bound firebase reference to a given property in the state.

unbindFirebaseRef('todos')

License

MIT

Support on Beerpay

Hey dude! Help me out for a couple of 🍻!

Beerpay Beerpay

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].