- Rename JS/CSS for main.html to be consistent (main.js, main.css) - Add hx.js module to reduce virtual-dom boilerplate - Move state.js into renderer/lib.js where it belongs - Rename torrent-list.js -> home.js for consistency - Rename create-torrent-page.js -> create-torrent.js for consistency
42 lines
948 B
JavaScript
42 lines
948 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 str = JSON.stringify(args)
|
|
var handler = _dispatchers[str]
|
|
if (!handler) {
|
|
handler = _dispatchers[str] = function (e) {
|
|
// Do not propagate click to elements below the button
|
|
e.stopPropagation()
|
|
|
|
if (e.currentTarget.classList.contains('disabled')) {
|
|
// Do not allow clicks on disabled buttons
|
|
return
|
|
}
|
|
|
|
_dispatch.apply(null, args)
|
|
}
|
|
}
|
|
return handler
|
|
}
|
|
|
|
function dispatch (...args) {
|
|
_dispatch.apply(null, args)
|
|
}
|