Merge pull request #28 from feross/main-loop
Batch virtual-dom changes (fix #27)
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
"debug": "^2.2.0",
|
"debug": "^2.2.0",
|
||||||
"drag-drop": "^2.3.1",
|
"drag-drop": "^2.3.1",
|
||||||
"hyperx": "^2.0.0",
|
"hyperx": "^2.0.0",
|
||||||
|
"main-loop": "^3.2.0",
|
||||||
"network-address": "^1.1.0",
|
"network-address": "^1.1.0",
|
||||||
"pretty-bytes": "^3.0.0",
|
"pretty-bytes": "^3.0.0",
|
||||||
"throttleit": "^1.0.0",
|
"throttleit": "^1.0.0",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ var createTorrent = require('create-torrent')
|
|||||||
var dragDrop = require('drag-drop')
|
var dragDrop = require('drag-drop')
|
||||||
var electron = require('electron')
|
var electron = require('electron')
|
||||||
var EventEmitter = require('events')
|
var EventEmitter = require('events')
|
||||||
|
var mainLoop = require('main-loop')
|
||||||
var networkAddress = require('network-address')
|
var networkAddress = require('network-address')
|
||||||
var path = require('path')
|
var path = require('path')
|
||||||
var throttle = require('throttleit')
|
var throttle = require('throttleit')
|
||||||
@@ -57,7 +58,7 @@ var state = global.state = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var client, currentVDom, rootElement, updateThrottled
|
var client, vdomLoop, updateThrottled
|
||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
client = global.client = new WebTorrent()
|
client = global.client = new WebTorrent()
|
||||||
@@ -65,9 +66,12 @@ function init () {
|
|||||||
client.on('error', onError)
|
client.on('error', onError)
|
||||||
state.view.client = client
|
state.view.client = client
|
||||||
|
|
||||||
currentVDom = App(state, dispatch)
|
vdomLoop = mainLoop(state, render, {
|
||||||
rootElement = createElement(currentVDom)
|
create: createElement,
|
||||||
document.body.appendChild(rootElement)
|
diff: diff,
|
||||||
|
patch: patch
|
||||||
|
})
|
||||||
|
document.body.appendChild(vdomLoop.target)
|
||||||
|
|
||||||
updateThrottled = throttle(update, 1000)
|
updateThrottled = throttle(update, 1000)
|
||||||
|
|
||||||
@@ -108,12 +112,12 @@ function init () {
|
|||||||
}
|
}
|
||||||
init()
|
init()
|
||||||
|
|
||||||
function update () {
|
function render (state) {
|
||||||
var newVDom = App(state, dispatch)
|
return App(state, dispatch)
|
||||||
var patches = diff(currentVDom, newVDom)
|
}
|
||||||
rootElement = patch(rootElement, patches)
|
|
||||||
currentVDom = newVDom
|
|
||||||
|
|
||||||
|
function update () {
|
||||||
|
vdomLoop.update(state)
|
||||||
updateDockIcon()
|
updateDockIcon()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user