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

Return a function directly instead of an object #5

Open
alexhoma opened this issue Dec 28, 2019 · 0 comments
Open

Return a function directly instead of an object #5

alexhoma opened this issue Dec 28, 2019 · 0 comments
Labels
good first issue Good for newcomers

Comments

@alexhoma
Copy link
Owner

alexhoma commented Dec 28, 2019

Description
It's not a bug. I've found a way to use the link function in a simpler way. The createRouteLinks function returns an object with only one function inside and I think this can be changed.

Describe alternatives you've considered
Return a function instead of an object, to simplify the usage. ⚠️ It will break the library API.

Related code:

routex.js/src/client.js

Lines 60 to 85 in 192e401

function createRouteLinks(routeDefinitions) {
const composedRoutes = composeRoutes(routeDefinitions);
return {
link({ route: routeName, params = {} }) {
if (!routeName) {
throw new Error(`Function link() should have a route name`);
}
let foundRoute = findRouteByName(composedRoutes, routeName);
if (!foundRoute) {
throw new Error(
`Route name "${routeName}" is not defined in your route definitions`
);
}
const { as, href } = foundRoute.getLinkProps(params);
return {
as,
href
};
}
};
}

@alexhoma alexhoma added the good first issue Good for newcomers label Dec 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant