UNPKG

fp-ts-std

Version:

The missing pseudo-standard library for fp-ts.

35 lines (34 loc) 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addEventListener_ = exports.addEventListener = exports.setTextContent = exports.getTextContent = exports.emptyChildren = exports.appendChild = exports.remove = exports.childNodes = exports.querySelectorAll = exports.querySelector = exports.fromNodeList = void 0; const IO = require("fp-ts/IO"); const NEA = require("fp-ts/NonEmptyArray"); const O = require("fp-ts/Option"); const function_1 = require("fp-ts/function"); const Function_1 = require("./Function"); exports.fromNodeList = Array.from; const querySelector = (q) => (x) => () => (0, function_1.pipe)(x, (0, Function_1.invoke)("querySelector")([q]), O.fromNullable); exports.querySelector = querySelector; const querySelectorAll = (q) => (x) => () => (0, function_1.pipe)(x, (0, Function_1.invoke)("querySelectorAll")([q]), exports.fromNodeList, NEA.fromArray); exports.querySelectorAll = querySelectorAll; const childNodes = (x) => () => (0, function_1.pipe)(x.childNodes, exports.fromNodeList, NEA.fromArray); exports.childNodes = childNodes; const remove = (x) => () => (0, function_1.pipe)(x, (0, Function_1.invoke)("remove")([])); exports.remove = remove; const appendChild = (child) => (parent) => () => (0, function_1.pipe)(parent, (0, Function_1.invoke)("appendChild")([child])); exports.appendChild = appendChild; exports.emptyChildren = (0, function_1.flow)(exports.childNodes, IO.chain(O.traverse(IO.Applicative)(IO.traverseArray(exports.remove)))); const getTextContent = (x) => () => (0, function_1.pipe)(x.textContent, O.fromNullable); exports.getTextContent = getTextContent; const setTextContent = (x) => (y) => () => { y.textContent = x; }; exports.setTextContent = setTextContent; const addEventListener = (type) => (listener) => (el) => () => { const _listener = (e) => listener(e)(); (0, function_1.pipe)(el, (0, Function_1.invoke)("addEventListener")([type, _listener])); return () => (0, function_1.pipe)(el, (0, Function_1.invoke)("removeEventListener")([type, _listener])); }; exports.addEventListener = addEventListener; const addEventListener_ = (type) => (listener) => (el) => (0, function_1.pipe)((0, exports.addEventListener)(type)(listener)(el), IO.map(function_1.constVoid)); exports.addEventListener_ = addEventListener_;