Closed greghuc closed 1 year ago
Also thinking about this, is there any reason we wouldn't delete watch[mutation.oldValue]
in this case? Otherwise, there'll be a memory leak overtime as a caller makes multiple onload calls for the same element.
@shama or @lukeburns do you have any thoughts on this?
@greghuc seems like this is a good improvement, and covers some subtle characteristics about how on-load works for the better. Do you see any drawbacks from this? Nothing is coming to mind when looking at this.
We can cut this in as a patch or minor in 4.0.0 after we discuss further.
@bcomnes I made this PR ages ago, and can't remember all the details. However, my former self did put serious work into understanding how on-load worked, so I do trust this PR and the suggestion to delete watch[mutation.oldValue]. I still use on-load, so it's great it's getting some love.
@bcomnes this looks good to me! 👍
Hi @bcomnes.
I'm not sure if you're still maintaining the on-load package, but if you are.. could you consider merging this (just updated) pr from 2016?
I just touched some code that uses on-load, so I decided to update this pr. The pr has tests and was ok-ed by @lukeburns in 2018. I also updated everything to 2023 by a) updating deps and b) linting with standard.
The underlying pr was two changes:
Many thanks!
Greg
Thanks @greghuc. Tested locally and LGTM. I'll merge this and do some other clean up then publish as new major (because of the var
to let
changes. Even though 6+ years later now let
is well supported now, still technically a breaking change).
@shama many thanks!
This PR addresses an edge case of
on-load
that has unintuitive behaviour. Specifically:on
andoff
functions (compared to the previous call)off
callback is eventually triggered on the element, the oldestoff
function supplied is called. This is unintuitive, as theoff
function was superceded in later calls to onload.This PR changes the behaviour to use the latest
off
function supplied instead, which seems more intuitive. It would also use the lateston
function too, but I don't think this callback would ever called.The PR changes
to
So previously the latest
watch
array for an element was overwritten with the earlierwatch
array; this means that the earlieron
/off
functions are always used in element callbacks. In this PR, we only overwritewatch[newValue][2]
withwatch[mutation.oldValue][2]
, which I believe indicates whetheron
oroff
was called last. So the lateron
/off
functions are used as element callbacks instead.