vigetlabs / microcosm

Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.
http://code.viget.com/microcosm/
MIT License
487 stars 29 forks source link

[microcosm] Add remove data helper. Setting undefined removes props #505

Closed nhunzaker closed 6 years ago

nhunzaker commented 6 years ago

This commit updates the way set works such that it removes a property if it is undefined. It also adds an remove function, which is an alias for set(object, prop, undefined).

import { set, remove } from 'microcosm'

val records = { 1: { name: 'Billy' }, 2: { name: 'Sal' } }

// These are the same
set(records, 1, undefined) // { 2: { name: 'Sal' } }
remove(records, 1)         // { 2: { name: 'Sal' } }

I also took this as an opportunity to rework flow types and refactor some of the data operation code to avoid null checks.

codecov-io commented 6 years ago

Codecov Report

Merging #505 into master will increase coverage by <.01%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #505      +/-   ##
==========================================
+ Coverage   99.69%   99.69%   +<.01%     
==========================================
  Files          27       27              
  Lines         658      659       +1     
  Branches      129      130       +1     
==========================================
+ Hits          656      657       +1     
  Misses          2        2
Impacted Files Coverage Δ
packages/microcosm/src/data.js 100% <100%> (ø) :arrow_up:

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 34f2a31...25252d2. Read the comment docs.