The reactive system is already done, a nameplate mod released at
https://www.curseforge.com/wow/addons/aim.
It's a tiny mod, almost all indicators are skin settings defined in the
DefaultSkin.lua.
Take the healthbar as an example:
Lua Code:
HealthBar = {
-- like class in css, share skin settings with a table for many elements
SHARE_STATUSBAR_SKIN,
location = { Anchor("BOTTOMLEFT"), Anchor("BOTTOMRIGHT") },
height = BAR_HEIGHT,
-- threat, tap, class color
statusBarColor = Wow.UnitExtendColor(true),
-- The minmax value for the status bar
minMaxValues = Wow.UnitHealthMax(),
-- Use smooth value instead the value, use NIL to block the default settings
value = NIL,
-- An extended property works for slider and statusbar for smoothing effect
-- the unit's health value will be dispatched here
smoothValue = Wow.UnitHealth(),
-- the back ground settings with a dynamic color for target
backgroundFrame = {
-- The border color turn white if the unit is player's target
backdropBorderColor = Wow.UnitIsTarget():Map(function(val) return val and Color.WHITE or Color.BLACK end),
},
},
The APIs like Wow.UnitHealth() will subscribe the UNIT_HEALTH event observable, and match the unit provided by the healthbar's parent(or parent's parent until find a UnitFrame).
The API's definition is simple:
Lua Code:
function Wow.UnitHealth()
-- Use the Next for a tiny delay after the UnitHealthMax
return Wow.FromUnitEvent("UNIT_HEALTH", "UNIT_MAXHEALTH"):Next():Map(UnitHealth)
end
The Wow.FromUnitEvent will be used to bind the UNIT event and the unit from the parent. The
Next() will delay the data dispatch for one frame and distinct it, so it won't be send twice or more, also make sure the value will be a tiny later than the Wow.UnitHealthMax which will change the status bar's minMax.
Full document will be out in the github when another mod for Raid Panel is released.