IjzerenHein / firestorter

Use Google Firestore in React with zero effort, using MobX 🤘
http://firestorter.com
MIT License
378 stars 50 forks source link

Batch update feature #49

Closed imikemiller closed 5 years ago

imikemiller commented 5 years ago

Implemented a simple object architecture:

Batch - equivalent to the firestore().batch() object Operation - a single operation to be run in the batch, used to enforce object types.

Batch to accept an JSON array of objects describing operations which are parsed into an array of Operations and set to Batch._operations.

Operations definitions are shaped like this:

{
    source:docRef, 
    operation:'update',//or set or delete
    data:{ //not required for delete
      doc:'another_value',
    }
  }

I moved the private function resolveRef() into utiltiies and added another condition (its ugly, i think it can improve) to resolve a firestore ref from a Firestorter Document. This is to allow an operation to target a Firestorter Document, Firestore DocumentReference, string or observable function (although I am not sure the use case for this in context of a batch of updates).

I am not expecting this to go into master in current state just wanted to get your thoughts on the approach.

codecov-io commented 5 years ago

Codecov Report

Merging #49 into master will increase coverage by 0.72%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #49      +/-   ##
==========================================
+ Coverage   81.85%   82.58%   +0.72%     
==========================================
  Files           6        7       +1     
  Lines         496      511      +15     
  Branches      121      123       +2     
==========================================
+ Hits          406      422      +16     
+ Misses         78       77       -1     
  Partials       12       12
Impacted Files Coverage Δ
src/Document.js 80.34% <ø> (ø) :arrow_up:
test/init.js 100% <ø> (ø) :arrow_up:
src/Utils.js 84.61% <100%> (+5.66%) :arrow_up:
src/Batch.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 26327b1...112686b. Read the comment docs.

IjzerenHein commented 5 years ago

Hey Mike, the idea of updating data in a batch is a great idea. I've experimented and build some stuff for this in the past and would like to use those learnings rather than this code to move forward on that. Hopefully anywhere in the following next 2 weeks. Cheers dude

imikemiller commented 5 years ago

No worries. I had a use case on a little test project. Interested to see how you approach it!

On Fri, 16 Nov 2018, 4:32 pm Hein Rutjes, notifications@github.com wrote:

Hey Mike, the idea of updating data in a batch is a great idea. I've experimented and build some stuff for this in the past and would like to use those learnings rather than this code to move forward on that. Hopefully anywhere in the following next 2 weeks. Cheers dude

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/IjzerenHein/firestorter/pull/49#issuecomment-439430077, or mute the thread https://github.com/notifications/unsubscribe-auth/AXtHNl1Y2f__Wa51KnhFtd5vsI3a94ICks5uvtqOgaJpZM4YUvHv .