I have some state-modifying tasks needed to be run inside componentDidMount
as well inside button click handlers defined in renderS
method.
Tasks have a lot of common code so i've decided to join them inside one class, that receives scope and applies necessary actions.
Trouble is: inside renderS
method i have access to ComponentScopeU[...]
and inside componentDidMount
i have ComponentScopeM[...]
I've found that to access .props
i need to verify my scope have supertrait ComponentScope_P[...]
, to access .state
my scope should have supertrait ComponentScope_S[...]
and to have ability to .modState
i should pass implicitly CompStateAccess[...]
.
So currently i have code like this
case class State(...)
type ScopePS = ComponentScope_P[Int] with ComponentScope_S[State]
type StateAccess[C] = CompStateAccess[C, State]
implicit class MyActions[T <: ScopePS : StateAccess](scope: T) {...}
It's working but i wonder how could this be simplified, i.e. how could props\state be accessed inside renderS
and componentDidMount
via common code?