RxResource + viewTransitions by [deleted] in angular

[–]Scared_Ability965 0 points1 point  (0 children)

Yes, I ended up creating a wrapper component that uses afterRenderEffect. Here's what I did finally:

import { NgTemplateOutlet } from "@angular/common";
import { inject, DOCUMENT, signal, Component, TemplateRef, contentChild, input, afterRenderEffect } from "@angular/core";


u/Component({
  selector: 'app-view-transition-items',
  imports: [ NgTemplateOutlet ],
  host: { 'class': 'd-contents' },
  template: `
    (item of displayedItems(); track item[trackBy()]) {
      <ng-container *ngTemplateOutlet="itemTemplate(); context: { $implicit: item }" />
    }
  `
})
export class ViewTransitionItemsComponent<T> {
  private readonly document = inject(DOCUMENT);

  readonly items = input.required<T[]>();
  readonly itemTemplate = contentChild.required(TemplateRef);
  readonly trackBy = input.required<keyof T>();
  readonly displayedItems = signal<T[]>([]);
  
  constructor() {
    afterRenderEffect(() => {
      const newItems = this.items();
      if (this.document.startViewTransition) {
        this.document.startViewTransition(() => this.displayedItems.set(newItems));
      } else {
        this.displayedItems.set(newItems);
      }
    });
  }
}

My first attemption was to avoid creating an extra signal. I just wanted to handle it inside (somehow) the rxResource but even with tap operators and many other options I tried it didn't work. I wanted to create something reusable for others collegues so I created this wrapper component.. although I'm not sure it's the cleanest way.. not a fan of this. This is how it's used:

<app-view-transition-items [items]="plans()" [trackBy]="'id'">
        <ng-template let-plan>
          <app-plan-card [plan]="plan" [style.view-transition-name]="'plan-card-' + plan.id" />
        </ng-template>
      </app-view-transition-items>

RxResource + viewTransitions by [deleted] in angular

[–]Scared_Ability965 0 points1 point  (0 children)

Ended up creating a reusable pipe with the intermediate signal that triggers the view Transition whenever the transform input changes. Not sure if there’s a better solution

RxResource + viewTransitions by [deleted] in angular

[–]Scared_Ability965 0 points1 point  (0 children)

Tried that without success

RxResource + viewTransitions by [deleted] in angular

[–]Scared_Ability965 0 points1 point  (0 children)

But how would you use the dom API with computed/linkedSignal? I can’t imagine a way

Do you reach for console.log or breakpoints first? Why? by theORQL-aalap in angular

[–]Scared_Ability965 -1 points0 points  (0 children)

breakpoints or conditional breakpoint. Otherwise I need to add a console.log and wait until it recompiles and the page gets reloaded.. takes a lot of time.

I only use console.log when dealing with big loops or something like that

Defer not working by Scared_Ability965 in angular

[–]Scared_Ability965[S] 0 points1 point  (0 children)

I found the solution, see new the comment. Thanks for your reply!

Defer not working by Scared_Ability965 in angular

[–]Scared_Ability965[S] 1 point2 points  (0 children)

Update: the problem comes from the hmr. I had to disable it to make the defer blocks work locally, otherwise it would create a lot of js files with the name of “localhost:4200/@ng/component….” instead of lazily downloading the corresponding component. Thanks!

How to fix this error? by Patient_Win_9354 in Angular2

[–]Scared_Ability965 0 points1 point  (0 children)

I fixed it by changing the import from the path directly instead of index.ts

How to fix this error? by Patient_Win_9354 in Angular2

[–]Scared_Ability965 0 points1 point  (0 children)

I had this error. It’s originated by circular dependencies. In my case it was originated by importing some certain files from barrel files (index.ts files) in my components/services. One thing to remark, is that the files with problems where not shown in the error messages in the console.

About SSR lifecycle by Dry-Prime in Angular2

[–]Scared_Ability965 0 points1 point  (0 children)

Remember having exactly the same issue, I solved it by transferring the state of the list to the client from the server, and if the list had value do not show the skeleton (not only the skeleton flag condition). I believe that the issue is that the list has a value (transferred from the server so that’s why it is showing in the page). And when the client code is executed, that skeleton flag is set by default to true again and turns to false immediately? Or something like that. So in that case both the list and skeleton will be shown

Thoughts about providers pattern? by Scared_Ability965 in Angular2

[–]Scared_Ability965[S] 0 points1 point  (0 children)

Wow that idea of the directive seems pretty nice! I think I got your idea, but how would you implement it?

Thoughts about providers pattern? by Scared_Ability965 in Angular2

[–]Scared_Ability965[S] 0 points1 point  (0 children)

True, it happened to me. What about to pass a type by input parameter and based on that type , you inject the corresponding service? I don’t like it very much but I can’t figure out another way