CreateObjectPool()

From Wowpedia
Jump to: navigation, search
This function is implemented by FrameXML in FrameXML/Pools.lua.

Creates an ObjectPoolMixin, a pool of reusable widgets that may be acquired and released for reuse.

pool = CreateObjectPool(creationFunc [, resetterFunc])

Arguments

creationFunc 
function - Called with one argument (pool) to construct and return a new widget.
resetterFunc 
function?Optional. Could be nil. - Called with two arguments (pool, widget) to initialize or restore a widget to its factory state.

Methods

ObjectPoolMixin:Acquire() - Furnishes a new or reused widget
ObjectPoolMixin:Release(widget) - Restores a widget to original condition for reuse
ObjectPoolMixin:ReleaseAll() - Restores all widgets sourced from the pool to original condition for reuse
ObjectPoolMixin:EnumerateActive() - Returns an iterator to cycle through widgets sourced from the pool
ObjectPoolMixin:EnumerateInactive() - Returns an iterator to cycle through widgets released back to the pool
ObjectPoolMixin:GetNextActive(current) - Moves to the next active widget within the pool, or returns nil
ObjectPoolMixin:GetNextInactive(current) - Moves to the next inactive widget within the pool, or returns nil
ObjectPoolMixin:IsActive(widget) - Indicates if the widget is presently acquired from the pool
ObjectPoolMixin:GetNumActive() - Returns the number of widgets presently acquired from the pool
ObjectPoolMixin:SetResetDisallowedIfNew() - Prevents Acquire() from calling resetterFunc() on newly-created widgets.

Example

-- initialize the pool
local function creationFunc()
	return CreateFrame("Frame")
end
local function resetterFunc(__, frame)
	frame:Hide()
end
local pool = CreateObjectPool(creationFunc, resetterFunc)

-- Request a frame
local frame = pool:Acquire()
frame:Show()

-- Return the frame when it is no longer required
pool:Release(frame)

-- Request a frame again
local frame = pool:Acquire()  -- could be a different frame if others were acquired/released in the interim
frame:Show() -- cancels Hide() in resetterFunc

Patch changes

See also

External links

References

  1. ^ 2017-03-28, Pools.lua, version 7.2.0.23835, archived at Townlong-Yak