mirror of
https://github.com/luxfi/explorer-v1.git
synced 2026-10-30 19:34:59 +00:00
39 lines
738 B
JavaScript
39 lines
738 B
JavaScript
import debounce from 'lodash.debounce'
|
|
|
|
export function batchChannel (func) {
|
|
let msgs = []
|
|
const debouncedFunc = debounce(() => {
|
|
func.apply(this, [msgs])
|
|
msgs = []
|
|
}, 1000, { maxWait: 5000 })
|
|
return (msg) => {
|
|
msgs.push(msg)
|
|
debouncedFunc()
|
|
}
|
|
}
|
|
|
|
export function showLoader (isTimeout, loader) {
|
|
if (isTimeout) {
|
|
const timeout = setTimeout(function () {
|
|
loader.removeAttr('hidden')
|
|
loader.show()
|
|
}, 100)
|
|
return timeout
|
|
} else {
|
|
loader.hide()
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function escapeHtml (text) {
|
|
const map = {
|
|
'&': '&',
|
|
'<': '<',
|
|
'>': '>',
|
|
'"': '"',
|
|
"'": '''
|
|
}
|
|
|
|
return text.replace(/[&<>"']/g, function (m) { return map[m] })
|
|
}
|