# @mmuscat/angular-auto

> Auto decorators for Angular

Latest version **0.1.3** (published 2022-07-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mmuscat/angular-auto
pnpm add @mmuscat/angular-auto
yarn add @mmuscat/angular-auto
bun add @mmuscat/angular-auto
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2022-07-09 |
| First published | 2022-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 72.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | mmuscat |
| Keywords | Angular, experimental, decorator, composition, api, lifecycle, hooks, subscribe, unsubscribe, auto, automatic, observable, rxjs |

## Links

- npm: https://www.npmjs.com/package/@mmuscat/angular-auto
- Repository: https://github.com/mmuscat/angular-auto
- Homepage: https://github.com/mmuscat/angular-auto#readme
- Issues: https://github.com/mmuscat/angular-auto/issues
- npm.io page: https://npm.io/package/@mmuscat/angular-auto

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2022-07-09
- 0.1.2 — 2022-07-08
- 0.1.1 — 2022-07-06
- 0.1.0 — 2022-07-06
- 0.0.6 — 2022-07-06
- 0.0.5 — 2022-07-04
- 0.0.4 — 2022-07-04
- 0.0.3 — 2022-07-03
- 0.0.2 — 2022-07-03
- 0.0.1 — 2022-07-03

## README

# Auto decorators for Angular

```ts
@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!")
   }
}
```

```ts
@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.

---
_Source: https://npm.io/package/@mmuscat/angular-auto · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
