GetItemInfoAsync

GetItemInfoAsync

39 Downloads

Often addon developers use boilerplate code for handling the GET_ITEM_INFO_RECEIVED event after GetItemInfo returns null.
This is quite verbose and usually involves tracking internal state of what items are pending load.
The purpose of this library is to simplify this process is the majority of scenarios.

How it works

When you call GetItemInfoAsync it immediately calls GetItemInfo. If data is returned then your callback is invoked synchronously.
If no data is returned it queues your callback pending GET_ITEM_INFO_RECEIVED event. If this scenario your callback will be invoked asynchronously.

API

GetItemInfoAsync(itemID|itemName|itemLink, callback)

returns true if callback was executed synchronously
returns false if callback was queued to execute asynchronously upon GET_ITEM_INFO_RECEIVED event

Example

.pkgmeta


    externals:
        libs/GetItemInfoAsync-1.0: https://repos.curseforge.com/wow/getiteminfoasync/GetItemInfoAsync-1.0

YourPlugin.toc


    lib\GetItemInfoAsync-1.0\GetItemInfoAsync-1.0.xml

YourPlugin.lua


    local GetItemInfoAsync = LibStub("GetItemInfoAsync-1.0")
    function PrintItemNameFromItemID(itemID)
      GetItemInfoAsync(itemID, function(itemName, ...)
          print("itemName is", itemName
      end)
    end