Skip to content

Commit

Permalink
Update module provider behavior (#913)
Browse files Browse the repository at this point in the history
* fix(module): change behavior of `BaseModuleProvider`

* fix(module-navigation): move functionality from init to constructor
  • Loading branch information
odinr authored May 31, 2023
1 parent 76b30c1 commit 83ee5ab
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .changeset/happy-eyes-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@equinor/fusion-framework-module-navigation': patch
---

__Change init of NavigationProvider__

moved the init to constructor
15 changes: 15 additions & 0 deletions .changeset/old-planets-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@equinor/fusion-framework-module': patch
---

__Change base behavior of BaseModuleProvider__

because of weird limitations of JavaScript, private fields are not accessible until all constructors are initialized (from ancestor to current child).
This causes the `abstract` init function could not access private members when overridden.

* __removed__ `init` from `BaseModuleProvider`
- _this is a breaking change, but not yet published, yet the `patch` version_
- https://github.com/equinor/fusion-framework/blob/43854d9538ade189483c43e04b52eff7e1aa3b0c/packages/modules/module/src/lib/provider/BaseModuleProvider.ts#L31
* __added__ `provider` sub-scope for package

> The usage when extending `BaseModuleProvider` is not as 😘, but now works
15 changes: 13 additions & 2 deletions packages/modules/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@
"description": "",
"main": "dist/esm/index.js",
"exports": {
".": "./dist/esm/index.js"
".": "./dist/esm/index.js",
"./provider": "./dist/esm/lib/provider/index.js"
},
"types": "index.d.ts",
"typesVersions": {
">=4.2": {
"*": [
"dist/types/*"
],
"provider": [
"dist/types/lib/provider/index"
]
}
},
"types": "dist/types/index.d.ts",
"scripts": {
"build": "tsc -b",
"prepack": "yarn build"
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/module/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './provider';
export { IModuleProvider } from './provider';
export { SemanticVersion } from './semantic-version';
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ export abstract class BaseModuleProvider<TConfig = unknown> implements IModulePr
}

constructor(args: BaseModuleProviderCtorArgs<TConfig>) {
this.#version = new SemanticVersion(args.version);
const { version } = args;
this.#version = new SemanticVersion(version);
this.#subscriptions = new Subscription();
this._init(args.config);
}

protected abstract _init(config: TConfig): void;

/**
* Add teardown down function, which is called on dispose.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/module/src/lib/provider/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export type { IModuleProvider } from './IModuleProvider';
export { BaseModuleProvider } from './BaseModuleProvider';
export { BaseModuleProvider, BaseModuleProviderCtorArgs } from './BaseModuleProvider';
7 changes: 6 additions & 1 deletion packages/modules/module/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"outDir": "dist/esm",
"rootDir": "src",
"declarationDir": "./dist/types",
"baseUrl": "src"
"baseUrl": "src",
"paths": {
"@equinor/fusion-framework-module/provider": [
"lib/provider"
]
}
},
"include": [
"src/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { AgnosticRouteObject, createRouter, Path, To } from '@remix-run/router';

import { filter, map } from 'rxjs/operators';

import { BaseModuleProvider } from '@equinor/fusion-framework-module';
import {
BaseModuleProvider,
type BaseModuleProviderCtorArgs,
} from '@equinor/fusion-framework-module/provider';

import { INavigationProvider } from './INavigationProvider';

Expand All @@ -15,7 +18,7 @@ export class NavigationProvider
extends BaseModuleProvider<INavigationConfigurator>
implements INavigationProvider
{
#navigator!: INavigator;
#navigator: INavigator;
#basePathname?: string;

public get state$() {
Expand All @@ -40,8 +43,10 @@ export class NavigationProvider
return this._localizePath(this.navigator.location);
}

protected _init(config: INavigationConfigurator): void {
const { basename, history } = config;
constructor(args: BaseModuleProviderCtorArgs<INavigationConfigurator>) {
super(args);

const { basename, history } = args.config;

this.#basePathname = basename;

Expand Down

0 comments on commit 83ee5ab

Please sign in to comment.