-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows to customize the patch & rendering function.
- Loading branch information
Showing
5 changed files
with
100 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
require("./dom-index") | ||
require("./patch-index") | ||
require("./patch-op-index") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var test = require("tape") | ||
var VNode = require("../../vnode/vnode") | ||
var VText = require("../../vnode/vtext") | ||
var diff = require("../../vtree/diff") | ||
|
||
var createElement = require("../create-element") | ||
var patch = require("../patch") | ||
|
||
test("overrided patch function is correctly used and received correct options", function (assert) { | ||
|
||
function patchCustom(rootNode, patches, renderOptions) { | ||
return { | ||
rootNode: rootNode, | ||
patches: patches, | ||
renderOptions: renderOptions | ||
} | ||
} | ||
function createElementCustom(vnode) {} | ||
|
||
var rootNode = new VNode("div") | ||
var patches = {} | ||
var renderOptions = { patch: patchCustom, render: createElementCustom } | ||
|
||
var result = patch(rootNode, patches, renderOptions) | ||
assert.equal(result.rootNode, rootNode) | ||
assert.equal(result.patches, patches) | ||
assert.equal(result.renderOptions, renderOptions) | ||
assert.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var test = require("tape") | ||
var VNode = require("../../vnode/vnode") | ||
var VText = require("../../vnode/vtext") | ||
var diff = require("../../vtree/diff") | ||
var document = require("global/document") | ||
|
||
var createElement = require("../create-element") | ||
var patch = require("../patch") | ||
|
||
var createElementCustom = function(vnode) { | ||
var created = createElement(vnode) | ||
created.customCreation = true | ||
return created | ||
} | ||
|
||
function assertPachedNodeIsMarked(leftNode, rightNode, assert) { | ||
var root = createElementCustom(leftNode) | ||
var patches = diff(leftNode, rightNode) | ||
var newRoot = patch(root, patches, { render: createElementCustom }) | ||
assert.equal(newRoot.childNodes[0].customCreation, true) | ||
assert.end() | ||
} | ||
|
||
test("overrided createElement is used on node insertion", function (assert) { | ||
var leftNode = new VNode("div") | ||
var rightNode = new VNode("div", {}, [new VNode("div")]) | ||
|
||
assertPachedNodeIsMarked(leftNode, rightNode, assert) | ||
}) | ||
|
||
test("overrided createElement is used for patching vnodes", function (assert) { | ||
var leftNode = new VNode("div", {}, [new VNode("div")]) | ||
var rightNode = new VNode("div", {}, [new VNode("span")]) | ||
|
||
assertPachedNodeIsMarked(leftNode, rightNode, assert) | ||
}) | ||
|
||
test("overrided createElement is used for patching text nodes", function (assert) { | ||
var leftNode = new VNode("div", {}, [new VNode("div")]) | ||
var rightNode = new VNode("div", {}, [new VText("hello")]) | ||
|
||
assertPachedNodeIsMarked(leftNode, rightNode, assert) | ||
}) | ||
|
||
test("overrided createElement is used for patching widget nodes", function (assert) { | ||
var Widget = function (){} | ||
Widget.prototype.type = "Widget" | ||
Widget.prototype.init = function(){ return document.createElement("div") } | ||
Widget.prototype.update = function(previous, domNode){ return null } | ||
Widget.prototype.destroy = function(domNode){} | ||
|
||
var leftNode = new VNode("div", {}, [new VNode("div")]) | ||
var rightNode = new VNode("div", {}, [new Widget()]) | ||
|
||
assertPachedNodeIsMarked(leftNode, rightNode, assert) | ||
}) |