From 7a31f313c61a31b4f80f509926baba4fab577b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E9=A2=82?= <313439271@qq.com> Date: Thu, 7 Jan 2021 02:51:24 +0000 Subject: [PATCH] =?UTF-8?q?chore(=F0=9F=A4=96):1.7.5=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [1.7.5](https://github.com/lizheming/anu/compare/v1.7.4...v1.7.5) (2021-01-07) ### Bug Fixes * [#11](https://github.com/lizheming/anu/issues/11) useEffect destroy函数执行时机不对 ([#13](https://github.com/lizheming/anu/issues/13)) ([c472319](https://github.com/lizheming/anu/commit/c47231909fd89578678b739bbe3c4c3961f401a4)) --- dist/React.js | 58 +++++++++++++++++++++++-------------------------- dist/ReactIE.js | 58 +++++++++++++++++++++++-------------------------- package.json | 2 +- 3 files changed, 55 insertions(+), 63 deletions(-) diff --git a/dist/React.js b/dist/React.js index 572f22852..57492df7d 100644 --- a/dist/React.js +++ b/dist/React.js @@ -1,5 +1,5 @@ /** - * by 司徒正美 Copyright 2020-11-03 + * by 司徒正美 Copyright 2021-01-07 * IE9+ */ @@ -754,15 +754,15 @@ } function useEffectImpl(create, deps, EffectTag, createList, destroyList) { var fiber = getCurrentFiber(); + var hookIndex = hookCursor; var updateQueue = fiber.updateQueue; - if (useCallbackImpl(create, deps, false, true)) { - if (fiber.effectTag % EffectTag) { - fiber.effectTag *= EffectTag; - } - var list = updateQueue[createList] || (updateQueue[createList] = []); - updateQueue[destroyList] || (updateQueue[destroyList] = []); - list.push(create); + var depsChange = !!useCallbackImpl(create, deps, false, true); + if (depsChange && fiber.effectTag % EffectTag) { + fiber.effectTag *= EffectTag; } + updateQueue[createList] || (updateQueue[createList] = []); + updateQueue[destroyList] || (updateQueue[destroyList] = []); + updateQueue[createList][hookIndex] = depsChange && create; } function useRef(initValue) { var fiber = getCurrentFiber(); @@ -2827,28 +2827,24 @@ delete fiber.oldChildren; fiber.children = {}; } - function safeInvokeHooks(upateQueue, create, destory) { - var uneffects = upateQueue[destory], - effects$$1 = upateQueue[create], - fn; - if (!uneffects) { - return; - } - while (fn = uneffects.shift()) { - try { - fn(); - } catch (e) { - } - } - while (fn = effects$$1.shift()) { - try { - var f = fn(); - if (typeof f === 'function') { - uneffects.push(f); + function safeInvokeHooks(upateQueue, create, destory, isUnmount) { + var prevDestroyList = upateQueue[destory]; + var curCreateList = upateQueue[create]; + curCreateList && curCreateList.forEach(function (createFn, i) { + var depsChange = typeof createFn === 'function'; + if (depsChange || isUnmount) { + var prevDestroyFn = prevDestroyList[i]; + if (typeof prevDestroyFn === 'function') { + prevDestroyFn(); } - } catch (e) { } - } + }); + !isUnmount && curCreateList && curCreateList.forEach(function (createFn, i) { + if (typeof createFn === 'function') { + var destroyFn = createFn(); + prevDestroyList[i] = destroyFn; + } + }); } function disposeFiber(fiber, force) { var stateNode = fiber.stateNode, @@ -2867,8 +2863,8 @@ Renderer.onDispose(fiber); if (fiber.hasMounted) { if (isStateless) { - safeInvokeHooks(fiber.updateQueue, 'layout', 'unlayout'); - safeInvokeHooks(fiber.updateQueue, 'passive', 'unpassive'); + safeInvokeHooks(fiber.updateQueue, 'layout', 'unlayout', true); + safeInvokeHooks(fiber.updateQueue, 'passive', 'unpassive', true); } stateNode.updater.enqueueSetState = returnFalse; guardCallback(stateNode, 'componentWillUnmount', []); @@ -3338,7 +3334,7 @@ findDOMNode: findDOMNode, unmountComponentAtNode: unmountComponentAtNode, unstable_renderSubtreeIntoContainer: unstable_renderSubtreeIntoContainer, - version: '1.7.3', + version: '1.7.4', render: render$1, hydrate: render$1, unstable_batchedUpdates: DOMRenderer.batchedUpdates, diff --git a/dist/ReactIE.js b/dist/ReactIE.js index 00f299e93..ca6998c60 100644 --- a/dist/ReactIE.js +++ b/dist/ReactIE.js @@ -1,5 +1,5 @@ /** - * IE6+,有问题请加QQ 370262116 by 司徒正美 Copyright 2020-11-03 + * IE6+,有问题请加QQ 370262116 by 司徒正美 Copyright 2021-01-07 */ (function (global, factory) { @@ -2048,15 +2048,15 @@ } function useEffectImpl(create, deps, EffectTag, createList, destroyList) { var fiber = getCurrentFiber(); + var hookIndex = hookCursor; var updateQueue = fiber.updateQueue; - if (useCallbackImpl(create, deps, false, true)) { - if (fiber.effectTag % EffectTag) { - fiber.effectTag *= EffectTag; - } - var list = updateQueue[createList] || (updateQueue[createList] = []); - updateQueue[destroyList] || (updateQueue[destroyList] = []); - list.push(create); + var depsChange = !!useCallbackImpl(create, deps, false, true); + if (depsChange && fiber.effectTag % EffectTag) { + fiber.effectTag *= EffectTag; } + updateQueue[createList] || (updateQueue[createList] = []); + updateQueue[destroyList] || (updateQueue[destroyList] = []); + updateQueue[createList][hookIndex] = depsChange && create; } function useRef(initValue) { var fiber = getCurrentFiber(); @@ -2752,28 +2752,24 @@ delete fiber.oldChildren; fiber.children = {}; } - function safeInvokeHooks(upateQueue, create, destory) { - var uneffects = upateQueue[destory], - effects$$1 = upateQueue[create], - fn; - if (!uneffects) { - return; - } - while (fn = uneffects.shift()) { - try { - fn(); - } catch (e) { - } - } - while (fn = effects$$1.shift()) { - try { - var f = fn(); - if (typeof f === 'function') { - uneffects.push(f); + function safeInvokeHooks(upateQueue, create, destory, isUnmount) { + var prevDestroyList = upateQueue[destory]; + var curCreateList = upateQueue[create]; + curCreateList && curCreateList.forEach(function (createFn, i) { + var depsChange = typeof createFn === 'function'; + if (depsChange || isUnmount) { + var prevDestroyFn = prevDestroyList[i]; + if (typeof prevDestroyFn === 'function') { + prevDestroyFn(); } - } catch (e) { } - } + }); + !isUnmount && curCreateList && curCreateList.forEach(function (createFn, i) { + if (typeof createFn === 'function') { + var destroyFn = createFn(); + prevDestroyList[i] = destroyFn; + } + }); } function disposeFiber(fiber, force) { var stateNode = fiber.stateNode, @@ -2792,8 +2788,8 @@ Renderer.onDispose(fiber); if (fiber.hasMounted) { if (isStateless) { - safeInvokeHooks(fiber.updateQueue, 'layout', 'unlayout'); - safeInvokeHooks(fiber.updateQueue, 'passive', 'unpassive'); + safeInvokeHooks(fiber.updateQueue, 'layout', 'unlayout', true); + safeInvokeHooks(fiber.updateQueue, 'passive', 'unpassive', true); } stateNode.updater.enqueueSetState = returnFalse; guardCallback(stateNode, 'componentWillUnmount', []); @@ -3463,7 +3459,7 @@ unmountComponentAtNode: unmountComponentAtNode, unstable_renderSubtreeIntoContainer: unstable_renderSubtreeIntoContainer, miniCreateClass: miniCreateClass, - version: '1.7.3', + version: '1.7.4', render: render$1, hydrate: render$1, unstable_batchedUpdates: DOMRenderer.batchedUpdates, diff --git a/package.json b/package.json index c47307dc2..b78d93a29 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anujs", - "version": "1.7.4", + "version": "1.7.5", "description": "a React16-compact mini framework", "main": "dist/React.js", "scripts": {