mirror of
https://gitee.com/antv/g6.git
synced 2024-12-03 20:28:36 +08:00
fix: behavior type error. closes: #1303.
This commit is contained in:
parent
d04130bbe9
commit
a261d98518
@ -1,6 +1,30 @@
|
||||
import { clone, each, wrapBehavior } from '@antv/util/lib';
|
||||
import { BehaviorOption } from '../types';
|
||||
import { ModelConfig, DefaultBehaviorType } from '../types';
|
||||
import behaviorOption from './behaviorOption';
|
||||
import { IGraph } from '../interface/graph';
|
||||
import { G6Event } from '../types';
|
||||
|
||||
type GetEvents = 'getEvents';
|
||||
type ShouldBegin = 'shouldBegin';
|
||||
type ShouldUpdate = 'shouldUpdate';
|
||||
type ShouldEnd = 'shouldEnd';
|
||||
type Bind = 'bind';
|
||||
type Unbind = 'unbind';
|
||||
type BehaviorOption<U> = {
|
||||
[T in keyof U]: T extends GetEvents
|
||||
? () => { [key in G6Event]?: string }
|
||||
: T extends ShouldBegin
|
||||
? (cfg?: ModelConfig) => boolean
|
||||
: T extends ShouldEnd
|
||||
? (cfg?: ModelConfig) => boolean
|
||||
: T extends ShouldUpdate
|
||||
? (cfg?: ModelConfig) => boolean
|
||||
: T extends Bind
|
||||
? (graph: IGraph) => void
|
||||
: T extends Unbind
|
||||
? (graph: IGraph) => void
|
||||
: (...args: DefaultBehaviorType[]) => unknown;
|
||||
};
|
||||
|
||||
export default class Behavior {
|
||||
// 所有自定义的 Behavior 的实例
|
||||
@ -11,7 +35,7 @@ export default class Behavior {
|
||||
* @param type Behavior 名称
|
||||
* @param behavior Behavior 定义的方法集合
|
||||
*/
|
||||
public static registerBehavior(type: string, behavior: BehaviorOption) {
|
||||
public static registerBehavior<T, U>(type: string, behavior: BehaviorOption<U>) {
|
||||
if (!behavior) {
|
||||
throw new Error(`please specify handler for this behavior: ${type}`);
|
||||
}
|
||||
|
@ -352,7 +352,6 @@ export interface BehaviorOption {
|
||||
shouldEnd?(e?: IG6GraphEvent): boolean;
|
||||
bind?(e: IGraph): void;
|
||||
unbind?(e: IGraph): void;
|
||||
[key: string]: (...args) => any;
|
||||
}
|
||||
|
||||
export type IEvent = Record<G6Event, string>;
|
||||
|
Loading…
Reference in New Issue
Block a user