fix(react): prevent double invoking
closes #56
It maybe call many times, use Set.has() to judge seems better, likes:
const nativeEvents = /* #__PURE__ */ Object.keys(HTMLElement.prototype)
.filter(eventName => eventName.startsWith('on'))
.map(eventName => eventName.slice(2));
const nativeEventsSet = new Set(nativeEvents)
export function isNativeEvent(eventName: string) {
return nativeEventsSet.has(eventName)
};
Good idea, I've just added it.
In quark, such as dialog、radio has custom event 'close'、'change',
const nativeEvents = /* #__PURE__ */ Object.keys(HTMLElement.prototype) .filter(eventName => eventName.startsWith('on')) .map(eventName => eventName.slice(2));
nativeEvents alse has chaneg, this will filte quark custom event.
In quark, such as dialog、radio has custom event 'close'、'change',
const nativeEvents = /* #__PURE__ */ Object.keys(HTMLElement.prototype) .filter(eventName => eventName.startsWith('on')) .map(eventName => eventName.slice(2));nativeEvents alse has chaneg, this will filte quark custom event.
As I mentioned before, those events will be registered/updated by React itself when passing props to it.
https://github.com/hellof2e/quark-design/blob/a4c4b7f0b538b2d723a98c0809b156cbff154899/packages/quark-reactify/src/index.ts#L63
those onChange / onClick / onInput events will be passed to React in ...rest and then be registered.
The core logic:
All native events will be register by React.
Custom events should be register by quark manually using this.setEvent(...).
I've tested <Field> component.
This onFocus will also be triggered twice, because it matches native event.
<Field onFocus={(e) => console.log(e)}></Field>
~~But onChange don't trigger at all, so this is a bug from Field component itself. (should also be triggered twice as onFocus)~~
<Field onChange={(e) => console.log(e)}></Field>
I found that there are more to deal with, I'll try to fix this later.
The core logic: All native events will be register by React. Custom events should be register by quark manually using
this.setEvent(...).
@vaakian you are right。quark now has filter click、 focus、 blur ,other native event I think can not need be use in use quark.which scen can need use another native event ?
I will close this pr. if need, you can reopen it, thank you!