Skip to content

Instantly share code, notes, and snippets.

@radutopala
Last active August 29, 2015 14:17
Show Gist options
  • Save radutopala/fe57d5da66c8be3326b9 to your computer and use it in GitHub Desktop.
Save radutopala/fe57d5da66c8be3326b9 to your computer and use it in GitHub Desktop.
virtual dom diff test
var parser = require('html2hscript'),
redis = require("redis"),
client = redis.createClient(),
util = require('util'),
diff = require('virtual-dom/diff'),
patches, content, oldTree = '';
client.on("error", function (err) {
console.log("Error " + err);
});
client.get('content', processContent);
function processContent(err, reply) {
if (reply) {
content = reply.toString();
client.get('translated', processTranslated);
}
}
function processTranslated(err, reply) {
if (reply) {
oldTree = reply.toString();
}
parser(content, processNewContent);
}
function processNewContent(err, newTree) {
//client.set('translated', newTree);
console.log(oldTree);
console.log(newTree);
patches = diff(oldTree, newTree);
console.log(patches);
client.end();
}
var parser = require('html2hscript'),
redis = require("then-redis"),
client = redis.createClient(),
diff = require('virtual-dom/diff'),
Q = require("q"),
jsdom = require("jsdom"),
patches, newContent, oldContent, newTree, oldTree;
client.on("error", function (err) {
console.log("Error " + err);
});
client.mget('newContent', 'oldContent').then(function (values) {
processContent(values);
console.log(newTree, oldTree);
patches = diff(newTree, oldTree);
console.log(patches);
//client.end();
});
function processContent(values) {
var funcs = [
parser(values[0], function (err, hscript) {
newTree = hscript;
return values;
}),
parser(values[1], function (err, hscript) {
oldTree = hscript;
return values;
})
];
var p = Q(values);
funcs.forEach(function (f) {
p.then(f);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment