rescript-react-navigation icon indicating copy to clipboard operation
rescript-react-navigation copied to clipboard

Proposal : Linking API

Open Freddy03h opened this issue 2 years ago • 7 comments

Linking API

For my project I created a linking API but I'm far from zero cost binding, since ReScript 10 and optional record attribute, it's seems less shitty and I think it's cool to discuss to have experts opinions about it.

Proposal

type routeName = string

type rec pathConfig = {
  path?: string,
  exact?: bool,
  initialRouteName?: routeName,
  screens?: screens,
}
and screens = Js.Dict.t<pathConfig>

type config = {
  initialRouteName?: routeName,
  screens: screens,
}

type t = {
  enabled?: bool,
  prefixes: array<string>,
  config?: config,
}

type routeNameAndConfig = (routeName, pathConfig)

let makeScreens = (screens: array<routeNameAndConfig>): screens => screens->Js.Dict.fromArray

Example

let options = {
  prefixes: [WebConst.origin],
  config: {
    initialRouteName: "app",
    screens: [
      (
        "app",
        {
          screens: [
            ("news", {screens: [("newsList", {path: ""})]->makeScreens}),
            (
              "planning",
              {
                screens: [
                  (
                    "planningNav",
                    {
                      screens: [
                        ("planningNewList", {path: "planning/news"}),
                        ("planningList", {path: "planning"}),
                      ]->makeScreens,
                    },
                  ),
                ]->makeScreens,
              },
            ),
            (
              "catalogue",
              {
                screens: [
                  (
                    "catalogueNav",
                    {
                      screens: [
                        ("seriesList", {path: "series"}),
                        ("authorsList", {path: "authors"}),
                        ("publishersList", {path: "publishers"}),
                      ]->makeScreens,
                    },
                  ),
                ]->makeScreens,
              },
            ),
          ]->makeScreens,
        },
      ),
      (
        "modalNav",
        {
          screens: [
            ("volumeDetail", {path: "volumes/:id"}),
            ("editionDetail", {path: "editions/:id"}),
            ("serieDetail", {path: "series/:id"}),
            ("publisherDetail", {path: "publishers/:id"}),
            ("authorDetail", {path: "authors/:id"}),
          ]->makeScreens,
        },
      ),
      (
        "collectionPublic",
        {
          initialRouteName: "collectionPublicNav",
          path: "user/:username",
          screens: [
            (
              "collectionPublicNav",
              {
                screens: [
                  ("collectionPublicList", {path: "collection"}),
                  ("planningPersoPublicList", {path: "planning"}),
                  ("missingPublicList", {path: "missing"}),
                  ("wishPublicList", {path: "wish"}),
                ]->makeScreens,
              },
            ),
            ("collectionPublicEdition", {path: "edition/:editionId"}),
          ]->makeScreens,
        },
      ),
    ]->makeScreens,
  },
}

Freddy03h avatar Dec 22 '22 17:12 Freddy03h

Is there a real interest to define screens = Js.Dict.t<pathConfig> ? If that's a abstract type (type screens;) makeScreen could be zero cost, right ?

MoOx avatar Dec 30 '22 10:12 MoOx

I don't know how to do that…

If screens isn't defined, it seems compiler take the first declared definition of screens and made others as errors.

Freddy03h avatar Feb 14 '23 10:02 Freddy03h

Is this needed with #58 ?

MoOx avatar Mar 21 '23 16:03 MoOx

Linking is not blocking for a new release, because this API doesn't exist yet.

I tested it on 10.0, I can give a new try with 10.1

Freddy03h avatar Mar 24 '23 13:03 Freddy03h

This could help us : https://github.com/rescript-lang/rescript-compiler/issues/6545

Freddy03h avatar Apr 12 '24 12:04 Freddy03h