Skip to content

Commit

Permalink
Bugfix: internal _clone() converted arrays to objects
Browse files Browse the repository at this point in the history
  • Loading branch information
guigrpa committed Feb 28, 2016
1 parent 9820450 commit 214c00e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Add `getIn()`, `updateIn()`, `mergeIn()`
* `setIn()` now creates nested objects for unknown paths
* Bugfix: internal `_clone()` converted arrays to objects

## 0.4.0 (Feb. 25, 2016)

Expand Down
3 changes: 3 additions & 0 deletions dist/timm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/timm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/timm.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ INVALID_ARGS = 'INVALID_ARGS'
_throw = (msg) -> throw new Error msg

_clone = (obj) ->
if Array.isArray obj then return [].concat obj
keys = Object.keys obj
out = {}
out[key] = obj[key] for key in keys
Expand Down
10 changes: 9 additions & 1 deletion test/tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe 'Object operations', ->
obj = null
arr = null
beforeEach ->
obj = {a: 1, b: 2, d: {d1: 3, d2: 4, b: {b: {b: 4}}}, e: {e1: 'foo', e2: 'bar'}}
obj = {a: 1, b: 2, d: {d1: 3, d2: 4, b: {b: {b: 4}}}, e: {e1: 'foo', e2: 'bar'}, arr: ['c', 'd']}
arr = [{a: 1}, {a: 2}, {a: 3, d: {d1: 4, d2: 5, d3: null}}]

describe 'getIn', ->
Expand Down Expand Up @@ -150,6 +150,14 @@ describe 'Object operations', ->
expect(obj2.d.b).to.equal obj.d.b
expect(obj2.e).to.equal obj.e

it 'should not convert arrays to objects', ->
obj2 = timm.setIn obj, ['arr', 2], 'e'
expect(obj.arr).to.have.length 2
expect(obj2).not.to.equal obj
expect(Array.isArray obj2.arr).to.be.true
expect(obj2.arr).to.have.length 3
expect(obj2.arr[2]).to.equal 'e'

describe 'deeper', ->
it 'with change', ->
obj2 = timm.setIn obj, ['d', 'b', 'b', 'b'], 3
Expand Down

0 comments on commit 214c00e

Please sign in to comment.