Comments (7)
Yea that's just the example, you don't have to use webpack chunks. It does however assume the babel dynamic import plugin will be used in the implementation. But that's optional, for this optional feature. It's not a dependency for the module.
from lit-redux-router.
@hutchgrant
Curious, does this assume a hard dependency on webpack?
const AboutRoute = {
load: () => import(/* webpackChunkName: "aboutPage" */ '../pages/home/about'),
loading: 'eve-loading'
};
const DocsRoute = {
load: () => import(/* webpackChunkName: "docsPage" */ '../pages/home/docs'),
loading: 'eve-loading'
};
from lit-redux-router.
oh I see, this is just for your example usage, and not needed for the underlying implementation?
from lit-redux-router.
Thanks for opening this issue @hutchgrant, it will be a great addition!
from lit-redux-router.
This problem intersects with another use case that is if you have to query for data or any other async process before being able to display a route. (angular ui-router had an interface for this for example)
calling an api using a promise
<lit-route
path="/docs"
component="docs-page"
.resolve="${() => fetch('mydomain.com/api')}"
></lit-route>
dynamic import is a promise as well
<lit-route
path="/docs"
component="docs-page"
.resolve="${() => import(/* webpackChunkName: "aboutPage" */ '../pages/home/about')}"
></lit-route>
As you suggested we need a component for loading status
<lit-route
path="/docs"
component="docs-page"
.resolve="${() => import(/* webpackChunkName: "aboutPage" */ '../pages/home/about')}"
loading="my-loading"
></lit-route>
And potentially add onSuccess
and onError
events for redirects or tracking or whatever
<lit-route
path="/docs"
component="docs-page"
.resolve="${() => import(/* webpackChunkName: "aboutPage" */ '../pages/home/about')}"
loading="my-loading"
@success="${result => console.log(result)}"
@error="${error => console.log(error)}"
></lit-route>
from lit-redux-router.
I suggest the following implementation with a few changes in the stateChanged lifecycle and the render function
public stateChanged(state: State): void {
this.active = isRouteActive(state, this.path);
this.params = getRouteParams(state, this.path);
if (this.active && this.resolve) {
this.isResolving = true;
this.resolve()
.then(() => {
this.isResolving = false;
// here potentially fire custom success event
})
.catch(() => {
this.isResolving = false;
// here potentially fire custom error event
});
}
}
public render(): TemplateResult {
if (!this.active) {
return html``;
}
if (this.resolve && this.isResolving) {
return !this.loading ? html`` : this.getTemplate(this.loading);
}
if (!this.component) {
return html`<slot></slot>`;
}
return this.getTemplate(this.component, this.params);
}
from lit-redux-router.
That looks good to me, though I still have to test it. That's way better looking logic than my hacky method.
Also the success and error events should be optional as well.
from lit-redux-router.
Related Issues (20)
- Add `module` property in package.json HOT 12
- Ability to conditionally pre-redirect HOT 3
- Update Documentation to show store setup HOT 2
- route not working. HOT 1
- path routing 404 on client side HOT 3
- JS error in Edge v44 HOT 4
- allow path to assume base href HOT 3
- Suggestion - enable `scrollDisable` by default HOT 3
- how to get query params HOT 2
- Component reloads on every state change HOT 5
- Imports should specify the file extension HOT 11
- Lazy Loaded components are never rendered
- Usage with redux-toolkit? HOT 3
- lit-route lit-plugin typing HOT 4
- Upgrade to latest version / distribution of `Lit@2` HOT 9
- The demo folder is also published to NPM which causes issues when building HOT 1
- Allow the use of sub-routers HOT 1
- Add authentication property HOT 2
- add option to disable / opt-out of Shadow DOM to support global CSS libraries HOT 8
- Using subroutes inside of components (with shadowRoot) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lit-redux-router.