-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
WIP feat(StaticViewStrategy): ability to statically analyze aurelia modules #606
Conversation
But dynamic compose is not a viable case for this right? |
Questions and comments: This should also accept a string, right?
Dunno what that means without an example.
Why is that a benefit?
|
<template>
<compose view-model.bind='vm' ></compose>
</template> export class MyElement {
viewModels = {
date: DateEditor,
number: NumberEditor
}
// change this to another class if needed
vm = this.viewModels.date;
}
Yes, it accepts string,
It's easier to scope local resources used in a view, thus aid app structuring / prototyping
you formatted the md wrong 😄 @davismj |
I forgot to answer your question. I don't think there would be any issue, consider the fact that router only care about the first custom element it hits in the module anyway, which means giving it a class or a module should be no different. But I haven't dug into the router code enough to confirm this. |
|
With the help of aurelia/framework#858, probably we can make it easier by allowing config to opt out the default resources that aren't used, then we can make typeof NO_AU_COMPOSE_V1 === 'undefined' ? Compose : ComposeV2 |
Really cool. Why still take a moduleId? This would mean Aurelia still needs a loader specific to the bundler used. Once this is introduced I doubt there would be a need for using moduleIds, or is there? |
I was thinking of supporting |
On a second thought, a decorator seems to be an overkill, probably we can make it cleaner, by enabling convention via static property on the class: import view from './calendar.html'
class Calendar {
static view = {
template: view,
resources: [],
imports: () => import('splitted-bundle.js')
}
static inject = [CellService];
constructor(service) {
this.service = service;
}
load() {
this.isLoaded = true
}
searchAll() {
this.service.searchAllCells();
}
} |
A decorator seems better because it aligns itself with the rest of the API. What makes it seem like an overkill? |
We can have both, like with |
Instead of it being |
Renaming it to about @view({
template: template,
dependencies: () => [...] // let devs decide what to go in here, more flexibility
})
class myclass {
} |
Sounds good. Let's go for that and see how it turns out. |
can |
yeah, we could have that. final API could look like interface IViewConfig {
template: string | HTMLTemplateElement | Promise<string | HTMLTemplateElement>;
dependencies?: Function[] | { (): Function[] | Promise<Function[]> };
} |
closed as this is part of #614 |
This PR adds static view strategy, which will give ability to declare all resources used in a view statically, also optionally lazily.
Syntax:
Usage example:
Differences compared to dynamic loading:
@staticView
doesn't useLoader
to load resources, as everything is declared statically, and thus, bundler friendly.@staticView
can use local class as custom elements, custom attributes, unlike dynamic module loading, where classes need to be exported to be discovered. (As shown in the example above,Cell
class is declared locally, and only used withinCalendar
view)@staticView
can take pre-builtHTMLTemplateElement
as its template config, thus help avoid issue with IE Html parser, where it strip invalid markup, (e.g:<template/>
element inside a<table/>
element). This also helps user to use hyper script syntax to pre built the template, and theoretically JSX too (for fun purposes I guess)@staticView
has config propertyimports
, that return a promise, which can be used to declared code split point via() => import('my-module')
. This is shown viaimports: () => import('./test-cell')
in above example, though you need to go to the demo in following link to checkDemo
https://stackblitz.com/edit/statically-aurelia?file=calendar.js
Demo with jsx
https://stackblitz.com/edit/statically-aurelia-zwqj67?file=calendar.js
Further improvement:
aurelia-dialog
already accepts a class as ViewModel in its config, so it doesn't need any tweaks. That said, we can provide an alternative version, where we only accepts classes as view model, and remove the usage of dynamically loaded view model via module string, to help tree shaking @StrahilKazlachevaurelia-router
should followaurelia-dialog
and accept a class directly atmoduleId
config. @davismjWith the two points above checked, we can build statically analyzable Aurelia apps without any special plugin / configuration. Thus should be friendly to modern bundler.
@EisenbergEffect @jdanyow @jods4
@jsobell
TODO