LibDataBlock is meant to create a bridge between addons that offer some data the user might want to see on his screen, and viewer addons that show the registered blocks , thus giving user some choice how to see them. For those who are familiar with the concept of lib data broker this shouldn't be new idea and indeed, lib data block is just a port of it for eso on permission of the original author.
To use LibDataBlock in your addon, easiest way is to embed it, as well as LibStub it requires, and then call for it’s instance in the addon.
Code:
local ldb = LibStub:GetLibrary("LibDataBlock-1.0")
API
Code:
ldb:NewDataObject(string name, table/nil dataobject) -> dataobject
Creates and registers a new data object. If table is provided as second parameter, the string keyed values will be used for the new data object. The method also fires callbacks which are registered to listen
"LibDataBlock_DataObjectCreated" event.
Code:
ldb:DataObjectIterator()
Iterator to go through all registered data objects which works like
pairs().
Lua Code:
for name, block in ldb:DataObjectIterator() do
...
end
Code:
ldb:GetDataObjectByName(dataobjectname) -> dataobject
Returns registered data object by name.
Code:
ldb:GetNameByDataObject(dataobject) -> string name
Returns name of the given data object.
Code:
ldb:pairs(string/dataobject dataobject_or_name)
Works as
pairs() for data object
Code:
ldb:ipairs(string/dataobject dataobject_or_name)
Works as
ipairs() for data object.
Code:
ldb:RegisterCallback(string eventname, function callback)
Is used to register a callback working much like events. The library fires 5 different types of callback events. Apart from the aforementioned data object creation, every time some value is changed in the block, four different events are caused. The callback is function that’ll get called when registered event happens. Next is list of event names, and parameters the functions attached to them will be passed.
LibDataBlock_DataObjectCreated (name, event)
Fired when new data object is registered.
LibDataBlock_AttributeChanged (name, key, value, dataobject)
Fired when any field in any data object is changed.
LibDataBlock_AttributeChanged_<name> (name, key, value, dataobject)
Fired when any field in data object <name> is changed.
LibDataBlock_AttributeChanged_<name>_<key> (name, key, value, dataobject)
Fired when field <key> in data object <name> is changed.
LibDataBlock_AttributeChanged__<key> (name, key, value, dataobject)
Fired when field <key> is changed in any data object. Yes, there is two underscores separating the key from the prefix.
Code:
ldb:UnregisterCallback(string eventName, function callback)
Is used to unregister previously registered callback. The same function has to be passed as parameter so if you are going to unregister an event, the function pointer should be preserved.
Data Specification
The very basic idea of LibDataBlock is based on data objects containing fields that the viewers know to expect and to show. Hence here is some guidelines for what fields should be expected. First and foremost there is type field which defines what sort of block is in question. The rest of the fields and their expectability is determined by what type the block claims to be.
Data Source
type (required) string
“data source”
text (required) string
The text that the block is supposed to show. For example “67/70” for inventory space addon or “Wayrest” for location one.
label string
Can be used as a title in place of name of the object.
icon string
Iconpath the viewers can choose to use to represent an icon accompanying the text.
OnClick function
Function to be executed when the block is clicked.
tooltip control
Control that the viewer can show when, in most usual case, the block is entered with mouse cursor. The viewer will take care of anchoring the control appropriately.
Launcher
type (required) string
“launcher”
icon (required) string
Iconpath the viewers can use to represent a way to launch desired functionality, like your addons interface.
OnClick (required) function
Function to be executed when the block is clicked.
label string
Can be used as a title in place of name of the object.