Skip to content
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

(recs) make rxjs systems granularly unsubscribable #329

Open
smallbraingames opened this issue Jan 7, 2023 · 0 comments
Open

(recs) make rxjs systems granularly unsubscribable #329

smallbraingames opened this issue Jan 7, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@smallbraingames
Copy link
Contributor

Currently, defineRxSystem in [recs](https://github.com/latticexyz/mud/blob/main/packages/recs/src/System.ts) does not return the rxjs Subscription object, but only registers the unsubscribe to world.registerDisposer()

This prevents the ability to granularly unsubscribe from systems, which is useful in many situations, like building a game with different game modes, for example.

Easy possible fix: Return Subscription object. Current workaround:

function defineRxSystemUnsubscribable<T>(
  world: World,
  observable$: Observable<T>,
  system: (event: T) => void
): Subscription {
  const subscription = observable$.subscribe(system);
  return subscription;
}

export function defineComponentSystemUnsubscribable<S extends Schema>(
  world: World,
  component: Component<S>,
  system: (update: ComponentUpdate<S>) => void,
  options: { runOnInit?: boolean } = { runOnInit: true }
): Subscription {
  const initial$ = options?.runOnInit
    ? from(getComponentEntities(component)).pipe(toUpdateStream(component))
    : EMPTY;
  return defineRxSystemUnsubscribable(
    world,
    concat(initial$, component.update$),
    system
  );
}
smallbraingames added a commit to smallbraingames/apes-gambit that referenced this issue Jan 7, 2023
- hack to make systems unsubscribable: latticexyz/mud#329
- rename battle royale to BR naming for clarity
- eventually... it should be easy to add a ton of minigames
smallbraingames added a commit to smallbraingames/apes-gambit that referenced this issue Jan 7, 2023
- hack to make systems unsubscribable: latticexyz/mud#329
- rename battle royale to BR naming for clarity
- eventually... it should be easy to add a ton of minigames
smallbraingames added a commit to smallbraingames/apes-gambit that referenced this issue Jan 7, 2023
- hack to make systems unsubscribable: latticexyz/mud#329
- rename battle royale to BR naming for clarity
- eventually... it should be easy to add a ton of minigames
smallbraingames added a commit to smallbraingames/apes-gambit that referenced this issue Jan 7, 2023
- hack to make systems unsubscribable: latticexyz/mud#329
- rename battle royale to BR naming for clarity
- eventually... it should be easy to add a ton of minigames
@alvrs alvrs added the enhancement New feature or request label Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants