nextbone-firestore
TypeScript icon, indicating that this package has built-in type declarations

0.8.0 • Public • Published

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

Use the v9 firestore API

import firebase from 'firebase/app'
import { FireCollection, FireModel } from 'nextbone-firestore'
import { getFirestore, collection, query, where } from 'firebase/firestore'

const db = getFirestore()

class PatientsQuery extends FireCollection {
  query(ref, params) {
    const { includeInactive } = params
    let result = ref
    // optionally add a query condition
    if (!includeInactive) {
      result = query(ref, where('active', '==', true))
    }
    return result
  }

  ref(params) {
    // return the collection ref
    return collection(db, `clinics/${params.clinicId}/patients`)
  }
}

const patients = new PatientsQuery()
// set some params
patients.params.clinicId = 'clinic-1'

// 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.params.includeInactive = true
// or
patients.params = { ...patients.params, 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 by Luiz Américo

Package Sidebar

Install

npm i nextbone-firestore

Weekly Downloads

1

Version

0.8.0

License

MIT

Unpacked Size

22.7 kB

Total Files

14

Last publish

Collaborators

  • blikblum