@dark-engine/platform-desktop
Version:
Dark renderer to desktop platforms like Windows, Linux, macOS via Nodegui and Qt
33 lines (32 loc) • 903 B
JavaScript
import { useMemo, $$scope } from '@dark-engine/core';
class SyntheticEvent {
type = '';
value = null;
constructor(options) {
this.type = options.type;
this.value = options.value;
}
}
function createSyntheticEventHandler(eventName, handler) {
const $scope = $$scope();
return value => {
$scope.setIsEvent(true);
handler(new SyntheticEvent({ type: eventName, value }));
$scope.setIsEvent(false);
};
}
const detectIsEvent = attrName => attrName === 'on';
function useEvents(map) {
const scope = useMemo(() => ({ map }), []);
const $map = useMemo(() => {
const state = {};
for (const key of Object.keys(scope.map)) {
state[key] = (...args) => scope.map[key](...args);
}
return state;
}, []);
scope.map = map;
return $map;
}
export { SyntheticEvent, createSyntheticEventHandler, detectIsEvent, useEvents };
//# sourceMappingURL=events.js.map