63 lines
1.9 KiB
Lua
63 lines
1.9 KiB
Lua
local ____lualib = require("lualib_bundle")
|
|||
|
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
||
|
|
local ____exports = __module.env
|
||
|
|
local M__share_event_event_hub = __MODULE__.Import("share.event.event_hub", __module)
|
||
|
|
local EventListenerContainer = M__share_event_event_hub.EventListenerContainer
|
||
|
|
____exports.ScopedObject = __TS__DefineClass("ScopedObject", __module)
|
||
|
|
local ScopedObject = ____exports.ScopedObject
|
||
|
|
ScopedObject.name = "ScopedObject"
|
||
|
|
__TS__ClassExtends(ScopedObject, EventListenerContainer)
|
||
|
|
function ScopedObject.prototype.____constructor(self, ...)
|
||
|
|
EventListenerContainer.prototype.____constructor(self, ...)
|
||
|
|
self.scopedObjects = {}
|
||
|
|
self.disposed = false
|
||
|
|
end
|
||
|
|
function ScopedObject.prototype.IsDisposed(self)
|
||
|
|
return self.disposed
|
||
|
|
end
|
||
|
|
function ScopedObject.prototype.AddScopedObject(self, obj)
|
||
|
|
if self.disposed then
|
||
|
|
obj:Dispose()
|
||
|
|
return
|
||
|
|
end
|
||
|
|
self.scopedObjects[obj] = true
|
||
|
|
end
|
||
|
|
function ScopedObject.prototype.RemoveScopedObject(self, obj)
|
||
|
|
self.scopedObjects[obj] = nil
|
||
|
|
end
|
||
|
|
function ScopedObject.prototype.GetScopedObjectCount(self)
|
||
|
|
local count = 0
|
||
|
|
for _, active in pairs(self.scopedObjects) do
|
||
|
|
if active == true then
|
||
|
|
count = count + 1
|
||
|
|
end
|
||
|
|
end
|
||
|
|
return count
|
||
|
|
end
|
||
|
|
function ScopedObject.prototype.DisposeAllScopedObjects(self)
|
||
|
|
local list = {}
|
||
|
|
for obj, active in pairs(self.scopedObjects) do
|
||
|
|
if active == true then
|
||
|
|
list[#list + 1] = obj
|
||
|
|
end
|
||
|
|
end
|
||
|
|
self.scopedObjects = {}
|
||
|
|
do
|
||
|
|
local i = 0
|
||
|
|
while i < #list do
|
||
|
|
list[i + 1]:Dispose()
|
||
|
|
i = i + 1
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
function ScopedObject.prototype.Dispose(self)
|
||
|
|
if self.disposed then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
self.disposed = true
|
||
|
|
self:DisposeAllScopedObjects()
|
||
|
|
EventListenerContainer.prototype.Dispose(self)
|
||
|
|
end
|
||
|
|
function __module.UpdateImports()
|
||
|
|
EventListenerContainer = M__share_event_event_hub.EventListenerContainer
|
||
|
|
end
|