neilff / redux-ui-router

ngRedux bindings for Angular UI Router
MIT License
143 stars 48 forks source link

Current params update occurring too late with ui-router 1.x #76

Closed Nighthawk14 closed 7 years ago

Nighthawk14 commented 7 years ago

Hey @hally9k, I think to finish the compatibility with ui-router 1.x we still missing a small piece.

As now the flow of transition has changed, the onSuccess transition is happening after the instantiation of the component controller. So we actually need to update the currentParams object on the state before that. There is couple of solutions:

  1. Use the onFinish instead of onSuccess as it is happening always before the instantiation (onFinish is the last transition event before onSuccess):
    $transitions.onFinish({}, $transition$ => ngUiStateChangeActions.onStateChangeSuccess(...prevNextReduxState($transition$)));

    instead of

    $transitions.onSuccess({}, $transition$ => ngUiStateChangeActions.onStateChangeSuccess(...prevNextReduxState($transition$)));
  2. Add a new toParams object to the state that will be used in the component controller instead of currentParams. This will be updated at onStart time. But using toParams in a controller constructor seems a bit weird.
  3. Dispatch a new action using onFinish or onEnter and update the currentParams at this time instead of at onSuccess time.

FYI the flow of transition is : onBefore > onStart > onEnter > onFinish > onSuccess.

I tested 1 and 3 and it's working fine.

Cheers.

That would fix #74

Nighthawk14 commented 7 years ago

Fixed by #78