Closed ivan-kleshnin closed 9 years ago
I don't like this part
function model(actions) {
return {
page$: actions.transition$.map(({toState, fromState}) => {
// Since Router5 doesn't allow arbitrary data to be forwarded through it,
// find the original route object and initiate its handler.
let routeName = toState.name;
let route = routes.filter(({name}) => name === routeName)[0];
let content = route.handler();
return {routeName, content};
}),
};
}
As soon as routes will be nested it will complicate things as will need to flatten route object before every lookup.
Since Router5 doesn't allow arbitrary data to be forwarded through it, find the original route object and initiate its handler.
Maybe we shouldn't couple routes and handlers at all.
I mean, maybe we need two or more datastructures:
// For router5 consumption
let routes = [
{path: "/users/", name: "users.index"},
{path: "/users/:id", name: "users.detail"},
];
// For app consumption
let contentHandlers = {
"users.index": () => ...,
"users.detail": () => ...,
};
And then:
function model(actions) {
return {
page$: actions.transition$.map(({toState, fromState}) => {
let content = contentHandlers[toState.name]();
return {routeName, content}; // possible to extend with other handler besides "content"
}),
};
}
What do you think about this?
I also thought about component approach like http://router5.github.io/docs/with-react.html#/inbox but as CycleJS team is going to remove custom elements it's hard to predict how to arrange all this together.
Between router5
/cycle-router5
and director
/cycle-director
, my preference is definitely for router5
. director
looks like it has stagnated a bit as a project, and its Cycle driver is a bit messy. It's odd that routes are instantiated in main()
, rather than in the driver's make
function. director
's API seems incomplete for at least my purposes. My recent router experiences has been with Angular ui-router
and react-router
, and simple things like a link builder utility, which isn't much to implement, is enormously useful. Ultimately, I'm most attracted to router5
because of its author is very much aligned with reactive programming principles, which in turn aligns well with what we're doing with Cycle.
Maybe we shouldn't couple routes and handlers at all.
I agree. While it means you have to declare the state names twice, I do think it's a better way to separate what router5
expects and what the application needs.
I'll work on updating the demo to your proposal.
Thanks for pointing out the depreciation of custom elements. Some references to future readers of this thread, regarding the proposal replacement of custom elements with dialogues:
@basham, thank you for the answer. I share your opinion and I will track your repo ;) CycleJS demos are still very rare.
Do you have an established opinion about local vs global CSS?
@ivan-kleshnin Changes are made. I've also updated it so custom components are no longer used, in favor of the dialogue architecture. I really like it. Seems less magical and very sensible to implement.
Do you have an established opinion about local vs global CSS?
Moving your question to issue #2.
I see you've implemented Cycle-Demo with both Director and Router-5 alternatives. Which one do you like the best?
My opinion is that Router5 is a much better library than Director. The last one does not even allow to build URLs which is a disaster.
Second thing is that Cycle-Director code is a total mess. Cycle-Router5 code looks clean and reasonable.
I also looked for another routing libraries and Router5 is my current TOP-1.
What's your opinion?