rtfeldman / seamless-immutable

Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.
BSD 3-Clause "New" or "Revised" License
5.37k stars 195 forks source link

Deep .merge of identical objects that contain arrays returns a new object #94

Closed zuk closed 8 years ago

zuk commented 8 years ago

A .merge with {deep: true} of two identical objects that contain an array is returning a new object.

For example:

var a = Immutable({foo: []})
var b = Immutable({foo: []})
var ab = a.merge(b, {deep: true})
ab === a  // => false

Without a nested array it works as expected:

var a = Immutable({foo: {}})
var b = Immutable({foo: {}})
var ab = a.merge(b, {deep: true})
ab === a  // => true
zuk commented 8 years ago

Added a failing test case for this in AkiraMD/seamless-immutable@98a912dd1d60e2fe7c805f6455c7e1c045ef0a88

zuk commented 8 years ago

Oh boy... started trying to fix this myself, but to be honest the current codebase is kind of a horror show. I understand the imperative not to make seamless-immutable dependent on too many libraries, but there's a whole lot of reinventing the wheel going on here. Using something like lodash for a lot of the type and equality checking stuff might help. I'm going to look in to some other libraries to manage an immutable Redux state now.