Match-id-5a0ba21295987c753666b977e0cb4ae7916d37f9
This commit is contained in:
commit
2d3e3ee6d0
25
.eslintrc.js
25
.eslintrc.js
|
@ -1,19 +1,13 @@
|
|||
module.exports = {
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
'plugin:@typescript-eslint/eslint-recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'prettier',
|
||||
],
|
||||
root: true,
|
||||
|
||||
plugins: [
|
||||
'jest',
|
||||
'no-for-of-loops',
|
||||
'no-function-declare-after-return',
|
||||
'react',
|
||||
'@typescript-eslint',
|
||||
],
|
||||
plugins: ['jest', 'no-for-of-loops', 'no-function-declare-after-return', 'react', '@typescript-eslint'],
|
||||
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
|
@ -34,8 +28,8 @@ module.exports = {
|
|||
rules: {
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'semi': ['warn', 'always'],
|
||||
'quotes': ['warn', 'single'],
|
||||
semi: ['warn', 'always'],
|
||||
quotes: ['warn', 'single'],
|
||||
'accessor-pairs': 'off',
|
||||
'brace-style': ['error', '1tbs'],
|
||||
'func-style': ['warn', 'declaration', { allowArrowFunctions: true }],
|
||||
|
@ -44,19 +38,18 @@ module.exports = {
|
|||
// 尾随逗号
|
||||
'comma-dangle': ['error', 'only-multiline'],
|
||||
|
||||
'no-constant-condition': 'off',
|
||||
'no-for-of-loops/no-for-of-loops': 'error',
|
||||
'no-function-declare-after-return/no-function-declare-after-return': 'error',
|
||||
},
|
||||
globals: {
|
||||
isDev: true
|
||||
isDev: true,
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: [
|
||||
'scripts/__tests__/**/*.js'
|
||||
],
|
||||
files: ['scripts/__tests__/**/*.js'],
|
||||
globals: {
|
||||
container: true
|
||||
container: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
@ -6,7 +6,7 @@ import {Props} from '../DOMOperator';
|
|||
* @param doc 指定 document
|
||||
*/
|
||||
export function getFocusedDom(doc?: Document): HorizonDom | null {
|
||||
let currentDocument = doc ?? document;
|
||||
const currentDocument = doc ?? document;
|
||||
|
||||
return currentDocument.activeElement ?? currentDocument.body;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ export function recoverParentContext(vNode: VNode) {
|
|||
|
||||
while (parent !== null) {
|
||||
if (parent.tag === ContextProvider) {
|
||||
parent.context = parent.props.value;
|
||||
setContext(parent, parent.props.value);
|
||||
}
|
||||
parent = parent.parent;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ const typeMap = {
|
|||
[TYPE_LAZY]: LazyComponent,
|
||||
};
|
||||
|
||||
function newVirtualNode (tag: VNodeTag, key?: null | string, vNodeProps?: any, realNode?: any): VNode {
|
||||
function newVirtualNode(tag: VNodeTag, key?: null | string, vNodeProps?: any, realNode?: any): VNode {
|
||||
return new VNode(tag, vNodeProps, key, realNode);
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,7 @@ export function onlyUpdateChildVNodes(processing: VNode): VNode | null {
|
|||
sibling = sibling.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
putChildrenIntoQueue(processing.child);
|
||||
|
||||
|
@ -210,7 +210,7 @@ export function onlyUpdateChildVNodes(processing: VNode): VNode | null {
|
|||
|
||||
markVNodePath(vNode);
|
||||
|
||||
putChildrenIntoQueue(vNode)
|
||||
putChildrenIntoQueue(vNode);
|
||||
}
|
||||
}
|
||||
// 子树无需工作
|
||||
|
|
|
@ -53,7 +53,7 @@ export function setParentsChildShouldUpdate(parent: VNode | null) {
|
|||
// 设置节点的所有父节点的childShouldUpdate
|
||||
export function updateParentsChildShouldUpdate(vNode: VNode) {
|
||||
let node = vNode.parent;
|
||||
let isShouldUpdate = vNode.shouldUpdate || vNode.childShouldUpdate;
|
||||
const isShouldUpdate = vNode.shouldUpdate || vNode.childShouldUpdate;
|
||||
|
||||
if (isShouldUpdate) { // 开始节点是shouldUpdate或childShouldUpdate
|
||||
// 更新从当前节点到根节点的childShouldUpdate为true
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as Horizon from '@cloudsop/horizon/index.ts';
|
||||
|
||||
describe('useContext Hook Test', () => {
|
||||
const { useState, useContext, act, unmountComponentAtNode } = Horizon;
|
||||
const { useState, useContext, createContext, act, unmountComponentAtNode } = Horizon;
|
||||
|
||||
it('简单使用useContext', () => {
|
||||
const LanguageTypes = {
|
||||
|
@ -45,4 +45,38 @@ describe('useContext Hook Test', () => {
|
|||
act(() => setValue(LanguageTypes.JAVASCRIPT));
|
||||
expect(container.querySelector('p').innerHTML).toBe('JavaScript');
|
||||
});
|
||||
|
||||
it('更新后useContext仍能获取到context', () => {
|
||||
const Context = createContext({});
|
||||
const ref = Horizon.createRef();
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Context.Provider
|
||||
value={{
|
||||
text: 'context',
|
||||
}}
|
||||
>
|
||||
<Child />
|
||||
</Context.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
let update;
|
||||
|
||||
function Child() {
|
||||
const context = useContext(Context);
|
||||
const [_, setState] = useState({});
|
||||
update = () => setState({});
|
||||
|
||||
return <div ref={ref}>{context.text}</div>;
|
||||
}
|
||||
|
||||
Horizon.render(<App />, container);
|
||||
expect(ref.current.innerHTML).toBe('context');
|
||||
|
||||
update();
|
||||
|
||||
expect(ref.current.innerHTML).toBe('context');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue