-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] BehaviorSubject to Signals migration #504
Comments
And convert |
Yes, sorry. Added! |
Hi, something is coming 🙌 Let's wait a little bit more 😬 |
Do you mean you are working on it, that Angular's core team is working on it, or that you think it's premature to add such a feature now? |
I've been working on a prototype for myself to do these kinds of migration, but nothing ready yet. |
Cool! I also thought that a next step could be converting something like that: combineLatest({
a: toObservable(this.a),
b: toObservable(this.b),
})
.pipe(
map(({a, b}) => this.a() + this.b()),
distinctUntilChanged(), // ... and other operators that don't matter with signals like share etc
); to computed(() => this.a() + this.b()); Might be harder than I think but it feels like it could be possible. |
I would argue that this could be https://stackblitz.com/edit/stackblitz-starters-qnm6xx?file=src%2Fmain.ts (look at console to see difrence) With pairWise we would get completle diffrent values |
Yeah they behave differently. Though I feel like in practice if you use a |
In the spirit of writing migration scripts to modernize Angular code, I want to propose the following script. Let me know if you think this is something that could fit the library.
The assumption here that everything that a
BehaviorSubject
is used for, a signal can be used instead, and I think it is possible to write a (relatively) robust script to do that migration. The script will:new BehaviorSubject
withsignal
, while keeping any used generics / inferred types..next
with.set
$
myValue$.value
usages tomyValue()
myValue$
with `toObservable(myValue)myValue
as a signal andmyValue$
as a stream. In that case, if there is no$
as a postfix, we'll have to add it.The text was updated successfully, but these errors were encountered: