wondering if babylon has anything like this ^ or if I can use this together with babylon’s observables
I have two managers, A and B, and action 1 that should be done after manager A is initialized, action 2 that should be done after B is initialized, and 3 that should be done only after A and B are initialized. Is observables the way to go here, and if so, how can I wait for multiple? thanks!
Yes, just daisy-chain them and/or have a global state management service. For any moderately complex application, you’re best off with a global state manager, but here’s a simple daisy-chain approach that matches your description:
// ManagerA.ts
this.isInitialized = true;
onInitializedObservable.notifyObservers(true);
// ManagerB.ts
managerA.onInitializedObservable.add(() => {
this.executeAction1();
this.isInitialized = true;
onInitializedObservable.notifyObservers(true);
});
// ConsumingClass.ts
managerB.onInitializedObservable.add(() => {
this.executeAction2();
this.isInitialized = true;
onInitializedObservable.notifyObservers(true);
// ManagerA and ManagerB are initialized, so OK to execute action 3
this.executeAction3();
});