Description
queryResult:snapshot()
performs all of the iterator task at once and provides you the results of the query at the moment it is called. Hecs has a similar feature with query().views()
, which is meant for repeated random access. It provides you a handle to discern whether it contains a specific entity and to access its data easily at an amortized cost via Views.get()
and Views.contains()
respectively.
I think providing similar methods will make :snapshot
a more meaningful arm to QueryResult
. We could even naively implement this by changing the list into a dictionary that maps the entity id to its packed data, and returning it, allowing people to just index it. But this wouldn't preserve the same order of traversal of entities as the query.
Considerations
This is a breaking change as it would most likely change the return type. Alternatively we can look to make a separate method called view.
Side note
Currently, you can't follow the :without()
arm with :snapshot()
. We may want to make a separate change to address this. #85
For tracking
Partial implementation: #80