This repository provides a set of Haxe macros and utilities for creating reactive Colyseus schema models. The tooling enables automatic generation of observable fields, synchronization listeners, and type-safe state management using tink.state.
The tooling is designed to simplify the integration of Colyseus schemas with reactive Haxe applications by:
- Automatically generating observable fields (
State<T>). - Creating listeners for primitive, serialized, and nested schema fields.
- Handling collections (
ArraySchemaandMapSchema) with fine-grained change detection. - Reducing boilerplate and ensuring type safety.
It is intended for developers building real-time applications who want fully reactive schema models without manual listener management.
-
SchemaListenMacro
- Automatically generates
listen,onAdd,onRemovelisteners for schema fields. - Supports nested schemas, arrays, and maps.
- See SchemaListenMacro README for details and examples.
- Automatically generates
-
ObservableSchemaMacro
- Generates typed
State<T>fields and a constructor for schema classes. - Works via
@:build(ObservableSchemaMacro.build(SchemaClass)). - See ObservableSchemaMacro README for usage examples.
- Generates typed
-
SchemaTypeUtils
- Provides helpers for type extraction, field analysis, struct generation, and collection management.
- Supports JSON parsing, inner type resolution, and default value generation.
- Intended as the internal utility layer for macros.
- See SchemaTypeUtils README for details.
- Install
tink_statefrom git — the haxelib release (0.11.1) doesn't compile against tink_core 2:haxelib git tink_state https://github.com/haxetink/tink_state.git 1.0.0-beta.3 - Add the tooling package to your Haxe project.
- Use
ObservableSchemaMacroto generate reactive schema classes. - Use
SchemaListenMacroto synchronize schema instances with reactive state. - Refer to the individual READMEs for detailed usage examples.
- Note that even though observables can be used as is, their full reactive potential can be unlocked with coconut.data Models.
The following command would generate the example code located in MainExample
haxe -cp example -cp src -main tools.MainExample -js out/main.js -lib tink_json -lib tink_state -lib tink_http -lib colyseus-websocket -D no-deprecation-warnings -D js-es=6 -D debug_macro
Inspect the output:
GameSchemaDebug- generated fieldsListenDebug- generated listenersout/main.js- look forio_colyseus_tools_GameObservableto inspect the generated code
---
**Note:** This tooling assumes Haxe 4.x, Colyseus Schema, and `tink.state` (and optionally `tink.json`) are available in your project.