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

Add back max history option #520

Closed nhunzaker closed 6 years ago

nhunzaker commented 6 years ago

What

This commit adds back the max history option to Microcosm, a feature of 12.x that controls how many actions Microcosm's history should hold on to.

This is based upon depth, not overall action count. This is so that you can checkout prior trees. For example:

          action-0__________
          /        \         \
      action-1  action-2  action-3__________
                         /        \         \
                     action-4  action-5  action-6__________
                                        /        \         \
                                    action-7  action-8  action-9___________
                                                       /        \          \
                                                   action-10 action-11  action-12___________
                                                                       /         \          \
                                                                   action-13  action-14  action-15
                                                                                        /         \
                                                                                    action-16  action-17

This is with a size of 10, though in this case, the overall depth hasn't hit higher than 6. With a size of 3, this would look like:

        action-0__________
          /        \         \
      action-1  action-2  action-3
                         /        \
                     action-4  action-5

This is zero by default in order to prevent memory leaks. However some apps (like email editors we have built in the past) may desire to hold on to a set number of actions for undo/redo and reporting features.

Why

I want to respect the 12.x API and keep this feature, which is extremely useful when you need it.

codecov-io commented 6 years ago

Codecov Report

Merging #520 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #520   +/-   ##
=======================================
  Coverage   93.74%   93.74%           
=======================================
  Files          32       32           
  Lines         799      799           
  Branches      162      162           
=======================================
  Hits          749      749           
  Misses         43       43           
  Partials        7        7
Impacted Files Coverage Δ
packages/microcosm/src/microcosm.js 88.57% <ø> (-0.32%) :arrow_down:
packages/microcosm/src/history.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 609c6da...0d5f7fe. Read the comment docs.