Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration(solid-js): reactivity of instance methods, getState vs subscribe's route, etc #468

Open
aleksanderd opened this issue Jun 26, 2020 · 0 comments

Comments

@aleksanderd
Copy link

Hi!

I playing with route5 and solid-js and there is a primitive state named signal. It needed to make things reactive in solid-js.

I subscribed to router and it work ok:

  const [getRouteState, setRouteState] = createSignal<RouteState>({
    route: props.router.getState(),
    previousRoute: null,
  });

  if (typeof window !== 'undefined') {
    const unsubscribe = props.router.subscribe(setRouteState) as () => void;
    onCleanup(unsubscribe);
  }

but there is getState() in context-provided router instance... and it is useless in solid-js by default - signal is needed to be reactive. It is possible to override the methods isself:

  const router = createRouter(routes);
  const [getState, setState] = createSignal<State | null>(router.getState());
  router.setState = setState;
  router.getState = getState;

Is it good idea at all?
I can't understand, may be the getState() is for internal usage only and must not be used at client apps, as reactive at least?
Is getState() always the same as route prop in subscribe handler or there is some diffs?

Second issue is about checking if the route active or not. In examples I found only equals by name. But what about nested routes, where the route is always most nested one. Is it ok to check it like this:

name === route.name || route.name.substring(0, name.length + 1) == name + '.')

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant