ngxtension / ngxtension-platform

Utilities for Angular
https://ngxtension.netlify.app/
MIT License
586 stars 86 forks source link

[feature request] BehaviorSubject to Signals migration #504

Open ShacharHarshuv opened 5 days ago

ShacharHarshuv commented 5 days ago

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:

jdegand commented 4 days ago

And convert .next to .set?

ShacharHarshuv commented 4 days ago

Yes, sorry. Added!

eneajaho commented 4 days ago

Hi, something is coming 🙌

Let's wait a little bit more 😬

ShacharHarshuv commented 4 days ago

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?

eneajaho commented 4 days ago

I've been working on a prototype for myself to do these kinds of migration, but nothing ready yet.

ShacharHarshuv commented 4 days ago

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.