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

vdux-fire

v1.2.36

Published

vdux firebase container

Downloads

102

Readme

vdux-fire

vdux firebase container

Installation

with yarn:

yarn add vdux-fire

with npm:

npm install vdux-fire

Usage

vdux-fire is inspired by vdux-summon and react-refetch. You can use it to declaratively fetch data for your components and inject it into their props.

import fire from 'vdux-fre'

export default fire((props) => ({
  todos: `/users/${props.uid}/todos`
}))(component({
  render ({props}) {
    const {todos} = props
    if (todos.loading) return <span/>
    return (
      todos.value.map(todo => <li>{todo.name}</li>)
    )
  }
}))

Middleware

In order to make this work however, you must install the vdux-fire middleware in your root component's middleware stack and pass it your firebase config object:

import * as vduxFire from 'vdux-fire'
import config from './firebaseConfig'

component({
  middleware: [...middleware, vduxFire.middleware(config)]
})

Descriptor Object

The structure of the descriptor object is:

  • ref - String, specifies the firebase ref to watch. If only a string is specified it is shorthand for this.
  • type - String, set to 'once' to only read the database ref only one time when the component is loaded. Without this enabled vdux-fire watches the ref and updates components on changes.
  • queryParams - Array, See query parameter section below.
  • join - Object, See join section below.

Query Parameters

All of the firebase queries can be written in either string or object notation. For more information about firebase queries checkout their docs.

Object notation

To write a query in object notation:

{
  ref: '/some/firebase/ref',
  queryParams: [
    {method: 'orderByKey'},
    {method: 'limitToFirst', value: 5},
  ]
}

String notation

To write the equivalent query:

{
  ref: '/some/firebase/ref',
  queryParams: [
    'orderByKey',
    'limitToFirst=5'
  ]
}

Join

To help keep your firebase database flat, vdux-fire has a join that can either replace or add new IDs within your data with other data from Firebase.

  • ref - String, The root ref of the join data.
  • child - String, The key to replace in your returned data. If the childRef is not specified this is also used as the childRef.
  • childRef - String or Function, The child to read from the join ref. If childRef is a function it receives the parameters (val, ref):
    • val - The value returned by the initial query.
    • ref - The firebase ref specified in the ref key of join.
    • Returns: Array or Firebase Ref, A single firebase reference or array of firebase references.

Basic example:

// Example data
// usernames: {
//   'uniqueID': 'danleavitt0'
// }
// games: {
//   'gameID': {
//     ...gameData,
//     uid: 'uniqueID'
//   }
// }
fire((props) => ({
  todos: {
    ref: `/games/${props.gameId}`,
    join: {
      ref: '/usernames',
      child: 'uid'
    }
  }
}))

Example using childRef as a function to return an array of join values. These will be merged in to their corresponding parents at the key gameVal:

// Example data
// users: {
//   kvkXjds5fRh0jliRNfji3LTFMbI3: {
//     games: {
//        gameRef: {
//           ...gameMetaData
//           ref: 'gameRef'
//         }
//     }
//   }
// }
// games: {
//   'gameRef': {
//     ...gameData,
//   }
// }
fire((props) => {
  ref: '/users/kvkXjds5fRh0jliRNfji3LTFMbI3/games',
  queryParams: ['orderByChild=lastEdited, limitToLast=3'],
  join: {
    ref: '/games',
    child: 'gameVal',
    childRef: (val, ref) => mapValues(v => ref.child(v.ref), val)
  }
})

Descriptor String

If you are NOT using join the entire descriptor object can be written as a single string. The format of the string is:

'ref#query1&query2'

To add a once in string notation add [once] to the string:

'ref[once]'
// or
'ref#query[once]'

Example:

todos: `/users/${props.uid}/todos#orderByChild=timestamp&limitToFirst=5`

Data Object

The structure of the data object is:

  • loading - Whether or not the collection is currently loading
  • error - If an error has occurred, it is stored here.
  • value - The value returned from the request.
  • ref - The firebase ref that was requested.