Nocturnal Practitioners of Magic

    nextbone-firestore

    0.7.2 • 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

    Install

    npm i nextbone-firestore

    DownloadsWeekly Downloads

    8

    Version

    0.7.2

    License

    MIT

    Unpacked Size

    15.8 kB

    Total Files

    7

    Last publish

    Collaborators

    • blikblum