TNG/ngqp

Rethink event propagation

Airblader opened this issue · 2 comments

NOTE: This information is just a rough writeup for my own personal use, I don't expect anyone to understand or work on this :-)

  1. Should QueryParam#setValue call _updateValue?
    a. Ensure models work without binding anything to components
    b. Particularly, QueryParam#setValueQueryParamGroup#valueChanges
    c. Investigate FormControl / FormGroup wrt differences of emitEvent and emitModelToView / emitViewToModel

  2. Make queryParamName directive go through the parent queryParamGroup directive rather than injecting the service itself

  3. Add tests for differet setValue / valueChanges interactions

Open Questions:

  1. What do we need the group service for exactly and could we do without?
    a. Needed for: router, destroy

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

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                  ```