How about more "reactive" observers ?
[https://gist.github.com/PixeyeHQ/fbec35b25b667b847b4eac413a8539a5](https://gist.github.com/PixeyeHQ/fbec35b25b667b847b4eac413a8539a5)
The idea is to subscribe for variable change. The proc you register will
trigger every time this variable changes.
type
ComponentObject = ref object
hp: int
name: string
attack: int
var cObject = new(ComponentObject)
cObject.hp = 20
cObject.name = "Platypus"
cObject.attack = 12
cObject.onChange(x=>x.hp,(x: ComponentObject)=>(echo &"current health:
{x.hp}"))
cObject.onChange(x=>x.name,(x: ComponentObject)=>(echo &"current name:
{x.name}"))
cObject.onChange(x=>x.attack,(x: ComponentObject)=>(echo &"current attack:
{x.attack}"))
handleObserver()
cObject.name="Alpaca"
cObject.hp+=10
cObject.attack+=10
echo "---------------------------"
handleObserver()
Run