Skip to content

Commit 96c5946

Browse files
committed
chore(lib): migrate to signals inputs
1 parent c7691e2 commit 96c5946

File tree

6 files changed

+87
-66
lines changed

6 files changed

+87
-66
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"lint": "ng lint",
1010
"test": "ng lint && npm run format:test && npm run test:lib",
1111
"test:lib": "node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js --config projects/elements/jest.config.ts",
12-
"watch": "ng test --watch",
1312
"prebuild": "npm run build:copy-changelog",
1413
"build": "ng build elements-demo && ng build elements",
1514
"postbuild": "replace \"onFetch.*\\{\" \"onFetch(event) { if (event.request.url.indexOf('unpkg.com') > -1) { return; }\" ./dist/elements-demo/browser/ngsw-worker.js",

projects/elements-demo/src/assets/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [19.0.0](https://github.com/angular-extensions/elements/compare/v18.2.1...v19.0.0) (2025-04-28)
6+
7+
### ⚠ BREAKING CHANGES
8+
9+
- **lib:** Angular 19
10+
11+
* cleanups, control flow migration, scss import migration
12+
* jest setup migration
13+
14+
### Features
15+
16+
- **lib:** upgrade to Angular 19 ([67980dd](https://github.com/angular-extensions/elements/commit/67980ddbee48922441017dbdbbc248130788e0ec))
17+
518
### [18.2.1](https://github.com/angular-extensions/elements/compare/v18.2.0...v18.2.1) (2024-09-02)
619

720
### Bug Fixes

projects/elements/jest.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const jestConfig: Config = {
99
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
1010
transform: {
1111
'^.+\\.(ts|js|html)$': [
12-
'ts-jest',
12+
'jest-preset-angular',
1313
{
1414
tsconfig: '<rootDir>/tsconfig.spec.json',
1515
stringifyContentPathRegex: '\\.(html|svg)$',
@@ -18,7 +18,6 @@ const jestConfig: Config = {
1818
],
1919
},
2020
moduleNameMapper: {
21-
tslib: 'tslib/tslib.es6.js',
2221
'^rxjs(/operators$)?$':
2322
'<rootDir>../../node_modules/rxjs/dist/bundles/rxjs.umd.js',
2423
'^rxjs/testing$':

projects/elements/src/lib/lazy-elements/lazy-element-dynamic/lazy-element-dynamic.directive.ts

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import {
44
Directive,
55
EmbeddedViewRef,
66
inject,
7-
Input,
87
OnInit,
98
PLATFORM_ID,
109
Renderer2,
1110
TemplateRef,
1211
ViewContainerRef,
12+
input,
1313
} from '@angular/core';
1414
import { DOCUMENT, isPlatformServer } from '@angular/common';
1515
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
@@ -25,18 +25,24 @@ const LOG_PREFIX = '@angular-extensions/elements';
2525
selector: '[axLazyElementDynamic]',
2626
})
2727
export class LazyElementDynamicDirective implements OnInit {
28-
@Input('axLazyElementDynamic') tag: string | null = null;
29-
@Input('axLazyElementDynamicUrl') url: string | null = null;
30-
@Input('axLazyElementDynamicLoadingTemplate')
31-
loadingTemplateRef: TemplateRef<any> | null = null;
32-
@Input('axLazyElementDynamicErrorTemplate')
33-
errorTemplateRef: TemplateRef<any> | null = null;
34-
@Input('axLazyElementDynamicModule') isModule = false;
35-
@Input('axLazyElementDynamicImportMap') importMap = false;
36-
@Input('axLazyElementLoadingSuccess') loadingSuccess?: () => void;
37-
@Input('axLazyElementLoadingError') loadingError?: (
38-
error: ErrorEvent,
39-
) => void;
28+
readonly tag = input<string | null>(null, { alias: 'axLazyElementDynamic' });
29+
readonly url = input<string | null>(null, {
30+
alias: 'axLazyElementDynamicUrl',
31+
});
32+
readonly loadingTemplateRef = input<TemplateRef<any> | null>(null, {
33+
alias: 'axLazyElementDynamicLoadingTemplate',
34+
});
35+
readonly errorTemplateRef = input<TemplateRef<any> | null>(null, {
36+
alias: 'axLazyElementDynamicErrorTemplate',
37+
});
38+
readonly isModule = input(false, { alias: 'axLazyElementDynamicModule' });
39+
readonly importMap = input(false, { alias: 'axLazyElementDynamicImportMap' });
40+
readonly loadingSuccess = input<() => void>(undefined, {
41+
alias: 'axLazyElementLoadingSuccess',
42+
});
43+
readonly loadingError = input<(error: ErrorEvent) => void>(undefined, {
44+
alias: 'axLazyElementLoadingError',
45+
});
4046

4147
#viewRef: EmbeddedViewRef<any> | null = null;
4248

@@ -58,15 +64,16 @@ export class LazyElementDynamicDirective implements OnInit {
5864
return;
5965
}
6066

67+
const tagValue = this.tag();
6168
if (ngDevMode) {
62-
if (!this.tag || this.tag.length === 0 || !this.tag.includes('-')) {
69+
if (!tagValue || tagValue.length === 0 || !tagValue.includes('-')) {
6370
throw new Error(
64-
`${LOG_PREFIX} - Valid tag has to be specified when using *axLazyElementDynamic directive (use *axLazyElementDynamic="'some-tag'"), got: "${this.tag}"`,
71+
`${LOG_PREFIX} - Valid tag has to be specified when using *axLazyElementDynamic directive (use *axLazyElementDynamic="'some-tag'"), got: "${tagValue}"`,
6572
);
6673
}
6774
}
6875

69-
const tag = this.tag!;
76+
const tag = tagValue!;
7077

7178
const elementConfig =
7279
this.#elementsLoaderService.getElementConfig(tag) ||
@@ -75,18 +82,19 @@ export class LazyElementDynamicDirective implements OnInit {
7582
const loadingComponent =
7683
elementConfig.loadingComponent || options.loadingComponent;
7784

78-
if (this.loadingTemplateRef) {
79-
this.#vcr.createEmbeddedView(this.loadingTemplateRef);
85+
const loadingTemplateRef = this.loadingTemplateRef();
86+
if (loadingTemplateRef) {
87+
this.#vcr.createEmbeddedView(loadingTemplateRef);
8088
} else if (loadingComponent) {
8189
this.#vcr.createComponent(loadingComponent);
8290
}
8391

8492
const loadElement$ = from(
8593
this.#elementsLoaderService.loadElement(
86-
this.url,
94+
this.url(),
8795
tag,
88-
this.isModule,
89-
this.importMap,
96+
this.isModule(),
97+
this.importMap(),
9098
elementConfig?.hooks,
9199
),
92100
);
@@ -98,7 +106,7 @@ export class LazyElementDynamicDirective implements OnInit {
98106
)
99107
.subscribe({
100108
next: () => {
101-
this.loadingSuccess?.();
109+
this.loadingSuccess()?.();
102110
this.#vcr.clear();
103111
const originalCreateElement = this.#renderer.createElement;
104112
this.#renderer.createElement = (name: string, namespace: string) => {
@@ -112,19 +120,20 @@ export class LazyElementDynamicDirective implements OnInit {
112120
this.#cdr.markForCheck();
113121
},
114122
error: (error) => {
115-
this.loadingError?.(error);
123+
this.loadingError()?.(error);
116124
const errorComponent =
117125
elementConfig.errorComponent || options.errorComponent;
118126
this.#vcr.clear();
119-
if (this.errorTemplateRef) {
120-
this.#vcr.createEmbeddedView(this.errorTemplateRef);
127+
const errorTemplateRef = this.errorTemplateRef();
128+
if (errorTemplateRef) {
129+
this.#vcr.createEmbeddedView(errorTemplateRef);
121130
this.#cdr.markForCheck();
122131
} else if (errorComponent) {
123132
this.#vcr.createComponent(errorComponent);
124133
this.#cdr.markForCheck();
125-
} else if (ngDevMode && !this.loadingError) {
134+
} else if (ngDevMode && !this.loadingError()) {
126135
console.error(
127-
`${LOG_PREFIX} - Loading of element <${this.tag}> failed, please provide <ng-template #error>Loading failed...</ng-template> and reference it in *axLazyElementDynamic="errorTemplate: error" to display customized error message in place of element\n\n`,
136+
`${LOG_PREFIX} - Loading of element <${this.tag()}> failed, please provide <ng-template #error>Loading failed...</ng-template> and reference it in *axLazyElementDynamic="errorTemplate: error" to display customized error message in place of element\n\n`,
128137
error,
129138
);
130139
}

projects/elements/src/lib/lazy-elements/lazy-element/lazy-element.directive.ts

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ import {
44
Directive,
55
EmbeddedViewRef,
66
inject,
7-
Input,
8-
OnChanges,
97
OnInit,
108
PLATFORM_ID,
11-
SimpleChanges,
129
TemplateRef,
1310
ViewContainerRef,
11+
input,
1412
} from '@angular/core';
1513
import { isPlatformServer } from '@angular/common';
16-
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
14+
import {
15+
takeUntilDestroyed,
16+
toObservable,
17+
toSignal,
18+
} from '@angular/core/rxjs-interop';
1719
import {
1820
animationFrameScheduler,
1921
BehaviorSubject,
@@ -35,34 +37,34 @@ const LOG_PREFIX = '@angular-extensions/elements';
3537
standalone: true,
3638
selector: '[axLazyElement]',
3739
})
38-
export class LazyElementDirective implements OnInit, OnChanges {
40+
export class LazyElementDirective implements OnInit {
3941
readonly #platformId = inject(PLATFORM_ID);
4042
readonly #destroyRef = inject(DestroyRef);
4143
readonly #vcr = inject(ViewContainerRef);
4244
readonly #cdr = inject(ChangeDetectorRef);
4345
readonly #template = inject(TemplateRef<any>);
4446
readonly #elementsLoaderService = inject(LazyElementsLoaderService);
4547

46-
@Input('axLazyElement') url: string | null = null;
47-
@Input('axLazyElementLoadingTemplate')
48-
loadingTemplateRef: TemplateRef<any> | null = null;
49-
@Input('axLazyElementErrorTemplate')
50-
errorTemplateRef: TemplateRef<any> | null = null;
51-
@Input('axLazyElementModule') isModule?: boolean;
52-
@Input('axLazyElementImportMap') importMap = false;
53-
@Input('axLazyElementLoadingSuccess') loadingSuccess?: () => void;
54-
@Input('axLazyElementLoadingError') loadingError?: (
55-
error: ErrorEvent,
56-
) => void;
48+
readonly url = input<string | null>(null, { alias: 'axLazyElement' });
49+
readonly loadingTemplateRef = input<TemplateRef<any> | null>(null, {
50+
alias: 'axLazyElementLoadingTemplate',
51+
});
52+
readonly errorTemplateRef = input<TemplateRef<any> | null>(null, {
53+
alias: 'axLazyElementErrorTemplate',
54+
});
55+
readonly isModule = input<boolean>(undefined, {
56+
alias: 'axLazyElementModule',
57+
});
58+
readonly importMap = input(false, { alias: 'axLazyElementImportMap' });
59+
readonly loadingSuccess = input<() => void>(undefined, {
60+
alias: 'axLazyElementLoadingSuccess',
61+
});
62+
readonly loadingError = input<(error: ErrorEvent) => void>(undefined, {
63+
alias: 'axLazyElementLoadingError',
64+
});
5765

5866
#viewRef: EmbeddedViewRef<any> | null = null;
59-
#url$ = new BehaviorSubject<string | null>(null);
60-
61-
ngOnChanges(changes: SimpleChanges): void {
62-
if (changes.url) {
63-
this.#url$.next(this.url);
64-
}
65-
}
67+
#url$ = toObservable(this.url);
6668

6769
ngOnInit() {
6870
// There's no sense to execute the below logic on the Node.js side since the JavaScript
@@ -104,8 +106,9 @@ export class LazyElementDirective implements OnInit, OnChanges {
104106
// The `animationFrameScheduler` is used to prevent the frame drop.
105107
debounceTime(0, animationFrameScheduler),
106108
switchMap((url) => {
107-
if (this.loadingTemplateRef) {
108-
this.#vcr.createEmbeddedView(this.loadingTemplateRef);
109+
const loadingTemplateRef = this.loadingTemplateRef();
110+
if (loadingTemplateRef) {
111+
this.#vcr.createEmbeddedView(loadingTemplateRef);
109112
} else if (loadingComponent) {
110113
this.#vcr.createComponent(loadingComponent);
111114
}
@@ -114,23 +117,24 @@ export class LazyElementDirective implements OnInit, OnChanges {
114117
this.#elementsLoaderService.loadElement(
115118
url,
116119
elementTag,
117-
this.isModule,
118-
this.importMap,
120+
this.isModule(),
121+
this.importMap(),
119122
elementConfig?.hooks,
120123
),
121124
).pipe(
122125
catchError((error) => {
123-
this.loadingError?.(error);
126+
this.loadingError()?.(error);
124127
this.#vcr.clear();
125128
const errorComponent =
126129
elementConfig.errorComponent || options.errorComponent;
127-
if (this.errorTemplateRef) {
128-
this.#vcr.createEmbeddedView(this.errorTemplateRef);
130+
const errorTemplateRef = this.errorTemplateRef();
131+
if (errorTemplateRef) {
132+
this.#vcr.createEmbeddedView(errorTemplateRef);
129133
this.#cdr.markForCheck();
130134
} else if (errorComponent) {
131135
this.#vcr.createComponent(errorComponent);
132136
this.#cdr.markForCheck();
133-
} else if (ngDevMode && !this.loadingError) {
137+
} else if (ngDevMode && !this.loadingError()) {
134138
console.error(
135139
`${LOG_PREFIX} - Loading of element <${elementTag}> failed, please provide <ng-template #error>Loading failed...</ng-template> and reference it in *axLazyElement="errorTemplate: error" to display customized error message in place of element`,
136140
);
@@ -139,7 +143,7 @@ export class LazyElementDirective implements OnInit, OnChanges {
139143
}),
140144
);
141145
}),
142-
tap(() => this.loadingSuccess?.()),
146+
tap(() => this.loadingSuccess()?.()),
143147
mergeMap(() => customElements.whenDefined(elementTag)),
144148
takeUntilDestroyed(this.#destroyRef),
145149
)

projects/elements/tsconfig.spec.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "../../out-tsc/spec",
5-
"module": "es2020",
6-
"esModuleInterop": true,
7-
"emitDecoratorMetadata": true,
8-
"allowJs": true,
5+
"module": "es2022",
96
"types": ["jest", "node"]
107
},
118
"files": [],

0 commit comments

Comments
 (0)