@@ -92,22 +92,32 @@ class PluginEditor extends Component {
92
92
93
93
createPluginHooks = ( ) => {
94
94
const pluginHooks = { } ;
95
+ const eventHookKeys = [ ] ;
96
+ const fnHookKeys = [ ] ;
95
97
const plugins = this . resolvePlugins ( ) ;
96
98
97
99
plugins . forEach ( ( plugin ) => {
98
100
Object . keys ( plugin ) . forEach ( ( attrName ) => {
99
- if ( pluginHooks [ attrName ] || attrName === 'onChange' ) return ;
100
-
101
- if ( attrName . indexOf ( 'on' ) === 0 || attrName . indexOf ( 'handle' ) === 0 ) {
102
- pluginHooks [ attrName ] = this . createEventHooks ( attrName , plugins ) ;
101
+ if ( attrName === 'onChange' ) return ;
102
+
103
+ // if `attrName` has been added as a hook key already, ignore this one
104
+ if ( eventHookKeys . indexOf ( attrName ) !== - 1 || fnHookKeys . indexOf ( attrName ) !== - 1 ) return ;
105
+
106
+ const isEventHookKey = attrName . indexOf ( 'on' ) === 0 || attrName . indexOf ( 'handle' ) === 0 ;
107
+ if ( isEventHookKey ) {
108
+ eventHookKeys . push ( attrName ) ;
109
+ return ;
103
110
}
104
111
105
- // checks if the function ends with Fn
106
- if ( attrName . length - 2 === attrName . indexOf ( 'Fn' ) ) {
107
- pluginHooks [ attrName ] = this . createFnHooks ( attrName , plugins ) ;
112
+ // checks if the `attrName` ends with 'Fn'
113
+ const isFnHookKey = ( attrName . length - 2 === attrName . indexOf ( 'Fn' ) ) ;
114
+ if ( isFnHookKey ) {
115
+ fnHookKeys . push ( attrName ) ;
108
116
}
109
117
} ) ;
110
118
} ) ;
119
+ eventHookKeys . forEach ( ( attrName ) => pluginHooks [ attrName ] = this . createEventHooks ( attrName , plugins ) ) ;
120
+ fnHookKeys . forEach ( ( attrName ) => pluginHooks [ attrName ] = this . createFnHooks ( attrName , plugins ) ) ;
111
121
return pluginHooks ;
112
122
} ;
113
123
0 commit comments