Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
fix: componentWillUnmount triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
zeromake committed Sep 26, 2017
1 parent 637a2e4 commit 11fd90f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"build:compat": "cross-env DEVTOOLS_ENV=production NODE_ENV=dev rollup -c config/rollup.compat.config.js",
"dev": "cross-env DEVTOOLS_ENV=production NODE_ENV=dev rollup -c config/rollup.config.js -w",
"test": "tslint src/**/*.ts && tsc && npm run test:karma",
"test:karma": "karma start test/karma.conf.js --single-run && npm run ts-coverage-html && npm run ts-coverage-lcov",
"test:karma": "karma start test/karma.conf.js --single-run && npm run ts-coverage-lcov",
"test:karma:watch": "npm run test:karma -- no-single-run",
"ts-coverage-html": "remap-istanbul -i test/coverage/coverage-final.json -o test/coverage/html -t html -e node_modules,test",
"ts-coverage-lcov": "remap-istanbul -i test/coverage/coverage-final.json -o test/coverage/lcov.info -t lcovonly -e node_modules,test",
Expand Down Expand Up @@ -80,6 +80,7 @@
"karma-webpack": "^2.0.4",
"mocha": "^3.4.2",
"preact-jsx-chai": "^2.2.1",
"preact-render-to-string": "^3.6.3",
"prop-types": "^15.5.10",
"remap-istanbul": "^0.9.5",
"rimraf": "^2.6.1",
Expand All @@ -97,8 +98,5 @@
"typescript": "^2.5.2",
"uglify-es": "^3.1.1",
"webpack": "^3.6.0"
},
"dependencies": {
"preact-render-to-string": "^3.6.3"
}
}
2 changes: 1 addition & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const options: {
*/
eventBind?: boolean;
/**
* ref 默认为vdom,
* ref 默认为vdom,
*/
ref?: ((vdom: IVDom) => any) | boolean;
} = {
Expand Down
26 changes: 14 additions & 12 deletions src/vdom/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ function diffChildren(
}
}
if (vlen !== 0) {
let offset = 0;
for (let i = 0; i < vlen; i++) {
vchild = vchildren[i];
child = null;
Expand Down Expand Up @@ -327,7 +328,7 @@ function diffChildren(
// morph the matched/found/created DOM child to match vchild (deep)
const pchild = idiff(child, vchild, context, mountAll, false);
// 获取真实
f = originalChildren[i];
f = originalChildren[i + offset];
if (pchild.base !== vdom.base && pchild.base !== f) {
if (f == null) {
vdom.base.appendChild(pchild.base);
Expand All @@ -345,16 +346,17 @@ function diffChildren(
// ```
const fvdom = (f as any)._vdom as IVDom;
if ( fvdom && fvdom.component) {
recollectNodeTree(fvdom, false);
const fkey = fvdom.component._key;
if (fkey && fkey in keyed) {
keyed[fkey] = undefined;
} else {
const findex = children.indexOf(fvdom);
if (findex > -1) {
children[findex] = undefined;
}
}
offset ++;
// recollectNodeTree(fvdom, false);
// const fkey = fvdom.component._key;
// if (fkey && fkey in keyed) {
// keyed[fkey] = undefined;
// } else {
// const findex = children.indexOf(fvdom);
// if (findex > -1) {
// children[findex] = undefined;
// }
// }
} else {
removeNode(f as any);
}
Expand All @@ -381,7 +383,7 @@ function diffChildren(
child = children[childrenLen--];
if (child !== undefined) {
// console.log("---removeChildren----", child);
// removeNode(child.base);
// removeNode(child.base);2
recollectNodeTree(child, false);
}
}
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1199,8 +1199,8 @@ camelcase@^4.1.0:
resolved "http://registry.npm.taobao.org/camelcase/download/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd"

caniuse-lite@^1.0.30000718:
version "1.0.30000735"
resolved "http://registry.npm.taobao.org/caniuse-lite/download/caniuse-lite-1.0.30000735.tgz#aab44016ef243e215ef43fd1343efd22930842f8"
version "1.0.30000737"
resolved "http://registry.npm.taobao.org/caniuse-lite/download/caniuse-lite-1.0.30000737.tgz#8199a601dd54c096e1f8567bcb7461b94f0d4509"

caseless@~0.11.0:
version "0.11.0"
Expand Down Expand Up @@ -1820,8 +1820,8 @@ ee-first@1.1.1:
resolved "http://registry.npm.taobao.org/ee-first/download/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"

electron-to-chromium@^1.3.18:
version "1.3.21"
resolved "http://registry.npm.taobao.org/electron-to-chromium/download/electron-to-chromium-1.3.21.tgz#a967ebdcfe8ed0083fc244d1894022a8e8113ea2"
version "1.3.22"
resolved "http://registry.npm.taobao.org/electron-to-chromium/download/electron-to-chromium-1.3.22.tgz#4322d52c151406e3eaef74ad02676883e8416418"

elliptic@^6.0.0:
version "6.4.0"
Expand Down Expand Up @@ -5041,8 +5041,8 @@ ua-parser-js@^0.7.9:
resolved "http://registry.npm.taobao.org/ua-parser-js/download/ua-parser-js-0.7.14.tgz#110d53fa4c3f326c121292bbeac904d2e03387ca"

uglify-es@^3.1.1:
version "3.1.1"
resolved "http://registry.npm.taobao.org/uglify-es/download/uglify-es-3.1.1.tgz#27615a1203cd0b351d8b5bda743ac92ed482b826"
version "3.1.2"
resolved "http://registry.npm.taobao.org/uglify-es/download/uglify-es-3.1.2.tgz#b22cfca950f0632092aff42bb46979d83b5ec6f5"
dependencies:
commander "~2.11.0"
source-map "~0.5.1"
Expand All @@ -5061,8 +5061,8 @@ uglify-js@^2.6, uglify-js@^2.8.29:
uglify-to-browserify "~1.0.0"

uglify-js@^3.0.9:
version "3.1.1"
resolved "http://registry.npm.taobao.org/uglify-js/download/uglify-js-3.1.1.tgz#e7144307281a1bc38a9a20715090b546c9f44791"
version "3.1.2"
resolved "http://registry.npm.taobao.org/uglify-js/download/uglify-js-3.1.2.tgz#b50bcf15a5fd9e9ed40afbcdef3b59d6891b291f"
dependencies:
commander "~2.11.0"
source-map "~0.5.1"
Expand Down

0 comments on commit 11fd90f

Please sign in to comment.