immer-to-firestore
Converts an immer patch to a firestore update.
Last updated 3 months ago by tdawes .
MIT · Original npm · Tarball · package.json
$ cnpm install immer-to-firestore 
SYNC missed versions from official npm registry.

Immer to Firestore

Converts an immer patch to a firestore update.

Usage

import immerToFirestore from "immer-to-firestore";
import * as immer from "immer";

// Enable patches in immer.
immer.enablePatches();

// Apply your mutations and collect the patches from immer
let patches;
immer.produce(original, draft => /* ... */, ps => { patches = ps; });

// Transform your patches to a Firestore update.
const firestoreUpdate = immerToFirestore(original, patches);

// Send the update to Firestore
if (firestoreUpdate.type === "set") {
  ref.set(firestoreUpdarte.value);
} else if (firestoreUpdate.type === "delete") {
  ref.delete();
|} else if (firestoreUpdate.type === "update") {
  ref.update(firestoreUpdate.update);
}

Warning

Due to limitations with Firestore's handling of arrays, it is not yet possible to mutate an object inside an array. You can add and remove elements, however.

Current Tags

  • 1.0.2                                ...           latest (3 months ago)

3 Versions

  • 1.0.2                                ...           3 months ago
  • 1.0.1                                ...           3 months ago
  • 1.0.0                                ...           3 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |