Open aneilbaboo opened 5 years ago
Changing from merge to extend would probably be backwards-incompatible change and potentially even dangerous if there are existing users that depend on merging strategy right now, no? It should probably be configurable either from the set
call or globally but default to current behavior.
That's a legitimate worry. However, the current behavior is a bug. So perhaps there's a path to fixing this:
mergeWhenSettingObjectAttributes
to the dynogels top level which sets an internal property_.merge
behavior:
"Warning: Please explicitly set mergeWhenSettingObjectAttributes. see
https:\\github.com\clarkie\dynogels\issues\174
for details. Current default behavior of Item.set, when value is an object, is to merge the new object with the existing object. In a future major release, this will change to overwrite. Usedynogels.mergeWhenSettingsObjectAttributes=false
for overwrite behavior. Set totrue
for merge behavior."
_.extend
, _.merge
._.extend
.Unexpected as it is, it seems like the behaviour is by design, because Item.prototype.update
uses Item.prototype.set
https://github.com/clarkie/dynogels/blob/6246c13ff8732d9508b854296970dfc592fef351/lib/item.js#L67
I noticed two problems in
Item.set
.doesn't work.
Inspecting
tweet.attrs
reveals the value to beThe problem is that
_.merge
is used, which causes recursive merging._.extend
should be used instead.