From d5dbb9d32e37269e93dcc80ed1ce79f85ff0d20b Mon Sep 17 00:00:00 2001 From: Aire-One Date: Wed, 29 Sep 2021 22:34:38 +0200 Subject: [PATCH] add(update_callback) allow nil callback Suggested by @sclu1034 --- lib/wibox/widget/template.lua | 10 ++++------ spec/wibox/widget/template_spec.lua | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/wibox/widget/template.lua b/lib/wibox/widget/template.lua index af86e7e11..18600a61f 100644 --- a/lib/wibox/widget/template.lua +++ b/lib/wibox/widget/template.lua @@ -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) - self:update_callback(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) diff --git a/spec/wibox/widget/template_spec.lua b/spec/wibox/widget/template_spec.lua index 7fad45622..e73ef568c 100644 --- a/spec/wibox/widget/template_spec.lua +++ b/spec/wibox/widget/template_spec.lua @@ -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)