Repository: vigetlabs/microcosm (js)

Issue:
Ability to set history length externally
For the dev tools, I want to allow a user to not have to worry about adding `maxHistory: Infinity` when in development mode. It would be great if there was a way to adjust the settings of the history object externally, like:

```
repo.history.setLimit(Infinity)
```

Pull request description:
Add a setLimit method to the history object.
Resolves #353. Also wrote some super basic tests just to be safe.

**What kind of change does this PR introduce?**
- Refactor

**Does this PR introduce a breaking change?**
- No

**Does this PR fulfill these requirements:**
<!-- (Update "[ ]" to "[x]" to check a box) -->

- [x] All tests are passing
- [x] `yarn pretty` has been run
- [x] Commits reference open issues


Patch:
diff --git a/src/history.js b/src/history.js
index 82c3463b..e2d813f7 100644
--- a/src/history.js
+++ b/src/history.js
@@ -40,7 +40,7 @@ class History extends Emitter {
     let options = merge(DEFAULTS, config)
 
     this.size = 0
-    this.limit = Math.max(0, options.maxHistory)
+    this.setLimit(options.maxHistory)
 
     this.updater = options.updater(options)
 
@@ -337,6 +337,13 @@ class History extends Emitter {
     this.size = size
   }
 
+  /**
+   * Set the limit of the history object.
+   */
+  setLimit(limit: number) {
+    this.limit = Math.max(0, limit)
+  }
+
   /**
    * Determine if provided action is within active history branch
    */


Test patch:
diff --git a/test/unit/history/setLimit.test.js b/test/unit/history/setLimit.test.js
new file mode 100644
index 00000000..125a7614
--- /dev/null
+++ b/test/unit/history/setLimit.test.js
@@ -0,0 +1,24 @@
+import History from '../../../src/history'
+
+describe('History::setLimit', function() {
+  it('sets the correct size given Infinity', function() {
+    const history = new History()
+    history.setLimit(Infinity)
+
+    expect(history.limit).toEqual(Infinity)
+  })
+
+  it('sets the correct size given an integer', function() {
+    const history = new History()
+    history.setLimit(10)
+
+    expect(history.limit).toEqual(10)
+  })
+
+  it('sets the limit to 0 given a negative integer', function() {
+    const history = new History()
+    history.setLimit(-10)
+
+    expect(history.limit).toEqual(0)
+  })
+})