JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q30783F
  • License MIT

Auto decorators for Angular

Package Exports

  • @mmuscat/angular-auto
  • @mmuscat/angular-auto/package.json

Readme

Auto decorators for Angular

@Auto()
@Component({
   template: `{{ count }}`,
   changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MyComponent {
   @Input()
   count = 0;

   object = new Resource()

   @Subscribe()
   autoIncrement = interval(1000).pipe(
      tap((value) => this.count = value + 1)
   );

   @Unsubscribe()
   subscription = new Subscription();

   ngOnInit() {
      console.log("I am called!")
   }
}
@Auto()
export class Resource {
   private http = inject(HttpClient)

   @Check()
   value

   ngOnInit() {
      console.log("I am also called!")
   }

   fetch(params) {
      this.http.get(endpoint, params)
         .subscribe((value) => this.value = value)
   }
}

Decorators

Auto

Automatically compose the decorated class. Lifecycle hooks cascade to any Auto decorated object created inside a field initializer or class constructor.

Check

Automatically check the decorated value during ngDoCheck and mark the view dirty when it changes. Use with OnPush change detection strategy.

Subscribe

Automatically subscribe to the decorated observable during ngDoCheck and mark the view dirty whenever a value is emitted. Use with OnPush change detection strategy. Assigning new values will automatically cancel the previous subscription. Subscriptions are automatically unsubscribed when the context is destroyed.

Unsubscribe

Automatically unsubscribe the decorated subject or subscription during ngOnDestroy. You must still manually call complete and/or unsubscribe before assigning a new value to prevent memory leaks.