Skip to content

chqs-git/reactive-ecs

Repository files navigation

Reactive Entity Component System (RECS)

RECS is a fast & lightweight Reactive Entity Component System pattern for Dart and Flutter, targeted at Widgets and state management. This project is Open Source and is under the MIT License.

First of all, what is the ECS paradigm?

A Entity Component System is a pattern that separates state from behaviour. It is composed by 3 main parts:

  • Entities: A unique identifier that groups components (and relationships);
  • Components: Data that represents the state of an entity;
  • Systems: Logic that operates on entities with specific components;

Usage

To use this package, add reactive-ecs as a dependency in your pubspec.yaml file.

dependencies:
  reactive-ecs:
      git: https://github.com/chqs-git/reactive-ecs.git

Example

final max = entityManager.createEntity()
    ..add(Self())
    ..add(Name(value: "Max"))
    ..add(PersonalDetails(hobby: 'Drawing', favoriteColor: Colors.green))
    ..addRelationship(ChildOf(order: 0), parentEntity)
    ..addRelationship(EmployeeOf(position: JobPosition.programmer), jobEntity);

@override
Widget build(BuildContext context) => EntityObservingWidget(
    provider: (em) => em.getUniqueComponent<Self>(),
    builder: (context, entity, _) => Column(
        children: [
            Text(entity.get<Name>().value),
            Row(
                children: [
                    Text(entity.get<PersonalDetails>().hobby),
                    Color(entity.get<PersonalDetails>().favoriteColor),
                ]
            ),
            Text('Parent: ${entity.getRelationship<ChildOf>().$1.get<Name>().value}')
        ]
    )
);

Features

  • Entities, components & systems;
  • Unique Components;
  • Groups;
  • Listenable;
  • Widgets;
  • Maps;
  • Relationships;
  • Web Inspector (Future);

Support

For contact information use: [email protected].

ko-fi

Acknowledgements

Other works that inspired and contributed to this package. (thank you)

About

Reactive Entity Component System For Flutter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages