Files
webtorrent-desktop/renderer/lib/dispatcher.js
DC 28c386d916 Fix file list enabled/disabled logic
* Files that are either 100% downloaded OR streamble should be enabled
* Disabled files should not be clickable

This fixes both bugs.
2016-04-06 02:55:41 -07:00

37 lines
907 B
JavaScript

module.exports = {
setDispatch,
dispatch,
dispatcher
}
// Memoize most of our event handlers, which are functions in the form
// () => dispatch(<args>)
// ... this prevents virtual-dom from updating every listener on every update()
var _dispatchers = {}
var _dispatch = () => {}
function setDispatch (dispatch) {
_dispatch = dispatch
}
// Get a _memoized event handler that calls dispatch()
// All args must be JSON-able
function dispatcher (...args) {
var json = JSON.stringify(args)
var handler = _dispatchers[json]
if (!handler) {
_dispatchers[json] = (e) => {
// Don't click on whatever is below the button
e.stopPropagation()
// Don't regisiter clicks on disabled buttons
if (e.currentTarget.classList.contains('disabled')) return
_dispatch.apply(null, args)
}
}
return handler
}
function dispatch (...args) {
_dispatch.apply(null, args)
}