-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add modify-value test by @matthewwolfe, fix value bug when value is a…
…n emoty string, increase version to 2.0.3, fixes #40
- Loading branch information
1 parent
6bb9b28
commit 6531b95
Showing
5 changed files
with
76 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "diff-dom", | ||
"main": "diffDOM.js", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"homepage": "https://github.com/fiduswriter/diffDOM", | ||
"authors": [ | ||
"Johannes Wilm <[email protected]>" | ||
|
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
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,69 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<script src="../diffDOM.js"> | ||
</script> | ||
<script> | ||
|
||
document.addEventListener("DOMContentLoaded", function(event) { | ||
// ------------- Testing the issue -------------------- // | ||
// ---------------------------------------------------- // | ||
|
||
var dd = new diffDOM(); | ||
|
||
// create two sets of identical html | ||
var element1 = document.createElement('form'); | ||
|
||
var input = document.createElement('input'); | ||
input.setAttribute('type', 'text'); | ||
input.setAttribute('value', 'testing'); | ||
|
||
var submit = document.createElement('input'); | ||
submit.setAttribute('type', 'submit'); | ||
|
||
var instructions = document.createElement('div'); | ||
instructions.innerHTML = '<p>1. Change the text<br>2. Click "submit" once<br>\ | ||
3. Check if the input field value stays the same<br>4. Click "submit" a\ | ||
second time<br>5. Check if input field is empty.</p>'; | ||
|
||
document.body.appendChild(instructions); | ||
|
||
element1.appendChild(input); | ||
element1.appendChild(submit); | ||
|
||
document.body.appendChild(element1); | ||
|
||
// element2 will remain virtual, and we will diff element1 with element2 | ||
// to determine if we actually need to update the DOM or not. | ||
var element2 = element1.cloneNode(true); | ||
|
||
// event listener for when the input value changes | ||
element1.addEventListener('input', function(e){ | ||
// update the virtual element, then diff and see if there needs to be updates | ||
element2.firstChild.setAttribute('value', e.target.value); | ||
|
||
var diff = dd.diff(element1, element2); | ||
dd.apply(element1, diff); | ||
|
||
console.log(diff); | ||
}); | ||
|
||
// event listener for pressing the submit button | ||
element1.addEventListener('submit', function(e){ | ||
e.preventDefault(); | ||
|
||
// update the virtual element, then diff and see if there needs to be updates | ||
element2.firstChild.setAttribute('value', ''); | ||
|
||
var diff = dd.diff(element1, element2); | ||
dd.apply(element1, diff); | ||
|
||
console.log(diff); | ||
}); | ||
|
||
}); | ||
</script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |