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

[Experimental] Smarter Predicate Buckets #244

Closed hmans closed 1 year ago

hmans commented 2 years ago

This changes predicate buckets to re-evaluate their source's entities against the predicate every time the predicate bucket is iterated over, or the update() function is called.

it("automatically sees updated entities, like magic", () => {
  const bucket = new EntityBucket<Entity>()
  const john = bucket.add({ name: "John", age: 30 })
  const jane = bucket.add({ name: "Jane" })

  const old = bucket.archetype((entity) => Number(entity.age) > 25)
  expect([...old]).toEqual([john])

  john.age = 25
  expect([...old]).toEqual([])

  john.age = 30
  expect([...old]).toEqual([john])
})

Notes:

Todo:

codesandbox[bot] commented 2 years ago

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

changeset-bot[bot] commented 2 years ago

⚠️ No Changeset found

Latest commit: abac7ff3d722ee2d49d5456d04ba4ca22edbb9dc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR