nextbone-firestore

Classes to use Firestore with Nextbone

Usage no npm install needed!

<script type="module">
  import nextboneFirestore from 'https://cdn.skypack.dev/nextbone-firestore';
</script>

README

nextbone-firestore

NPM version NPM downloads Build Status Coverage Status Dependency Status

nextbone-firestore is a Nextbone binding for Firestore

Features

    ✓ Fetch data on demand or listen for changes in real time
    ✓ Bind for documents or collections
    ✓ Tracking of reference / query params changes

Usage

Assumes Firebase Web SDK is properly installed and configured

import firebase from 'firebase/app'
import { FireCollection, FireModel, refSource } from 'nextbone-firestore'

const db = firebase.firestore()

class PatientsQuery extends FireCollection {
  // changes to to includeInactive will re evaluate ref / query
  @refSource
  includeInactive

  query(ref) {
    // optionally add a query method to configure the query params
    const { includeInactive } = this
    let query = ref
    if (!includeInactive) {
      query = query.where('active', '==', true)
    }
    return query
  }

  ref() {
    // return the collection ref
    return db.collection(`patients`)
  }
}

const patients = new PatientsQuery()
// get all patients once
await patients.fetch()

// observe changes in real time
patients.observe()
// awaits for ready method to ensure data is loaded from server
await patients.ready()

// reset the query
patients.includeInactive = true
// awaits for the query with new params return
await patients.ready()

Get in Touch

License

Copyright © 2021 Luiz Américo. This source code is licensed under the MIT license found in the LICENSE.txt file. The documentation to the project is licensed under the CC BY-SA 4.0 license.


Made with ♥ by Luiz Américo and contributors