Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Syntax for queries and events #70

Closed
fernandojsg opened this issue Sep 3, 2019 · 4 comments
Closed

Syntax for queries and events #70

fernandojsg opened this issue Sep 3, 2019 · 4 comments

Comments

@fernandojsg
Copy link
Member

Currently the syntax for queries and its events is the following:

{
  queries: {
    entities: {
      components: [Rotating, Transform]
      events: {
        added: {
          event: "EntityAdded"
        },
        removed: {
          event: "EntityRemoved"
        },
        changed: {
          event: "EntityChanged"
        },
        rotatingChanged: {
          event: "ComponentChanged",
          components: [Rotating]
        },
        transformChanged: {
          event: "ComponentChanged",
          components: [Transform]
        }
      }
    }
  }
}```

And the way to access the entities on the `execute` method is:
```javascript
execute() {
  // Queries
  this.queries.entities.forEach(entity => {})

  // Events
  this.events.entities.added.forEach(entity => {})
  this.events.entities.removed.forEach(entity => {})
  this.events.entities.changed.forEach(entity => {})
  this.events.entities.rotatingChanged.forEach(entity => {})
  this.events.entities.transformChanged.forEach(entity => {})
}

I'd like to get feedback on using a common path this.queries.entities.* for both type of queries. Something like:

execute() {
  // Queries
  this.queries.entities.results.forEach(entity => {})

  // Events
  this.queries.entities.events.added.forEach(entity => {})
  this.queries.entities.events.removed.forEach(entity => {})
  this.queries.entities.events.changed.forEach(entity => {})
  this.queries.entities.events.rotatingChanged.forEach(entity => {})
  this.queries.entities.events.transformChanged.forEach(entity => {})
}
@feiss
Copy link

feiss commented Sep 9, 2019

A naive and probably not very popular alternative --but much less verbose-- would be to merge all queries and events in the root of the system, and the user would be the one making sure that there's no name clashing. So, instead of:

this.queries.entities.forEach(entity => {})

this.events.entities.added.forEach(entity => {})
this.events.entities.removed.forEach(entity => {})
this.events.entities.changed.forEach(entity => {})
this.events.entities.rotatingChanged.forEach(entity => {})
this.events.entities.transformChanged.forEach(entity => {})

we would have:

this.entities.forEach(entity => {})

this.added.forEach(entity => {})
this.removed.forEach(entity => {})
this.changed.forEach(entity => {})
this.rotatingChanged.forEach(entity => {})
this.transformChanged.forEach(entity => {})

Example with two queries:

this.cars.forEach(entity => {})
this.bikes.forEach(entity => {})

this.bikeAdded.forEach(entity => {})
this.carAdded.forEach(entity => {})
this.bikeRotatingChanged.forEach(entity => {})
this.carTransformChanged.forEach(entity => {})
...

So it's a matter of naming, with much simpler syntax to remember. If you look at the examples, when you have only one query you call it 'entities', but as soon as you have more than one, you start putting significant names like "ball", "intersectingBall"..

@feiss
Copy link

feiss commented Sep 9, 2019

Another alternative, more cleaner but also not very verbose, would be adding an object for each query with all the events, and a list (or all, any other name) member for accessing the array of entities:

this.cars.list.forEach(entity => {})
this.bikes.list.forEach(entity => {})

this.bikes.added.forEach(entity => {})
this.cars.added.forEach(entity => {})
this.bikes.rotatingChanged.forEach(entity => {})
this.cars.ransformChanged.forEach(entity => {})

@joshmarinacci
Copy link
Contributor

joshmarinacci commented Sep 9, 2019 via email

@fernandojsg
Copy link
Member Author

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants