driver-worker
Advanced tools
Comparing version 0.6.3-3 to 0.6.3-4
@@ -19,3 +19,4 @@ 'use strict'; | ||
var TEXT_CONTENT_ATTR = 'textContent' in document ? 'textContent' : 'nodeValue'; | ||
var TEXT_CONTENT = 'textContent'; | ||
var TEXT_CONTENT_ATTR = TEXT_CONTENT in document ? TEXT_CONTENT : 'nodeValue'; | ||
var EVENT_OPTIONS = supportsPassive ? { | ||
@@ -108,2 +109,3 @@ capture: true, | ||
} | ||
if (vnode.style) { | ||
@@ -116,2 +118,3 @@ for (var i in vnode.style) { | ||
} | ||
if (vnode.attributes) { | ||
@@ -128,2 +131,3 @@ for (var _i = 0; _i < vnode.attributes.length; _i++) { | ||
} | ||
if (vnode.childNodes) { | ||
@@ -134,2 +138,3 @@ for (var _i2 = 0; _i2 < vnode.childNodes.length; _i2++) { | ||
} | ||
if (vnode.events) { | ||
@@ -235,66 +240,2 @@ for (var _i3 = 0; _i3 < vnode.events.length; _i3++) { | ||
function applyMutation(mutation) { | ||
MUTATIONS[mutation.type](mutation); | ||
} | ||
var timer = void 0; | ||
var MUTATION_QUEUE = []; | ||
if (!window.requestIdleCallback) { | ||
var IDLE_TIMEOUT = 10; | ||
window.requestIdleCallback = function (cb) { | ||
var start = Date.now(); | ||
setTimeout(function () { | ||
return cb({ | ||
timeRemaining: function timeRemaining() { | ||
return Math.max(0, IDLE_TIMEOUT - (Date.now() - start)); | ||
} | ||
}); | ||
}, 1); | ||
}; | ||
} | ||
function processMutationQueue(deadline) { | ||
clearTimeout(timer); | ||
var q = MUTATION_QUEUE; | ||
var start = Date.now(); | ||
var isDeadline = deadline && deadline.timeRemaining; | ||
var cache = {}; | ||
var i = void 0; | ||
for (i = 0; i < q.length; i++) { | ||
if (isDeadline ? deadline.timeRemaining() <= 0 : Date.now() - start > 1) break; | ||
var m = q[i]; | ||
applyMutation(q.splice(i--, 1)[0]); | ||
} | ||
if (q.length) doProcessMutationQueue(); | ||
} | ||
function doProcessMutationQueue() { | ||
clearTimeout(timer); | ||
timer = setTimeout(processMutationQueue, 100); | ||
requestIdleCallback(processMutationQueue); | ||
} | ||
function queueMutation(mutation) { | ||
if (mutation.type === 'characterData' || mutation.type === 'attributes') { | ||
for (var i = MUTATION_QUEUE.length; i--;) { | ||
var m = MUTATION_QUEUE[i]; | ||
if (m.type == mutation.type && m.target.$$id == mutation.target.$$id) { | ||
if (m.type === 'attributes') { | ||
MUTATION_QUEUE.splice(i + 1, 0, mutation); | ||
} else { | ||
MUTATION_QUEUE[i] = mutation; | ||
} | ||
return; | ||
} | ||
} | ||
} | ||
if (MUTATION_QUEUE.push(mutation) === 1) { | ||
doProcessMutationQueue(); | ||
} | ||
} | ||
worker.onmessage = function (_ref8) { | ||
@@ -305,4 +246,7 @@ var data = _ref8.data; | ||
if (type === 'MutationRecord') { | ||
for (var i = 0; i < data.mutations.length; i++) { | ||
queueMutation(data.mutations[i]); | ||
var mutations = data.mutations; | ||
for (var i = 0; i < mutations.length; i++) { | ||
// apply mutation | ||
var mutation = mutations[i]; | ||
MUTATIONS[mutation.type](mutation); | ||
} | ||
@@ -309,0 +253,0 @@ } |
{ | ||
"name": "driver-worker", | ||
"version": "0.6.3-3", | ||
"version": "0.6.3-4", | ||
"description": "Worker driver for Rax", | ||
@@ -5,0 +5,0 @@ "license": "BSD-3-Clause", |
@@ -11,3 +11,4 @@ // feature-detect support for event listener options | ||
const TEXT_CONTENT_ATTR = 'textContent' in document ? 'textContent' : 'nodeValue'; | ||
const TEXT_CONTENT = 'textContent'; | ||
const TEXT_CONTENT_ATTR = TEXT_CONTENT in document ? TEXT_CONTENT : 'nodeValue'; | ||
const EVENT_OPTIONS = supportsPassive | ||
@@ -109,2 +110,3 @@ ? { | ||
} | ||
if (vnode.style) { | ||
@@ -116,2 +118,3 @@ for (let i in vnode.style) | ||
} | ||
if (vnode.attributes) { | ||
@@ -128,2 +131,3 @@ for (let i = 0; i < vnode.attributes.length; i++) { | ||
} | ||
if (vnode.childNodes) { | ||
@@ -134,2 +138,3 @@ for (let i = 0; i < vnode.childNodes.length; i++) { | ||
} | ||
if (vnode.events) { | ||
@@ -140,2 +145,3 @@ for (let i = 0; i < vnode.events.length; i++) { | ||
} | ||
} else if (vnode.nodeType === 8) { | ||
@@ -216,73 +222,10 @@ node = document.createComment(vnode.data); | ||
function applyMutation(mutation) { | ||
MUTATIONS[mutation.type](mutation); | ||
} | ||
let timer; | ||
let MUTATION_QUEUE = []; | ||
if (!window.requestIdleCallback) { | ||
const IDLE_TIMEOUT = 10; | ||
window.requestIdleCallback = cb => { | ||
let start = Date.now(); | ||
setTimeout( | ||
() => | ||
cb({ | ||
timeRemaining: () => | ||
Math.max(0, IDLE_TIMEOUT - (Date.now() - start)) | ||
}), | ||
1 | ||
); | ||
}; | ||
} | ||
function processMutationQueue(deadline) { | ||
clearTimeout(timer); | ||
let q = MUTATION_QUEUE; | ||
let start = Date.now(); | ||
let isDeadline = deadline && deadline.timeRemaining; | ||
let cache = {}; | ||
let i; | ||
for (i = 0; i < q.length; i++) { | ||
if (isDeadline ? deadline.timeRemaining() <= 0 : Date.now() - start > 1) | ||
break; | ||
let m = q[i]; | ||
applyMutation(q.splice(i--, 1)[0]); | ||
} | ||
if (q.length) doProcessMutationQueue(); | ||
} | ||
function doProcessMutationQueue() { | ||
clearTimeout(timer); | ||
timer = setTimeout(processMutationQueue, 100); | ||
requestIdleCallback(processMutationQueue); | ||
} | ||
function queueMutation(mutation) { | ||
if (mutation.type === 'characterData' || mutation.type === 'attributes') { | ||
for (let i = MUTATION_QUEUE.length; i--; ) { | ||
let m = MUTATION_QUEUE[i]; | ||
if (m.type == mutation.type && m.target.$$id == mutation.target.$$id) { | ||
if (m.type === 'attributes') { | ||
MUTATION_QUEUE.splice(i + 1, 0, mutation); | ||
} else { | ||
MUTATION_QUEUE[i] = mutation; | ||
} | ||
return; | ||
} | ||
} | ||
} | ||
if (MUTATION_QUEUE.push(mutation) === 1) { | ||
doProcessMutationQueue(); | ||
} | ||
} | ||
worker.onmessage = ({ data }) => { | ||
let type = data.type; | ||
if (type === 'MutationRecord') { | ||
for (let i = 0; i < data.mutations.length; i++) { | ||
queueMutation(data.mutations[i]); | ||
let mutations = data.mutations; | ||
for (let i = 0; i < mutations.length; i++) { | ||
// apply mutation | ||
let mutation = mutations[i]; | ||
MUTATIONS[mutation.type](mutation); | ||
} | ||
@@ -289,0 +232,0 @@ } |
58469
1785