-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate vicious.call into sync and async versions
- Loading branch information
Showing
1 changed file
with
31 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
-- Vicious module initialization | ||
-- Copyright (C) 2009 Lucas de Vries <[email protected]> | ||
-- Copyright (C) 2009-2013 Adrian C. (anrxc) <[email protected]> | ||
-- Copyright (C) 2011 Joerg T. (Mic92) <[email protected]> | ||
-- Copyright (C) 2011-2017 Joerg Thalheim <[email protected]> | ||
-- Copyright (C) 2012 Arvydas Sidorenko <[email protected]> | ||
-- Copyright (C) 2012 Jörg Thalheim <[email protected]> | ||
-- Copyright (C) 2013 Dodo <[email protected]> | ||
-- Copyright (C) 2013-2014,2017 Jörg Thalheim <[email protected]> | ||
-- Copyright (C) 2014 blastmaster <[email protected]> | ||
-- Copyright (C) 2015 Daniel Hahler <git@thequod.de> | ||
-- Copyright (C) 2015,2019 Daniel Hahler <github@thequod.de> | ||
-- Copyright (C) 2017 James Reed <[email protected]> | ||
-- Copyright (C) 2017 Joerg Thalheim <[email protected]> | ||
-- Copyright (C) 2017 getzze <[email protected]> | ||
-- Copyright (C) 2017 mutlusun <[email protected]> | ||
-- Copyright (C) 2018 Beniamin Kalinowski <[email protected]> | ||
-- Copyright (C) 2018 Nguyễn Gia Phong <[email protected]> | ||
-- Copyright (C) 2019 Daniel Hahler <[email protected]> | ||
-- Copyright (C) 2018,2020 Nguyễn Gia Phong <[email protected]> | ||
-- | ||
-- This file is part of Vicious. | ||
-- | ||
|
@@ -322,16 +318,39 @@ function vicious.activate(widget) | |
end | ||
-- }}} | ||
|
||
-- {{{ Get custom widget format data | ||
function vicious.call(myw, format, warg) | ||
local mydata = myw(format, warg) | ||
-- {{{ Get formatted data from a synchronous widget type | ||
function vicious.call(wtype, format, warg) | ||
if wtype.async ~= nil then return nil end | ||
|
||
local data = wtype(format, warg) | ||
if type(format) == "string" then | ||
return helpers.format(format, mydata) | ||
return helpers.format(format, data) | ||
elseif type(format) == "function" then | ||
return format(myw, mydata) | ||
return format(wtype, data) | ||
end | ||
end | ||
-- }}} | ||
|
||
-- {{{ Get formatted data from an asynchronous widget type | ||
function vicious.call_async(wtype, format, warg, callback) | ||
if wtype.async == nil then | ||
callback() | ||
return | ||
end | ||
|
||
wtype.async( | ||
format, warg, | ||
function (data) | ||
if type(format) == "string" then | ||
callback(helpers.format(format, data)) | ||
elseif type(format) == "function" then | ||
callback(format(wtype, data)) | ||
else | ||
callback() | ||
end | ||
end) | ||
end | ||
-- }}} | ||
|
||
return vicious | ||
-- }}} |