-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Simplify Wasp TS config (TS SDK) syntax #2353
Comments
Boilerplate when defining pages and routesThere is quite some boilerplate here, big part of it coming from part that is common for the rest of the config also, which is that declration names and import symbols are often very same or similar. But, let's be specific for routes and pages. Here is how I attempted to make my Wasp TS config more readable: appPageWithRoute('Main', '/', '@src/client/MainPage.jsx', { auth: true });
appPageWithRoute('Thoughts', '/thoughts', '@src/client/ThoughtsPage.jsx', { auth: true });
appPageWithRoute('Login', '/login', '@src/client/LoginPage.jsx');
appPageWithRoute('Signup', '/signup', '@src/client/SignupPage.jsx');
function appPageWithRoute(pageName: string, path: string, from: ExtImport['from'], config?: { auth: boolean }) {
const page = app.page(pageName, {
component: { importDefault: pageName, from },
...(config?.auth && { authRequired: config?.auth })
});
app.route(pageName + 'Route', { path, to: page });
} I overdid it a bit, I don't think this should be normal API, because we need to be able to define routes on their own (route can point to other stuff than page, or at least it should be able to), and also positional arguments might not be the best, but it does go some way in the right direction I believe. Here is what @vincanger did: // Either pull the name from the const variable name, e.g. "MainPage"...
const MainPage = app.pageWithRoute({
import: 'Main',
from: '@src/client/MainPage.jsx'
route: '/',
authRequired: true
});
// ...or use the same name as the imported component
pp.pageWithRoute({
import: 'MainPage', // Page name would default to MainPage, and route name to MainPageRoute
from: '@src/client/MainPage.jsx'
route: '/',
authRequired: true
}); |
Boilerplate caused by declaration names and importsBig part of boilerplate right now is that you have to define declration names always, even though often they are not used anywhere, and also you have to provide names even for default imports (although we might phaes out default imports so in that case not a concern), and declaration names and import names are often really just the same thing. This goes for more or less all declarations. Names are important for |
Route decl names are important for referencing them in the email auth provider setup. We can change this to be a plain string. e.g. |
For now, we made Wasp TS config have the same syntax as Wasp DSL.
But, it now becomes easier for us to iterate on the syntax, especially if we phase DSL out.
So let's talk here about how we can improve it and collect ideas, so we can do it when the moment comes!
We can do changes on multiple levels:
Natural progress can also be (1) -> (2) -> (3), meaning that we can try out new stuff in (1), then adapt (2) if that works, and finally push the change to (3). Or we can skip steps of course if that makes sense, but this way we can test things gradually.
The text was updated successfully, but these errors were encountered: