Closed Kusmeroglu closed 11 months ago
Thanks for the detailed description @Kusmeroglu! You're right, it does look like we have an inconsistent naming pattern here. We're always happy to take in pull requests if you'd like to add the change! I think on/off
makes sense as it also aligns with the direct callbacks you can attach to rive (i.e., onStateChange
), so it may make sense to add an off
alias to unsubscribe
and perhaps add a deprecation notice that unsubscribe
would be removed in a future major version bump. That way we can make this a minor/patch version bump for now.
Additionally, when this change goes in, we'll make sure to reflect the docs.
@zplata I put up a PR here: https://github.com/rive-app/rive-wasm/pull/328
There is an 'unsubscribeAll', and I'm not sure what name would match on
/off
. Perhaps off
with no callback supplied, or removeAllListeners(type)
.
@Kusmeroglu thanks for this! We'll get this patched and pushed in next chance we get. I think something like the latter makes sense for the unsubscribeAll
- removeAllEventListeners
or something. We can add a separate commit for that
Released in v1.2.3
Description
The event handlers for the
Rive
class are inconsistent in their naming. UsuallyaddEventListener
/removeEventListener
(javascript DOM API) or.on
/.off
(popularized by jQuery) or.subscribe
/.unsubscribe
are used. It's confusing to haveRive.on
/Rive.unsubscribe
because the names are not obviously related. I also can't find anything in the Rive API docs regarding these methods so it was hard to discover that they existed.These functions are defined here for .on and here for .unsubscribe.
I am glad to provide a pull request to fix this!
Provide a Repro
I can't use the
onStateChange
argument to the Rive constructor because my handleStateChange function changes during the lifetime of the Rive, so my usage looks like this:Expected behavior
Both
Rive.on
andRive.off
exist and are aliases toRive.subscribe
andRive.unsubscribe
(or vice-versa).