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

redfire

v0.3.1

Published

Microscopic Redux + Firebase bindings

Downloads

8

Readme

RedFire

Redfire is a tiny library for Redux and Firebase. Use it to sync properties of your Redux store to Firebase Refs.


🚧🚧🚧 This is a work in progress. 🚧🚧🚧


Instalation

Just add it to your project with:

$ npm i -S redfire

Getting Started

Just follow these simple steps:

  1. Import what you need to your project

    import { reducer, setDispatch, sync } from 'redfire';
  2. Combine redfire's reducer with yours and set the dispatch function

    const store = Redux.createStore(
      Redux.combineReducers({
        /* Other reducers here */
        myFirebaseData: reducer
      },
    );
       
    setDispatch(store.dispatch);
  3. Sync an id with a firebase Ref...

    sync('myId', FirebaseRef.child('myObject'));

Thats it. Your Redux State will look like this:

const state = {
  myFirebaseData: {
    myId: { /* Whatever you had in firebase */ } 
  }
};

Other Examples

There are other syncing functions to use

import { sync, get, syncChildren, unsync } from 'redfire';

This will keep id up to date with ref's value

sync('myId', FirebaseRef.child('myObject'));
// myId: { myFirstKey: 'myFirstValue', mySecondKey: 'mySecondValue' }

You can use subkeys in your id. Separate them with /

sync(`user/details/${uid}`, FirebaseRef.child('profiles').child(uid));
// users: { 
//   details: {
//     <uid>: /* ... */
//   }
// }

You can set asArray option to (surprise!) have data saved as array

sync('myArray', FirebaseRef.child('myObject'), {
  asArray: true
});
// myArray: [
//   { key: 'myFirstKey', value: 'myFirstValue' },
//   { key: 'mySecondKey', value: 'mySecondValue' },
// ]

Will bypass binding if this id is alredy in sync with a ref

sync('myObject', FirebaseRef.child('myObject'), {
  overwrite: false
});

Will set the value from ref but won't keep it in sync

get('myConfig', FirebaseRef.child('myConfig'));

Will keep in sync using child_added, child_removed and child_changed. Use for large objects.

syncChildren('myHugeObject', FirebaseRef.child('myHugeObject'));

You use query refs too

const searchRef = FirebaseRef
  .child("dinosaurs")
  .orderByChild("height")
  .startAt(3);

sync('myResults', searchRef);

FAQ

Is there a way to know when my data is loading?

Yes. If redfire[yourId] === undefined, it means we haven't received any results firebase. It is safe to show a preloader at this point because you cannot have undefined in firebase. If your data in firebase is empty, the value will be set to null.

Why are you using setDispatch?

To avoid having dependency on redux-thunk or having to send dispatch function on every call.

Then how do I change the state's data?

You don't. RedFire will take care of that. Make changes to update firebase directly witn ref.set(), ref.update(), ref.remove() and the changes will be reflected your store instantly, no delays. That's because of firebase optmistic nature. If the changes are not allowed on the server, the store will be reverted back to it's original state.