-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(EventEmitter): 新增事件链式注册,统一清除功能 #1968
Open
admin1949
wants to merge
5
commits into
didi:master
Choose a base branch
from
admin1949:feat-eventemiter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f1711fe
feat(EventEmitter): 新增事件链式注册,统一清除功能
fce7608
feat(feature-examples): 新增批量注册事件的示例代码
49be65a
feat(LogicFlow): 类型兼容使LogicFlow实例上的on和once方法兼容eventCenter的on和once
0f3885b
fix(EventEmitter): 修改类型命名
59950d3
feat(docs): 新增官网文档中关于EventCenter链式调用的介绍
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.viewport { | ||
position: relative; | ||
height: 80vh; | ||
overflow: hidden; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { FC, useEffect, useRef, useState } from 'react' | ||
import { Card, Button, Divider, message } from 'antd' | ||
import '@logicflow/core/es/index.css' | ||
import LogicFlow from '@logicflow/core' | ||
import styles from './batch-use.less' | ||
|
||
const Example: FC = () => { | ||
const [haRegist, setHaRegist] = useState(false) | ||
const refContainer = useRef<HTMLDivElement>(null) | ||
const lf = useRef<LogicFlow>() | ||
const [messageApi, contextHolder] = message.useMessage() | ||
|
||
useEffect(() => { | ||
const container = refContainer.current | ||
if (!container) { | ||
return | ||
} | ||
|
||
const instance = new LogicFlow({ | ||
container, | ||
}) | ||
|
||
instance.render({ | ||
nodes: [ | ||
{ | ||
type: 'rect', | ||
x: 100, | ||
y: 100, | ||
text: '节点1', | ||
properties: { | ||
name: '矩形', | ||
}, | ||
}, | ||
{ | ||
type: 'rect', | ||
x: 300, | ||
y: 100, | ||
text: '节点2', | ||
properties: { | ||
name: '矩形', | ||
}, | ||
}, | ||
], | ||
}) | ||
|
||
lf.current = instance | ||
return () => { | ||
instance.destroy() | ||
} | ||
}, []) | ||
|
||
const off = useRef(() => {}) | ||
|
||
const registerEvent = () => { | ||
if (!lf.current) { | ||
return | ||
} | ||
off.current = lf.current.graphModel.eventCenter | ||
.on('node:click', () => { | ||
messageApi.info('node click') | ||
}) | ||
.on('node:mouseenter', () => { | ||
messageApi.success('node mouseenter') | ||
}) | ||
.on('node:mouseleave', () => { | ||
messageApi.warning('node mouseleave') | ||
}) | ||
} | ||
|
||
const offEvent = () => { | ||
off.current() | ||
} | ||
|
||
const toggleEvent = () => { | ||
setHaRegist(!haRegist) | ||
if (haRegist) { | ||
offEvent() | ||
} else { | ||
registerEvent() | ||
} | ||
} | ||
return ( | ||
<Card title="批量注册事件"> | ||
{contextHolder} | ||
<div> | ||
<Button onClick={toggleEvent}> | ||
{haRegist ? '批量清除' : '批量注册'} | ||
</Button> | ||
</div> | ||
<Divider /> | ||
<div ref={refContainer} className={styles.viewport}></div> | ||
</Card> | ||
) | ||
} | ||
|
||
export default Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块儿有点问题,evt 不能直接写成 string,上面说的类型提示失效好像是这块儿的问题,得再确认一下