@preact-mvc/core 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/module.js +12 -6
  2. package/package.json +1 -1
package/dist/module.js CHANGED
@@ -4,8 +4,11 @@ import { InjectorContext } from './context';
4
4
  import { installViewInterop } from './view';
5
5
  import { ownMeta } from './decorators';
6
6
  // Modules are the unit of provider scoping. A module's providers (plus those
7
- // of its imports, transitively) register into a single child Injector. The
8
- // injector tree mirrors the view tree: root injector -> AppModule injector ->
7
+ // of its imports, transitively) register into a single Injector. The
8
+ // bootstrap module registers into the ROOT injector itself — matching
9
+ // Angular, where eager module providers share the root scope — so
10
+ // providedIn: 'root' services can inject them. Only feature/lazy modules
11
+ // get child injectors: root injector (holding the app module's graph) ->
9
12
  // feature/lazy module injectors -> per-view injectors.
10
13
  export function getModuleMeta(mod) {
11
14
  return ownMeta(mod, '__module');
@@ -63,11 +66,14 @@ export function getModuleInjector(mod, parent) {
63
66
  export function bootstrap(RootModule, el) {
64
67
  installViewInterop();
65
68
  const root = new Injector(null, 'root');
66
- const appInjector = createModuleInjector(RootModule, root);
67
- const meta = getModuleMeta(RootModule);
68
- const App = meta.bootstrap?.[0];
69
+ // The bootstrapped module is eager: its providers and imports merge into
70
+ // the root injector, so providedIn: 'root' services (instantiated under
71
+ // root) can inject them — including forRoot() bundles like
72
+ // RouterModule.forRoot().
73
+ registerModule(RootModule, root, new Set());
74
+ const App = getModuleMeta(RootModule).bootstrap?.[0];
69
75
  if (!App) {
70
76
  throw new Error('Root module must declare a bootstrap component: @Module({ bootstrap: [AppView] })');
71
77
  }
72
- render(h(InjectorContext.Provider, { value: appInjector }, h(App, {})), el);
78
+ render(h(InjectorContext.Provider, { value: root }, h(App, {})), el);
73
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preact-mvc/core",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Angular-inspired modules/DI/decorators + class-based JSX views rendered by Preact + signal reactivity",
5
5
  "type": "module",
6
6
  "sideEffects": false,