-
Notifications
You must be signed in to change notification settings - Fork 483
Conversation
78e1e63
to
8334355
Compare
function resolveLazyChildren(route: Route, injector: Injector): Promise<Route> { | ||
if (typeof route.loadChildren === 'function') { | ||
//not supported | ||
//return route.loadChildren().; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would this not be supported if it returns a Promise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue I had with this one is that loadChildren is typed as () => Type<any> | NgModuleFactory<any> | Promise<Type<any>> | Observable<Type<any>>
So out of those we could do a instanceof
to see if it's a NgModuleFactory
and Coerce the Observable into a Promise
But I'm uncertain how to how to retrieved a NgModuleFactory from a Type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use the RouterConfigLoader
?
https://github.com/angular/angular/blob/master/packages/router/src/router_config_loader.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here's an example of how it's used
https://github.com/angular/angular/blob/master/packages/router/src/router_preloader.ts#L126
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a Private API since you cant find it here https://github.com/angular/angular/blob/master/tools/public_api_guard/router/router.d.ts
but it does infer a reasonable point
if (t instanceof NgModuleFactory) {
return of (t);
} else {
return fromPromise(this.compiler.compileModuleAsync(t));
}
this indicates to me that the returned function will be a factory if it's in AOT or just a normal type if it's JIT, hence the compiler
1eb506b
to
3d046c1
Compare
I've added Karma config for testing to the project since it was becoming very tedious to test if specific scenarios were working. |
c06886b
to
c58dda3
Compare
|
||
class FileLoader implements ResourceLoader { | ||
get(url: string): Promise<string> { | ||
return new Promise((resolve) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResourceLoader#get returns a Promise | string union. You can thus return readFileSync directly instead of the resolved promise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With fs.ReadFile
you have to provide callbacks and what not, it's not as easy as just calling .toString()
. I did simplify it a little bit more, I don't think using the sync version could get it anymore concise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh, readFileSync is used in that code. No promise needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh! sorry, I misread what you said, gotcha
7391eb2
to
2755b92
Compare
class MockServerModule{} | ||
return jitCompiler.compileModuleAsync(MockServerModule); | ||
} | ||
function createFactoryAndGetRotues(routeConfig: Route[], moduleMap: {[key: string]: any} = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in createFactoryAndGetRotues
}); | ||
} | ||
|
||
function cocerceIntoPromise<T>(mightBePromise: Observable<T> | Promise<T> | T): Promise<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this has to be coerceIntoPromise ?
2e136e6
to
32406c9
Compare
ea09dbb
to
93a6a46
Compare
now that |
72622e3
to
62c9292
Compare
got the tests to pass. If Alex already wrote this then I think this would be a great example of how people can build stuff with Universal. @Toxicable maybe you can turn this into a blog post |
I've updated it but I don't know how to configure the build system. |
@Toxicable Do you want me to push to this branch or just walk you through it? |
@CaerusKaru Feel free to push to this branch |
closed in favour of #1002 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
A tool for traversing a given factory and retrieving the routes.
Useful when used with Universal pre-rendering when you want to prerender each potential static route
This differs from Alex's one, ref https://github.com/alxhub/universal/blob/pwa-tools/modules/pwa-tools/lib/ls-routes/lib.ts
In that it works off a factory bundle rather than the Module src and is only hunting for routes instead of other metadata