npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vuexfire

v3.2.5

Published

Firestore binding for Vuex

Downloads

7,844

Readme

Vuexfire Build Status npm package coverage

SSR ready Firebase binding for Vuex

Documentation

Installation

yarn add firebase vuexfire
# or
npm install firebase vuexfire

Usage

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

import { vuexfireMutations } 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
    ...vuexfireMutations,
  },
})

It works with modules as well, but you should not 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, bindFirestoreRef and unbindFirestoreRef:

import { firestoreAction } from 'vuexfire'

const setTodosRef = firestoreAction(
  ({ bindFirestoreRef, unbindFirestoreRef }, { ref }) => {
    // this will unbind any previously bound ref to 'todos'
    bindFirestoreRef('todos', ref)
    // you can unbind any ref easily
    unbindFirestoreRef('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', { ref: 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 atlassian/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 firestoreAction, it gets access to the local state and commit so it works with modules too :+1:

License

MIT