RxJS.Observable?

Hi all!

Are there any plans to replace Babylon.Obervable by RxJS.Observable?

  • adhere to a industry standard
  • use cool RxJS features (delay, debounce, map,…)
1 Like

Hey!

no no plan :slight_smile: We do not take external dependencies

But it should be straightforward from a user standpoint to wrap them

1 Like

For anyone wandering how to wrap BABYLON observable into RxJS one, here is example:

export interface BeforeRenderEvent {
  data: Scene;
  state: EventState
}

export function makeBeforeRenderObservable(scene: Scene): Observable<BeforeRenderEvent> {
  return new Observable<BeforeRenderEvent>((subscriber) => {
    const notifier = scene.onBeforeRenderObservable.add((data: Scene, state: EventState) => {
      subscriber.next({data, state});
    });
    return () => scene.onBeforeRenderObservable.remove(notifier);
  });
}

then in your code you can use it like

makeBeforeRenderObservable(scene).pipe(
    throttleTime(1000),
    tap((event) => console.log('before render evt', event)),
    // ... do rx magic
)
3 Likes