I have an idea that could solve some problems I have with the design.
path
is a bit confusing as we are naming different things with that name. Also, this doesn’t fit well with URLs containing a query, and that’s something we need if we want to support searches.
// API right now:
actions.router.set(pathOrObj)
actions.source.fetch(pathOrObj)
state.source.get(pathOrObj)
// This is a path.
source.get("/category/nature/")
// This is a path too...
source.get("/category/nature/page/2/")
// This is a path with a page (but actually is the path above).
source.get({ path: "/category/nature/", page: 2 })
// And what's this? Also a path? How do you express it as an object?
source.get("/category/nature/page/2/?s=gullfoss")
My idea is to rename path
to route
.
The API would be then like this:
actions.router.set(routeOrObj)
actions.source.fetch(routeOrObj)
state.source.get(routeOrObj)
// A route can be equal to a path...
route = "/category/nature/";
obj = { path: "/category/nature" }
// ...but not always.
route = "/category/nature/page/2/";
obj = { path: "/category/nature", page: 2 }
// It can even have a query!
route = "/category/nature/page/2/?s=something";
obj = { path: "/category/nature", page: 2, query: "?s=something" }
The logic to pass from route to object and vice versa could be implemented with two functions, routeToObj
and objToRoute
.
data
objects would be generated for each route
and stored in state.source.data[route]
.
What I’m not sure about is if route
should be the part of a URL without the site URL, or just without the site domain, as this would only affect to the library resolver
in wp-source
, and it could that library what handles those different cases.
// WordPress site in a domain's root
url = "https://test.frontity.io/category/nature/"
route = "/category/nature/"
// WordPress site in a domain's subpage
url = "https://test2.frontity.io/wp-site/category/nature/"
// how should be route in this case?
route = "/category/nature/"
route = "/wp-site/category/nature/"
@orballo, @luisherranz, opinions? Suggestions?