some tweaking + docs...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-08-31 17:11:35 +03:00
parent 3de5dae2b9
commit a2848932b9

View File

@ -584,6 +584,15 @@ var KeyboardActions = actions.Actions({
// Add debounce support to keyboard handling... // Add debounce support to keyboard handling...
// //
// Syntax:
// @0.5s actionName: arg arg -- doc...
//
// Supported units:
// ms (default) - Milliseconds
// s - Seconds
// m - Minutes
// hz - Hertz
//
// NOTE: these are not actions to make the call as light as possible... // NOTE: these are not actions to make the call as light as possible...
parseStringHandler: function(txt, ...rest){ parseStringHandler: function(txt, ...rest){
var debounce = 0 var debounce = 0
@ -591,14 +600,21 @@ var KeyboardActions = actions.Actions({
ms: 1, ms: 1,
s: 1000, s: 1000,
m: 1000 * 60, m: 1000 * 60,
h: 1000 * 60 * 60, //h: 1000 * 60 * 60,
// just for fun...
hz: function(v){ return 1000 / v },
//khz: function(v){ return 1 / v },
} }
txt = txt.replace(/^\s*@([^\s]*)\s*/, txt = txt.replace(/^\s*@([^\s]*)\s*/,
function(_, time){ function(_, time){
var unit = time var unit = time
.replace(/(\d+|\d*\.\d+)(h|m|s|ms)/, '$2') .replace(/(\d+|\d*\.\d+)([^\s]*)/, '$2')
.toLowerCase()
unit = unit == time ? 'ms' : unit unit = unit == time ? 'ms' : unit
debounce = parseFloat(time) * scale[unit] debounce = scale[unit] instanceof Function ?
scale[unit](parseFloat(time))
: parseFloat(time) * scale[unit]
return '' return ''
}) })