1.0.1 • Published 6 years ago

unistore-fire v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Unistore Fire

CircleCI NPM BundlePhobia

Peer Dependencies

This library relies on having firebase (web, admin or react-native) and unistore installed and initialized. If you haven't installed them previously :

  yarn add unistore firebase
  # or yarn add unistore firebase-admin
  # or yarn add unistore react-native-firebase
  # Or npm i unistore firebase

Install

  yarn add unistore-fire
  # Or npm i unistore-fire

Usage

Realtime Database

Map your Firebase database to unistore Stores.

This module exports 3 methods :

  • toBox
  • toObject
  • toArray

Usage

import { toBox, toObject, toArray } from "unistore-fire";

const ref = firebase.database().ref("path/to/data");
const box = toBox(ref);
box.getState(); //  { value: valueFromFirebase }
const map = toObject(ref);
map.getState(); // { value: { [key:keyFromFirebase]: valueFromFirebase } }
const array = toArray(ref);
array.getState(); // { value: Array<{ key:keyFromFirebase, value:valueFromFirebase }> }

API

Input

Any firebase ref, with or without sorting, limiting

Output

A unistore store that always has the latest value of the ref inside it.

toBox

The state has the following shape :

type State = {
  value: ValueFromFirebase | null;
};

toObject

The state has the following shape :

type State = {
  value: { [key: keyFromFirebase]: ValueFromFirebase } | null;
};

toArray

The state has the following shape :

type State = {
  value: Array<{ key: keyFromFirebase; value: ValueFromFirebase }>;
};

Check the tests for more examples !

1.0.1

6 years ago

1.0.0

6 years ago

0.1.3

6 years ago