Skip to content

A jQuery like library based on XStream and FP-TS.

License

Notifications You must be signed in to change notification settings

mblink/query-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

query-ts

A jQuery like DOM manipulation library for server side rendered pages based on XStream and FP-TS 2.x.

npm install query-ts

Sample usage:

// Get a single element from the dom and map over the Option
import {Q, QElement, UnsafeHtml} from "query-ts";
import {pipe} from "fp-ts/lib/pipeable"
import {Option, filter, map, getOrElse} from "fp-ts/lib/Option";

const c: Option<Q<QElement>> = Q.one(".container");

const el: Q<QElement> = pipe(
  c,
  filter(e => e.hasClass("container")), // Filter and map over the Option<Q>
  map(e => e.removeClass("container")),
  getOrElse(() => Q.of(document.createElement("div"))) // Lift an element into Q in case of None
);

const html: UnsafeHtml = el.getOuterHtml();

console.log(html.toString())


// Get a list of elements from the dom and iterate over the list
const l: Q<QElement>[] = Q.all(".container");

l.map(e => console.log(e.hasClass("container")));

About

A jQuery like library based on XStream and FP-TS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published