diff --git a/docs/index.md b/docs/index.md index 9e2db9bc1a8..646580a3f6c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,132 +1 @@ ---- -title: Formily - Alibaba unified front-end form solution -order: 10 -hero: - title: Alibaba Formily - desc: Alibaba Unified Front-end Form Solution - actions: - - text: Introduction - link: /guide - - text: Quick start - link: /guide/quick-start -features: - - icon: https://img.alicdn.com/imgextra/i2/O1CN016i72sH1c5wh1kyy9U_!!6000000003550-55-tps-800-800.svg - title: Easier to Use - desc: Out of the box, rich cases - - icon: https://img.alicdn.com/imgextra/i1/O1CN01bHdrZJ1rEOESvXEi5_!!6000000005599-55-tps-800-800.svg - title: More Efficient - desc: Fool writing, ultra-high performance - - icon: https://img.alicdn.com/imgextra/i3/O1CN01xlETZk1G0WSQT6Xii_!!6000000000560-55-tps-800-800.svg - title: More Professional - desc: Complete, flexible and elegant -footer: Open-source MIT Licensed | Copyright © 2019-present
Powered by self ---- - -```tsx -/** - * inline: true - */ -import React from 'react' -import { Section } from './site/Section' -import './site/styles.less' - -export default () => ( -
- -
-) -``` - -```tsx -/** - * inline: true - */ -import React from 'react' -import { Section } from './site/Section' -import './site/styles.less' - -export default () => ( -
- - - -
-) -``` - -```tsx -/** - * inline: true - */ -import React from 'react' -import { Section } from './site/Section' -import './site/styles.less' - -export default () => ( -
- - - -
-) -``` - -```tsx -/** - * inline: true - */ -import React from 'react' -import { Section } from './site/Section' -import { Contributors } from './site/Contributors' -import './site/styles.less' - -export default () => ( -
- -
-) -``` - -```tsx -/** - * inline: true - */ -import React from 'react' -import { Section } from './site/Section' -import { QrCode, QrCodeGroup } from './site/QrCode' -import './site/styles.less' - -export default () => ( -
- - - -
-) -``` + diff --git a/docs/index.tsx b/docs/index.tsx new file mode 100644 index 00000000000..22e56f15428 --- /dev/null +++ b/docs/index.tsx @@ -0,0 +1,98 @@ +import React from 'react' + +import { autorun, batch, reaction, observable } from '@formily/reactive' + +const fieldA = observable({ + value: '', + visible: true, +}) + +const fieldB = observable({ + value: '', + visible: true, + cache: '', +}) + +const fieldC = observable({ + value: '', + visible: true, + cache: '', +}) + +// ===== fieldB reaction ===== +reaction( + () => fieldB.value, + () => { + if (fieldB.value && fieldB.visible === false) { + fieldB.cache = fieldB.value + // 删除 fieldB.value 时,会重新 runReaction + delete fieldB.value + } + } +) + +reaction( + () => fieldB.visible, + () => { + if (fieldB.visible === true) { + // debugger + console.log('fieldB.cache: ', fieldB.cache) + // 执行到这里时,不会执行 fieldB.value 的 autorun,因为在上面 delete fieldB.value 时,已经执行了 + fieldB.value = fieldB.cache + } + } +) + +// ===== fieldC reaction ===== +reaction( + () => fieldC.value, + () => { + if (fieldC.value && fieldC.visible === false) { + fieldC.cache = fieldC.value + delete fieldC.value + } + } +) + +reaction( + () => fieldC.visible, + () => { + if (fieldC.visible === true) { + fieldC.value = fieldC.cache + } + } +) + +// ===== schema 渲染 ===== +autorun(() => { + fieldB.visible = fieldA.value === 'fieldA' +}, 'A') + +autorun(() => { + fieldC.visible = fieldB.value === 'fieldB' +}, 'B') + +// fieldB.value = 'fieldB' +// fieldC.value = 'fieldC' +// fieldA.value = 'fieldA' + +batch(() => { + fieldB.value = 'fieldB' + fieldC.value = 'fieldC' + // debugger + fieldA.value = 'fieldA' + // window.xxx = true +}) + +console.log( + 'fieldA.visible:', + fieldA.visible, + 'fieldB.visible:', + fieldB.visible, + 'fieldC.visible:', + fieldC.visible +) + +const App = () =>
123123
+ +export default App diff --git a/packages/reactive/src/autorun.ts b/packages/reactive/src/autorun.ts index eb02aab34b3..adc63113880 100644 --- a/packages/reactive/src/autorun.ts +++ b/packages/reactive/src/autorun.ts @@ -33,16 +33,16 @@ export const autorun = (tracker: Reaction, name = 'AutoRun') => { ReactionStack.pop() const key = reaction._updateKey + const target = reaction._updateTarget if (key) { - const keys = - reaction._boundary.get(reaction._updateTarget) || new Set([]) + const keys = reaction._boundary.get(target) || new Set([]) keys.add(key) - reaction._boundary.set(reaction._updateTarget, keys) + reaction._boundary.set(target, keys) } batchEnd() - const keys = reaction._boundary.get(reaction._updateTarget) + const keys = reaction._boundary.get(target) if (keys) { keys.delete(key) }