Support angular signals #440
-
Which @ngneat/elf-* package(s) are relevant/releated to the feature request?store DescriptionRecently, angular team announced new reactive primitive - signal. Is there any chances you could integrate them in your library? Proposed solutionAlternatives consideredDo you want to create a pull request?No |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 14 replies
-
Signals seem to be the next major state mechanic in Angular, it would be great to have "native" support in elf. |
Beta Was this translation helpful? Give feedback.
-
What do you expect to see? |
Beta Was this translation helpful? Give feedback.
-
TBH, I don't know if we could do this. This library is framework agnostic. |
Beta Was this translation helpful? Give feedback.
-
EDIT: ↓ update in my reply below ↓ This is an easy fix: just convert the store state to a signal and build computed properties from there. See the example below: in my case, I'm using the repository pattern using an OOP approach: import { toSignal } from '@angular/core/rxjs-interop';
import { createStore, withProps, select } from '@ngneat/elf';
type User {
name: string;
};
type AuthProps = {
token: string;
user: User;
};
const store = createStore(
{ name: 'auth' },
withProps<AuthProps>({
token: '',
user: null,
}),
);
export class FieldsRepository {
// convert the main observable to a signal
private state = toSignal(store.pipe(select((state) => state)));
// use computed values instead of rxjs's pipes
token = computed(() => this.state().token);
user = computed(() => this.state().user);
// typical setters, no differences here
setToken(token: AuthProps['token']) {
store.update(setProp('token', token));
}
setUser(user: AuthProps['user']) {
store.update(setProp('user', user));
}
} |
Beta Was this translation helpful? Give feedback.
This library is based on observables and operators. We can't do what you suggest. The ngrx team created a new library. It's writing it from scratch or using the
toSignal
function.