Skip to content

Add user configured context to actionsΒ #76

@krispya

Description

@krispya

From @Ctrlmonster:

Any chance we could pass our own type into createActions (with the default just being world), similar to how directed lets you define what goes into the system args?

Example: I'd like to define action stores for levels and it'd be nice to be able to control the signature for calling the store. Right now it can only be world, which feels unnecessary restrictive given that I'm defining the function and am responsible for providing the args

// define a store that takes in world and extra args (in this case a level entity)
const LevelActions = createActions((world: World, level: Entity) => ({
  spawn() {
    const entity = world.spawn();
    entity.add(PartOfLevel(level));
    return entity;
  },
  destroy() {
    world.query(PartOfLevel(level)).forEach(e => e.destroy());
  }
}));


// ---
// somewhere else when using the store
const {spawn, destroy} = LevelActions(world, someLevelEntity);
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions