CreateObjectPool()
(Redirected from ObjectPoolMixin)
Jump to navigation
Jump to search
- This function is implemented in
FrameXML/Pools.lua
.
- This function is implemented in
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? - 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
- Patch 7.2.0 (2017-03-28): Added.[1]
See also
- CreateFramePool(frameType, parent, frameTemplate, resetterFunc, forbidden) - Constructs standard Frames.
- CreateTexturePool(parent, layer, subLayer, textureTemplate, resetterFunc) - Constructs standard Textures.
- CreateFontStringPool(parent, layer, subLayer, fontStringTemplate, resetterFunc) - Constructs standard FontStrings.
- CreateActorPool(parent, actorTemplate, resetterFunc) - Constructs standard ModelSceneActors.
External links
- GitHub FrameXML, Gethe
- Globe "wut?" Tool, Townlong-Yak
References
- ^ 2017-03-28, Pools.lua, version 7.2.0.23835, archived at Townlong-Yak