Rethink event propagation
Airblader opened this issue · 2 comments
Airblader commented
NOTE: This information is just a rough writeup for my own personal use, I don't expect anyone to understand or work on this :-)
-
Should
QueryParam#setValue
call_updateValue
?
a. Ensure models work without binding anything to components
b. Particularly,QueryParam#setValue
→QueryParamGroup#valueChanges
c. Investigate FormControl / FormGroup wrt differences of emitEvent and emitModelToView / emitViewToModel -
Make queryParamName directive go through the parent queryParamGroup directive rather than injecting the service itself
-
Add tests for differet setValue / valueChanges interactions
Open Questions:
- What do we need the group service for exactly and could we do without?
a. Needed for: router, destroy
Airblader commented
Temporary notes:
- FormControl
- setValue / patchValue
- onlySelf, emitEvent, emitModelToViewChange, emitViewToModelChange
- onChange function <=> emitModelToViewChange !== false
- passes emitViewToModelChange
- parent#updateValue <=> !onlySelf
- valueChanges <=> emitEvent
- FormGroup
- setValue / patchValue
- onlySelf, emitEvent
- iterate over children, pass onlySelf: true, emitEvent as given in input
- parent#updateValue <=> !onlySelf
- valueChanges <=> emitEvent
Airblader commented
More thoughts for myself:
- QueryParam
- setValue
- onlySelf (false): To prevent propagating to group to coordinate synchronous group emission instead
- emitEvent (true): Emit on valueChanges
- emitModelToViewChange (true): Trigger changeFn
- QueryParamGroup
- setValue, patchValue
- emitEvent (true): Emit on valueChanges
- emitModelToViewChange (true): Trigger changeFn
====
(1) URL updates
- Expected: valueChanges on group & control
- Update controls using onlySelf: true + emitEvent: true + emitModelToViewChange: false
- Update group using emitEvent: true + emitModelToViewChange: false
(2) Control updates
- Expected: valueChanges on group & control, URL update
- Send through internal queue
(3) QueryParam#setValue
- Expected: valueChanges on group & control, URL update
- valueChanges must emit even if not bound to any controls!
- Defaults
- (!) PROBLEM: after URL update, valueChanges would emit again?
- Or would it… router probably swallows this
(4) QueryParamGroup#setValue
- Expected: valueChanges on group & control, URL update
- valueChanges must emit even if not bound to any controls!
- Defaults
- (!) PROBLEM: after URL update, valueChanges would emit again?
- Or would it… router probably swallows this
===
Idea: Make compareWith mandatory, use it in setValue to check if value actually changed and bail otherwise
- Probably not what a user expects when calling setValue, though
- Mitigation
- Another parameter (onlyDistinct) only set for QueryParam in (1)
- Have QueryParam#setValue return boolean whether the update happened, set QueryParamGroup#emitEvent only to true
if at least one control returned true in this case ```