npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ecsy-cache

v1.0.2

Published

Cache helpers for Ecsy Entity Component System

Downloads

2

Readme

ecsy-cache

Cache helpers for Ecsy Entity Component System

Sometimes it's useful to cache Entities to be able to access them instantly from Systems by a key. This is where EntitySingleCache and EntityMultipleCache come handy.

To create a new cache, subclass one of these two abstract classes and define a key function key(entity:Entity):string|undefined. Then you can call .add(entity:Entity) and .remove(entity:Entity) to update cache as well as get(key:string) to fetch entities from cache by key.

The difference between Single and Multiple is that Single can only store one Entity per key and Multiple can store an array of Entities under the same key.

Usage in Systems

.add and .remove are defined as instance arrow functions so that they are bound to the cache instance when cache is instantiated. This enables us to pass these functions directly to .forEach in the System:

// example execute method on a System
execute() {
  this.queries.entities.added.forEach(this.world.cache.add)
  this.queries.entities.removed.forEach(this.world.cache.remove)
}

Since systems are never instantiated directly but registered on the World with a constructor, it is most practical to define caches on the World and then access them in the System via world instance variable.

In order to be able to do that, we need to define ecsy's System as System<T extends World>. This is why ecsy-cache also provides a BaseSystem, which is just a normal ecsy System but with generic .world instance variable (and basic .queries type definition). Then we can do something like this: src/example/ExampleWorld.test.ts

(There is some debate going on in ecsy community on how to approach Typescript type definitions. Until those debates result in a successful merge, we will be using BaseSystem as a base class for all our systems)