Skip to content

Commit d64173d

Browse files
committed
fix - Make sure bind does not mutate columns
1 parent 546b3dd commit d64173d

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
8.9.3 / 2017-02-09
2+
==================
3+
4+
* Fix - Make sure `bind` does not mutate columns.
5+
16
8.9.2 / 2017-02-09
27
==================
38

__tests__/bind-test.js

+36
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { cloneDeep } from 'lodash';
12
import { bind } from '../src';
23

34
describe('reactabular-column-extensions.bind', function () {
@@ -162,6 +163,41 @@ describe('reactabular-column-extensions.bind', function () {
162163
expect(result).toEqual(expected);
163164
});
164165

166+
it('does not mutate columns', function () {
167+
const extensions = [
168+
{
169+
match({ cell }) {
170+
return cell.ok;
171+
},
172+
evaluate({ cell: { ok } }) {
173+
return {
174+
cell: {
175+
ok: ok + ok,
176+
formatters: [
177+
'b'
178+
]
179+
}
180+
};
181+
}
182+
}
183+
];
184+
const columns = [
185+
{
186+
cell: {
187+
ok: 'foo',
188+
formatters: [
189+
'a'
190+
]
191+
}
192+
}
193+
];
194+
const expected = cloneDeep(columns);
195+
196+
bind(extensions)(columns);
197+
198+
expect(columns).toEqual(expected);
199+
});
200+
165201
it('works with multiple evaluators', function () {
166202
const extensions = [
167203
{

src/bind.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function bindColumn({
2323
return match(col) && evaluate(col);
2424
});
2525

26-
return mergeWith(column, ...matches, (obj, src) => {
26+
return mergeWith({}, column, ...matches, (obj, src) => {
2727
if (isArray(obj)) {
2828
return obj.concat(src);
2929
}

0 commit comments

Comments
 (0)