Socket
Socket
Sign inDemoInstall

@latticexyz/recs

Package Overview
Dependencies
21
Maintainers
3
Versions
1257
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @latticexyz/recs

`recs` is built with reactivity in mind. `Components` and `Queries` expose an `update$` stream, that `Systems` can react to.


Version published
Weekly downloads
5.2K
increased by8.04%
Maintainers
3
Install size
25.3 MB
Created
Weekly downloads
 

Changelog

Source

Version 2.0.11

Release date: Wed May 15 2024

Patch changes

build: bump to node 18.20.2, pnpm 9.1.1 (#2831) (create-mud)

Added pnpm 9 to project's engines.

fix(cli): fixed module artifactPath imports (#2832) (@latticexyz/cli)

Fixed imports of module artifacts via artifactPath and removed unused @latticexyz/world-modules dependency.


Readme

Source

recs - Reactive Entity Component System

recs is built with reactivity in mind. Components and Queries expose an update$ stream, that Systems can react to.

To build some fundamental intuition about ECS, have a look at our MUD ECS introduction.

recs is seamlessly integrated with the other MUD libraries, but can be used independently.

For detailed documentation, check out mud.dev/recs.

Features

  • Reactive components, queries, and systems
  • Powerful queries, including advanced indirect relationship queries
  • Seamless integration with other MUD libraries and services
  • Simple, declarative API
  • Ultra high performance
  • TypeScript support

Example

import {
  createWorld,
  defineComponent,
  createEntity,
  withValue,
  defineSystem,
  Has,
  getComponentValue,
  setComponent,
} from "@latticexyz/recs";

// Create a new World
const World = createWorld();

// Define a couple components
const Position = defineComponent(world, { x: Type.Number, y: Type.Number });
const Movable = defineComponent(world, { speed: Type.Number });

// Create a new entity
const entity1 = createEntity(world, [withValue(Position, { x: 0, y: 0 }), withValue(Movable, { speed: 10 })]);

// Define a system that reacts to updates of movable entities with a position
defineSystem(world, [Has(Position), Has(Movable)], (update) => {
  console.log("Entity", update.entity, "moved to", update.value);
  // ... do stuff, like rendering the entity on the screen, etc
});

// Move the entity around
setInterval(() => {
  const currentPosition = getComponentValue(Position, entity1);
  const newPosition = { x: position.x + 1, y: position.y + 1 };
  setComponent(Position, entity1, newPosition);
}, 1000);

Acknowledgements

  • Syntax originally inspired by bitECS

FAQs

Last updated on 15 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc