properties: Allow to delay some operations.
This will be useful for the append/remove support.
This commit is contained in:
parent
a8dcd3b2a2
commit
fbe2b34af4
|
@ -8,6 +8,7 @@
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
local gtable = require("gears.table")
|
local gtable = require("gears.table")
|
||||||
|
local gtimer = nil --require("gears.timer")
|
||||||
-- local gdebug = require("gears.debug")
|
-- local gdebug = require("gears.debug")
|
||||||
local object = {}
|
local object = {}
|
||||||
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
||||||
|
@ -83,6 +84,8 @@ function object.capi_index_fallback(class, args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert(type(class) ~= "function")
|
||||||
|
|
||||||
-- Attach the accessor methods
|
-- Attach the accessor methods
|
||||||
class.set_index_miss_handler(getter)
|
class.set_index_miss_handler(getter)
|
||||||
class.set_newindex_miss_handler(setter)
|
class.set_newindex_miss_handler(setter)
|
||||||
|
@ -190,7 +193,7 @@ local function copy_object(obj, to_set, name, capi_name, is_object, join_if, set
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function object._legacy_accessors(obj, name, capi_name, is_object, join_if, set_empty)
|
function object._legacy_accessors(obj, name, capi_name, is_object, join_if, set_empty, delay)
|
||||||
|
|
||||||
-- Some objects have a special "object" property to add more properties, but
|
-- Some objects have a special "object" property to add more properties, but
|
||||||
-- not all.
|
-- not all.
|
||||||
|
@ -248,6 +251,7 @@ function object._legacy_accessors(obj, name, capi_name, is_object, join_if, set_
|
||||||
|
|
||||||
|
|
||||||
--TODO v6 Use the original directly and drop this legacy copy
|
--TODO v6 Use the original directly and drop this legacy copy
|
||||||
|
local function apply()
|
||||||
local result = is_formatted and objs
|
local result = is_formatted and objs
|
||||||
or gtable.join(unpack(objs))
|
or gtable.join(unpack(objs))
|
||||||
|
|
||||||
|
@ -258,6 +262,23 @@ function object._legacy_accessors(obj, name, capi_name, is_object, join_if, set_
|
||||||
else
|
else
|
||||||
self._private[name.."_formatted"] = result
|
self._private[name.."_formatted"] = result
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Some properties, like keys, are expensive to set, schedule them
|
||||||
|
-- instead.
|
||||||
|
if not delay then
|
||||||
|
apply()
|
||||||
|
else
|
||||||
|
if not self._private["_delayed_"..name] then
|
||||||
|
gtimer = gtimer or require("gears.timer")
|
||||||
|
gtimer.delayed_call(function()
|
||||||
|
self._private["_delayed_"..name]()
|
||||||
|
self._private["_delayed_"..name] = nil
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
self._private["_delayed_"..name] = apply
|
||||||
|
end
|
||||||
|
|
||||||
self._private[name] = copy_object(
|
self._private[name] = copy_object(
|
||||||
obj, objs, name, capi_name, is_object, join_if, set_empty
|
obj, objs, name, capi_name, is_object, join_if, set_empty
|
||||||
|
|
Loading…
Reference in New Issue