- Why static? Why $ dollar sign?
- How come you didn’t use @bindable but used “resource = { bindables:” never seen that before (and why is it that I don’t see this way anywhere)?
It’s announced here. https://aurelia.io/blog/2018/06/24/aurelia-release-notes-june-2018
Traditionally, there’s only one way to register a resource or add a plugin or add a feature: via module path (or module Id string) pointing to the resource/plugin/feature. This doesn’t play well with static code analysis, and part of the reason why it took huge amount of effort to do first webpack plugin. We can refer to this way of adding resource as “dynamic”, as in “not known at build time”:
export class App {
configureRouter(config) {
config.map([
{ route: 'home', moduleId: 'pages/home' },
{ route: 'dashboard', moduleId: 'pages/dashboard' }
])
}
}
There is no way for tooling to know that 'pages/home'
refers to the file at 'pages/home'
without a plugin or special implementation of bundler like Aurelia-CLI.
Since not all applications need this dynamic capability, it’s desirable to refer to resources via their constructor directly, instead of the module id pointing to where they are, that feature was developed to better support this scenario. Doing it this way helps tooling “see” & “build” dependency graph correctly at build time, aka static, naturally. This enables easier tooling integration, as there is no need for special plugin to teach tooling when a dependency of a module needs to be pulled into the final bundle (like PLATFORM.moduleName
with webpack).
While developing this feature, I saw that it enables tooling free capability, so it seemed it would be better to have a way to declare bindables or resource configurations easily without decorator, as decorator seemed to be in neverland because of ECMAScript class field proposal. Thus, $resource
and $view
was in, $
is a breaking chance avoidance move, a compromise made to avoid major version bump, without breaking existing app, as resource
and view
(or plain field names generally) were pointed out to be too risky.
The final result of this is aurelia-script
as announced at https://aurelia.io/blog/2018/11/04/aurelia-2018-q3-report, and soon something like following (PR at WIP feat(router): ability to use classe/module as view model by bigopon · Pull Request #624 · aurelia/router · GitHub , @davismj and I are working on it) :
export class App {
configureRouter(config) {
config.map([
{ route: 'home', viewModel: () => import('pages/home') },
{ route: 'dashboard', viewModel: () => import('pages/dashboard') },
]);
}
}
Note that native dynamic import API (or import('pages/...')
) is naturally understood by probably 100% of tooling, enabling code splitting by default, while still helps with static code analysis.
- why “globalResources” shouldn’t it be “feature()” or “plugin()” ?
.feature()
, .plugin()
when used with a module path, will be resolved to underlying exported configure
function, which will eventually call .globalResources()
normally, so if there is no special setup needed, it can be just the direct registration.