hmans / miniplex

A 👩‍💻 developer-friendly entity management system for 🕹 games and similarly demanding applications, based on 🛠 ECS architecture.
MIT License
854 stars 39 forks source link

Offer bound `ECS.useEntities(world => bucket)` API #267

Open hmans opened 1 year ago

hmans commented 1 year ago

Have createReactAPI return a bound version of useEntities whose single argument is either a bucket, or a function returning a bucket. When the function form is used, a reference to the world the hook is bound to is passed into that function's first argument.

So instead of this:

import { ECS } from "./state"

const Asteroids = () => {
  const asteroids = useEntities(ECS.world.with("asteroid"))
  return <ECS.Entities in={asteroids} />
}

you'd now do this:

import { ECS } from "./state"

const Asteroids = () => {
  const asteroids = ECS.useEntities((world) => world.with("asteroid"))
  return <ECS.Entities in={asteroids} />
}