add(update_callback) allow nil callback
Suggested by @sclu1034
This commit is contained in:
parent
18ae7bb56d
commit
d5dbb9d32e
|
@ -16,10 +16,6 @@ local wbase = require("wibox.widget.base")
|
|||
local gtable = require("gears.table")
|
||||
local gtimer = require("gears.timer")
|
||||
|
||||
local default_update_callback = function()
|
||||
return nil
|
||||
end
|
||||
|
||||
local default_template_widget = wbase.empty_widget()
|
||||
|
||||
local template = {
|
||||
|
@ -28,7 +24,9 @@ local template = {
|
|||
}
|
||||
|
||||
function template:_do_update_now(args)
|
||||
if type(self.update_callback) == 'function' then
|
||||
self:update_callback(args)
|
||||
end
|
||||
template.queued_updates[self] = false
|
||||
end
|
||||
|
||||
|
@ -73,7 +71,7 @@ function template.new(args)
|
|||
|
||||
local widget = wbase.make_widget_from_value(widget_template)
|
||||
|
||||
widget.update_callback = args.update_callback or default_update_callback
|
||||
widget.update_callback = args.update_callback
|
||||
widget.update_args = args.update_args or {}
|
||||
|
||||
gtable.crush(widget, template, true)
|
||||
|
|
|
@ -32,7 +32,7 @@ describe("wibox.widget.template", function()
|
|||
it("batch calls", function()
|
||||
local spied_update_callback = spy.new(function() end)
|
||||
|
||||
widget.update_callback = spied_update_callback
|
||||
widget.update_callback = function(...) spied_update_callback(...) end
|
||||
|
||||
-- Multiple calls to update
|
||||
widget:update()
|
||||
|
@ -54,7 +54,7 @@ describe("wibox.widget.template", function()
|
|||
local update_args = { foo = "bar" }
|
||||
|
||||
widget.update_args = args_structure
|
||||
widget.update_callback = spied_update_callback
|
||||
widget.update_callback = function(...) spied_update_callback(...) end
|
||||
|
||||
widget:update(update_args)
|
||||
|
||||
|
|
Loading…
Reference in New Issue