import { clone , each , wrapBehavior } from '@antv/util' ; import { BehaviorOption } from '../types' ; import behaviorOption from './behaviorOption' ; export default class Behavior { private static types = { } ; param type param behavior public static registerBehavior ( type , behavior ) { if ( ! behavior ) { throw new Error ( `please specify handler for this behavior: ${ type }` ) ; } const prototype = clone ( behaviorOption ) ; Object . assign ( prototype , behavior ) ; const base = function ( cfg ) { Object . assign ( this , this . getDefaultCfg ( ) , cfg ) ; const events = this . getEvents ( ) ; this . events = null ; const eventsToBind = { } ; if ( events ) { each ( events , ( handle , event ) => { eventsToBind [ event ] = wrapBehavior ( this , handle ) ; } ) ; this . events = eventsToBind ; } } ; base . prototype = prototype ; Behavior . types [ type ] = base ; } public static hasBehavior ( type ) { return ! ! Behavior . types [ type ] ; } public static getBehavior ( type ) { return Behavior . types [ type ] ; } }