Skip to content

Commit 754eb8f

Browse files
committed
chore: support IE11 without polyfills and transpiling
1 parent b44c4b9 commit 754eb8f

File tree

15 files changed

+2110
-183
lines changed

15 files changed

+2110
-183
lines changed

benchmark/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const benchmark = require('benchmark')
2+
const fs = require('fs')
3+
const jsdom = require('jsdom')
4+
const path = require('path')
5+
const diff = require('../lib/diff')
6+
7+
const oldPath = path.join(__dirname, 'old.html')
8+
const newPath = path.join(__dirname, 'new.html')
9+
const oldHtml = fs.readFileSync(oldPath, 'utf8')
10+
const newHtml = fs.readFileSync(newPath, 'utf8')
11+
const oldNode = new jsdom.JSDOM(oldHtml).window.document.body
12+
const newNode = new jsdom.JSDOM(newHtml).window.document.body
13+
14+
const suite = new benchmark.Suite()
15+
suite.add('diff', () => {
16+
diff.visualDomDiff(oldNode, newNode)
17+
})
18+
suite.on('cycle', function(event) {
19+
console.log(String(event.target))
20+
})
21+
suite.run({ async: true })

benchmark/new.html

Lines changed: 833 additions & 0 deletions
Large diffs are not rendered by default.

benchmark/old.html

Lines changed: 833 additions & 0 deletions
Large diffs are not rendered by default.

demo/main.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ import 'regenerator-runtime/runtime'
33
import { visualDomDiff } from '../lib'
44
import './main.css'
55

6-
window.addEventListener('load', () => {
6+
window.addEventListener('load', function() {
77
const input1Html = document.getElementById('input1-html')
88
const input1 = document.getElementById('input1')
99
const input2Html = document.getElementById('input2-html')
1010
const input2 = document.getElementById('input2')
1111
const outputHtml = document.getElementById('output-html')
1212
const output = document.getElementById('output')
13-
const updateInput1 = () => {
13+
const updateInput1 = function() {
1414
input1.firstChild.innerHTML = input1Html.value
1515
}
16-
const updateInput2 = () => {
16+
const updateInput2 = function() {
1717
input2.firstChild.innerHTML = input2Html.value
1818
}
19-
const updateDiff = () => {
19+
const updateDiff = function() {
2020
output.innerHTML = ''
2121
output.appendChild(visualDomDiff(input1.firstChild, input2.firstChild))
2222
outputHtml.value = output.innerHTML
2323
}
2424

25-
input1Html.addEventListener('input', () => {
25+
input1Html.addEventListener('input', function() {
2626
updateInput1()
2727
updateDiff()
2828
})
29-
input2Html.addEventListener('input', () => {
29+
input2Html.addEventListener('input', function() {
3030
updateInput2()
3131
updateDiff()
3232
})

jest.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ module.exports = {
22
preset: 'ts-jest',
33
setupFiles: ['<rootDir>/scripts/jestSetUp'],
44
testMatch: [`<rootDir>/src/**/*.test.ts`],
5+
testEnvironment: 'node',
56
collectCoverage: true,
67
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.test.{ts,tsx}'],
78
coverageThreshold: {
89
global: {
910
branches: 100,
1011
functions: 100,
1112
lines: 100,
12-
statements: 100
13-
}
14-
}
13+
statements: 100,
14+
},
15+
},
1516
}

package-lock.json

Lines changed: 34 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
],
1212
"scripts": {
1313
"clean": "rimraf lib",
14+
"prettier-fix": "prettier \"./src/**/*\" \"./demo/**/*\" \"!./**/*.jpg\" --list-different --write",
1415
"prettier": "prettier \"./src/**/*\" \"./demo/**/*\" \"!./**/*.jpg\" --list-different",
1516
"tslint": "tslint --project .",
1617
"tsc": "tsc -b .",
@@ -21,7 +22,8 @@
2122
"start:demo": "webpack-dev-server -d",
2223
"start:tsc": "tsc -b -w .",
2324
"preversion": "npm outdated && run-s build demo && git add docs",
24-
"postversion": "git push && git push origin v${npm_package_version}"
25+
"postversion": "git push && git push origin v${npm_package_version}",
26+
"benchmark": "node benchmark"
2527
},
2628
"repository": {
2729
"type": "git",
@@ -48,6 +50,7 @@
4850
"@types/jest": "^24.0.18",
4951
"@types/jsdom": "^12.2.4",
5052
"babel-loader": "^8.0.6",
53+
"benchmark": "^2.1.4",
5154
"clean-webpack-plugin": "^3.0.0",
5255
"core-js": "^3.2.1",
5356
"css-loader": "^3.2.0",

src/config.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Diff } from 'diff-match-patch'
2+
import { JSDOM } from 'jsdom'
23
import { optionsToConfig } from './config'
34
import { diffText, isComment, isDocumentFragment, isText } from './util'
45

6+
const document = new JSDOM('').window.document
57
const text = document.createTextNode('text')
68
const span = document.createElement('SPAN')
79
const div = document.createElement('DIV')

src/diff.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { areNodesEqual, charForNodeName, isElement, isText } from './util'
66

77
jest.setTimeout(2000)
88

9+
const document = new JSDOM('').window.document
910
const pChar = charForNodeName('P')
1011

1112
function fragmentToHtml(documentFragment: DocumentFragment): string {

0 commit comments

Comments
 (0)