UNPKG

xatto

Version:

xatto is View Layer Library based on Function and Context using VirtualDOM. This is developed by forking from jorgebucaran/superfine.

44 lines (36 loc) 975 B
import { EXTRA, PATH } from './consts/attributeNames' import { deepGet } from './deepGet' import { Props } from './Props' export function eventProxyProvider ( mutate, getContext, eventTargetProps: WeakMap<EventTarget, Props> ) { return (event: Event | CustomEvent) => { const node = event.currentTarget! const props = eventTargetProps.get(node) || {} const path = deepGet(props, PATH) || '' const detail = (event as CustomEvent).detail || {} const extra = deepGet(props, EXTRA) || {} const newContext = props!['on' + event.type]( getContext(path), { ...extra, ...detail, dispatch: (name, dtl = {}) => { node && node.dispatchEvent( new CustomEvent(name, { bubbles: true, cancelable: true, detail: dtl }) ) } }, props, event ) mutate(newContext, path) } }