ngxtension / ngxtension-platform

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

[feature request] applyRxjsOperator for signal #500

Open MillerSvt opened 2 weeks ago

MillerSvt commented 2 weeks ago

Hi. Sometimes we need to add various rxjs operators to signals (for example, debounceTime), and we have to do this through a double conversion first to the stream, then to the signal back. I suggest adding a utility for this.

Expected API:

const result = applyRxJSOperator(source, debounceTime(1000));
const result = applyRxJSOperator(source, pipe(debounceTime(1000), map(i => i + 1)));

Draft implementation:

function applyRxJSOperator(signal: Signal, operator: OperatorFunction): Signal {
  const streamFromSignal = toObservable(signal);

  return toSignal(streamFromSignal.pipe(operator));
}

If you support the idea, I can do it...