Closed m-mujica closed 5 years ago
@justinbmeyer should the first call to obj.set("foo", "bar");
trigger an add
event instead of a set
event?
wondering if the add
event is just an old artifact that does not apply to Maps or if there is an issue.
Yes, it should fire an add event
It looks like can-define never fires "add" patches even in cases where the key did not previously exist.
https://github.com/canjs/can-define/blob/c98548b0b849bc10df0eb1e99e0cb873b902f325/can-define.js#L517 https://github.com/canjs/can-define/blob/c98548b0b849bc10df0eb1e99e0cb873b902f325/can-define.js#L1094
However, can-define does fire "add" events correctly. https://github.com/canjs/can-define/blob/c98548b0b849bc10df0eb1e99e0cb873b902f325/can-define.js#L686
Contrast with can-observe objects where having previously had the key determines "add" vs. "set" patches. https://github.com/canjs/can-observe/blob/f365a0180353851a8b76dfec010e251e2836a751/src/-make-object.js#L142
I would consider the can-observe behavior to be the correct one, and using a similar "hasOwn" selector for patches in can-define should make "add" patches align with "add" events.
Brad, I created this issues btw https://github.com/canjs/can-define/issues/400
The docs were correct. There was an issue in can-define and that was fixed.