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

firedb

v0.0.3

Published

Vuex plugin to integrate with Firebase's Firestore and create two way bindings.

Downloads

20

Readme

firedb

firedb takes minilistic approac to integrating firestore to your vuex store with live updates from firestore and pushing changes you make locally to firestore automatically.

Prerequisites

  • firedb depends on firebase. You should have already installed firebase in your repository.

Installation

Step 1: Download npm package

npm install firedb 

Step 2: Import and register Vuex plugin

Import firedb in the file you are creating your store and pass firedb as one of the plugins.

import firedb from "firedb";

const store = new Vuex.Store({
  state,
  mutations,
  plugins: [firedb] // register firedb as plugin
})

Thats it you are good to go!

Registering and Unregistering firestore paths

firedb exposes registerPath and unregisterPath actions. As the name suggests, use registerPath to register a firestore path to a collection or document to start two way sync. Once you no longer need it simply call unregisterPath.

ATTN: You need to make sure you have appropriate permissions to the path you are registering.

Register

$store.dispatch("firedb/registerPath", "collection/doc");

// Now the document will be available in components like below

var doc = $store.state.firedb.collection.doc;

Unregister

$store.dispatch("firedb/unregisterPath", "collection/doc");

// $store.state.firedb.collection.doc is no longer avilable.

Things to note:

  • You can register both collections or documents paths.
  • firedb follows the same data structure as your firestore. E.g. a path col1/doc1/col2 will be avilable in store as state.firedb.col1.doc1.col2.
  • You cannot register/unregister same path multiple times. firedb will ignore the duplicate reqeusts.
  • Unregister will also clean the state. Meaning if you had a path collection/doc/ registered. After unregistering $store.state.firedb.collection will not exist.

Saving changes / set

firedb exposes set action to update documents. It is recommended that any updates firestore documents are done through this action. It is similar to Vue.set method.

// You must have registered "path/to/collection" OR "path/to/collection/document" for this to work.
$store.dispatch("firedb/set", {path: "path/to/collection/document", value: {/*data*/}});

// If document doesnt exist in the collection, it will be created.
let doc = $store.state.firedb.path.to.collection.document;

// To remove a document, just pass value as null or undefined
$store.dispatch("firedb/set", {path: "path/to/collection/document", value: null});
$store.dispatch("firedb/set", {path: "path/to/collection/document"});

// Both of the above statement will remove document from collection

Things to note:

  • All updates will be sent to the server. If user do not have write access to the path referenced, this action will fail.
  • If document doesnt exist on referenced collection, it will be created.
  • You must have registered the path for this to work. For e.g. set to a/b refers to document b in collection a. You must have either registered path a or a\b before calling an update on b.
  • Any call to set on a collection path (odd length) will be log console error and ignored.