Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alcfeoh/ngx-signalify

A small library to convert RxJs Observables into Angular Signals
https://github.com/alcfeoh/ngx-signalify

angular observables rxjs signals

Last synced: about 17 hours ago
JSON representation

A small library to convert RxJs Observables into Angular Signals

Awesome Lists containing this project

README

        

# NgxSignalify (for Angular)

To install: `npm install ngx-signalify`

Then, turn any `Observable` into a `SignalState` object with information about:
- Are we still loading data?
- What's the current data?
- Did any error happen?

Example in your component Typescript code:
```javascript
import { signalify } from 'ngx-signalify';

http = inject(HttpClient);
comments = signalify(this.http.get(URL));
```
HTML template:
```angular17html
@if(comments.loading()) {
Loading comments...
} @else {
We have {{comments.data()?.length}} comments
}
@if (comments.error()) {
Something went wrong!
}
```

The `SignalState` object has 3 properties - `loading`, `data`, and `error` - all Angular signals:
```typescript
export interface SignalState {
loading: Signal;
data: Signal;
error: Signal;
}
```

And that's it! You can `signalify` any `Observable` into a `SignalState` object.

Live example: https://stackblitz.com/edit/ngx-signalify-demo