Hey,
I am working on a module that depends on user-defined type
. I am not sure if there’s a better way than the below approach:
module type NavigationConfig = {type route;};
module CreateNavigation = (Config: NavigationConfig) => {
module StackNavigator = {
type action =
| Push(Config.route)
| Pop;
type state = {routes: list(Config.route)};
let component = ReasonReact.reducerComponent("CallstackRerouteRouter");
let make = (~initialRoute, children) => {
...component,
initialState: () => {routes: [initialRoute]},
reducer: (action, state) =>
switch action {
| Push(route) => ReasonReact.Update({routes: [route, ...state.routes]})
| _ => ReasonReact.NoUpdate
},
render: self =>
self.state.routes
|> List.map(route => children(~currentRoute=route))
|> Array.of_list
|> ReasonReact.arrayToElement
};
};
};
I don’t like the need of passing type route
around - feels like it should be easy to let compiler infer it. Unfortunately, I was unable to do so in any of my prior attempts.
Anyone?