Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire Value Change Callbacks consistently #499

Merged

Conversation

seanpdoyle
Copy link
Contributor

Closes 490

According to the Change callbacks documentation:

Stimulus invokes each change callback after the controller is
initialized and again any time its associated data attribute changes.
This includes changes as a result of assignment to the value’s setter.

Prior to this change, this was true for all value change callbacks
except for those that declare defaults.

This change moves the
ValueObserver.invokeChangedCallbacksForDefaultValues() invocation out
of the constructor and into the ValueObserver.start() call, which is
invoked by Context.connect, which is invoked after the
Context.constructor.

[Closes 490][]

According to the [Change callbacks][] documentation:

> Stimulus invokes each change callback after the controller is
> initialized and again any time its associated data attribute changes.
> This includes changes as a result of assignment to the value’s setter.

Prior to this change, this was true for all value change callbacks
_except_ for those that declare defaults.

This change moves the
`ValueObserver.invokeChangedCallbacksForDefaultValues()` invocation out
of the constructor and into the `ValueObserver.start()` call, which is
invoked by [Context.connect][], which is invoked _after_ the
[Context.constructor][].

[Closes 490]: hotwired#490
[Change callbacks]: https://stimulus.hotwired.dev/reference/values#change-callbacks
[Context.constructor]: https://github.com/hotwired/stimulus/blob/5149adf287425597306d7871b1820795d7af1e66/src/core/context.ts#L20-L34
[Context.connect]: https://github.com/hotwired/stimulus/blob/5149adf287425597306d7871b1820795d7af1e66/src/core/context.ts#L36-L47
@dhh dhh merged commit eeb870a into hotwired:main Dec 17, 2021
@seanpdoyle seanpdoyle deleted the default-value-lifecycle-callback-order branch December 17, 2021 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants