Skip to content
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

Update angular, primeng, convert to standalone, inject context #28

Closed
wants to merge 16 commits into from

Conversation

theNEXlevel
Copy link

@theNEXlevel theNEXlevel commented Jun 11, 2023

  • Updated to the latest primeng version
  • Updated to the latest rxjs version
  • Updated Angular to 16
  • Converted entire application to standalone
  • Converted all files to use inject instead of constructor injection
  • Converted all services to be provided in root

@@ -65,7 +75,7 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {

key: string = "";

constructor(public layoutService: LayoutService, private cd: ChangeDetectorRef, public router: Router, private menuService: MenuService) {
constructor() {
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need variable menuSourceSubscription to keep sub ref in order to unsub.
Angular core have new way of unsub using -> https://v16.angular.io/api/core/DestroyRef

Define variable
private destroyRef = inject(DestroyRef);
and on Observable use
.pipe(takeUntilDestroyed(this.destroyRef))

Like so:

this.menuService.menuSource$
      .pipe(takeUntilDestroyed(this.destroyRef))
      .subscribe(value => {
        Promise.resolve(null).then(() => {
          if (value.routeEvent) {
            this.active = (value.key === this.key || value.key.startsWith(this.key + '-'));
          } else {
            if (value.key !== this.key && !value.key.startsWith(this.key + '-')) {
              this.active = false;
            }
          }
        });
      });

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do use this approach in my personal projects but because it's still dev preview I don't think it's good to put into a component library / template like this one.

@@ -65,7 +75,7 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {

key: string = "";

constructor(public layoutService: LayoutService, private cd: ChangeDetectorRef, public router: Router, private menuService: MenuService) {
constructor() {
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
Promise.resolve(null).then(() => {
if (value.routeEvent) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.active = (value.key === this.key || value.key.startsWith(this.key + '-')) ? true : false;

this can be simplified

(value.key === this.key || value.key.startsWith(this.key + '-')) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants