Skip to content

Commit

Permalink
feat(hdom): add support for event listener strings
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 27, 2020
1 parent 074985a commit db8d350
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/hdom/src/dom.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { isArray as isa, isNotStringAndIterable as isi } from "@thi.ng/checks";
import {
isArray as isa,
isNotStringAndIterable as isi,
isString as iss,
} from "@thi.ng/checks";
import { css, SVG_NS, SVG_TAGS } from "@thi.ng/hiccup";
import type { HDOMImplementation, HDOMOpts } from "./api";

const isArray = isa;
const isNotStringAndIterable = isi;
const isString = iss;

const maybeInitElement = <T>(el: T, tree: any) =>
tree.__init && tree.__init.apply(tree.__this, [el, ...tree.__args]);
Expand Down Expand Up @@ -319,9 +324,14 @@ export const setStyle = (el: Element, styles: any) => (
export const setListener = (
el: Element,
id: string,
listener: EventListener | [EventListener, boolean | AddEventListenerOptions]
listener:
| string
| EventListener
| [EventListener, boolean | AddEventListenerOptions]
) =>
isArray(listener)
isString(listener)
? el.setAttribute("on" + id, listener)
: isArray(listener)
? el.addEventListener(id, ...listener)
: el.addEventListener(id, listener);

Expand Down

0 comments on commit db8d350

Please sign in to comment.