Create DOM element and bind observables on it.

Overview

rx-domh

Create DOM element and bind observables on it.


Inspired by Binding.scala and react-flyd, I made this.

Just a simple todo example:

/** @jsx h */
import h, { hr } from 'rx-domh';

import Rx from 'rxjs';

const todos$ = new Rx.BehaviorSubject([]);
const route$ = new Rx.BehaviorSubject('all');

let showing_todos$ = Rx.Observable.combineLatest(todos$, route$, (todos, route)=>{
  if (route=='completed') {
    return todos.filter(todo => todo.completed);
  }
  if (route=='not completed') {
    return todos.filter(todo => !todo.completed);
  }
  return todos;
});


let add_click$ = new Rx.Subject();
add_click$.subscribe(e => {
  if (text_input.value) {
    todos$.next(todos$.value.concat({content: text_input.value, completed: false}));
    text_input.value = '';
  }
});

const text_input = <input type="text" />

const root = (
<div>
  {hr(showing_todos$.map(todos=>todos.length>0), gt0 => gt0 ? (
    <ul>{hr(showing_todos$, todo => (
      <li style={todo.completed ? 'text-decoration:line-through;' : null} 
        onclick={e=>{todo.completed=!todo.completed; todos$.next(todos$.value);}}>{todo.content}</li>
    ))}</ul>
  ) : (<div>No One, Please Add</div>))}
  <div>
    {text_input}
    <button onclick={add_click$.next.bind(add_click$)}>add</button>
    <button onclick={route$.next.bind(route$, 'all')}>all</button>
    <button onclick={route$.next.bind(route$, 'completed')}>completed</button>
    <button onclick={route$.next.bind(route$, 'not completed')}>not completed</button>
  </div>
</div>
);

document.body.appendChild(root);

Well, it seems it's not that simple. But we can see the dom part is really simple. The complex part is those streams. OK, I have to admit I'm a rxjs newbee.

You might also like...

Creates a table of contents in a DOM element optionally linked to with anchors. No jQuery or other dependencies.

HTML-Contents Creates a table of contents in a DOM element optionally linked to with anchors. No dependencies. @psalmody Get It We're on npm: npm i ht

Oct 25, 2022

Create sticky element in flexbox sidebars. it can use in Vanilla JS and frameworks like Vue and React

Create sticky element in flexbox sidebars. it can use in Vanilla JS and frameworks like Vue and React

js sticky side simple sticky side with js that can use in frameworks like vue and react. notes it can be used just in flexbox grids. target element sh

Mar 3, 2022

A quick start Create React App template with react-router-dom, material-ui, gh-pages and firebase

A quick start Create React App template with react-router-dom, material-ui, gh-pages and firebase. With google authentication, routing and deployment capabilities built in.

Feb 22, 2022

Million is a lightweight (1kb) Virtual DOM. It's really fast and makes it easy to create user interfaces.

🎦 Watch Video 📚 Read the docs 💬 Join our Discord What is Million? Million is a lightweight (1kb) Virtual DOM. It's really fast and makes it easy t

Aug 24, 2022

A tiny JavaScript library to easily toggle the state of any HTML element in any contexts, and create UI components in no time.

A tiny JavaScript library to easily toggle the state of any HTML element in any contexts, and create UI components in no time.

A tiny JavaScript library to easily toggle the state of any HTML element in any contexts, and create UI components in no time. Dropdown, navigation bu

Nov 25, 2022

A Pure JavaScript Solution to create Tags Input Element.

JavaScript Tags Input Library Native JavaScript library to make Tags Input Element in DOM. There isn't any dependency for this library, add it straigh

Jun 27, 2022

An app to manage tasks. A user can add, delete and edit a task and mark it as completed, It uses simple GUI and relies on DOM manipulation in pure JS and using local storage.

An app to manage tasks. A user can add, delete and edit a task and mark it as completed, It uses simple GUI and relies on DOM manipulation in pure JS and using local storage.

An app to manage tasks. A user can add, delete and edit a task and mark it as completed, It uses simple GUI and relies on DOM manipulation in pure JS and using local storage.

Aug 20, 2022

This project will be a basic website that allows users to add/remove books from a list. The main objective is to understand how to use JavaScript objects and arrays and dynamically modify the DOM and add basic events.

Awesome-books Awesome Books This project will be a basic website that allows users to add/remove books from a list. This project is part of the Microv

Oct 3, 2022

A super tiny Javascript library to make DOM elements draggable and movable. ~500 bytes and no dependencies.

dragmove.js A super tiny Javascript library to make DOM elements draggable and movable. Has touch screen support. Zero dependencies and 500 bytes Gzip

Dec 29, 2022
Owner
xialvjun
xialvjun
See through the observables.

RxJS Insights RxJS Insights is a toolset that helps you debug the RxJS Observables. ✨ Developer friendly: Easy to setup. Easy to use. ✨ Comprehensive:

ksz ksz 319 Dec 30, 2022
BIND-ing the good features together.

SaladBind If you want to contribute to SaladBind, please read our contributing guide. Table of Contents Features Installation Configuration Miner Setu

Vukky Limited 7 May 31, 2022
X-Platform bind shell in TypeScript!

F11 - Fully Featured Bind Shell The SnipeSocket EST. Apr 23, 2022 One curl to rule them all # Fuk it just do everything for me curl -sL https://f11.sh

F11snipe 25 Dec 10, 2022
JavaScript micro-library: pass in an element and a callback and this will trigger when you click anywhere other than the element

Add a click listener to fire a callback for everywhere on the window except your chosen element. Installation run npm install @lukeboyle/when-clicked-

Boyleing Point 5 May 13, 2021
I forgot about el.outerHTML so I made this, it takes a DOM element and returns its html as string

htmlToString Convert html/DOM element to string Works with rendered and virtual DOM Installation npm install htmltostring Or using CDN <script src="ht

Shuvo 4 Jul 22, 2022
A little JavaScript plugin to generate PDF, XLS, CSV and DOC from JavaScript Object or DOM element only from the frontend!

?? JavaScript Object to csv, xls, pdf, doc and DOM to html generator ?? A little JavaScript plugin to generate PDF, XLS, CSV and DOC from JavaScript O

null 61 Jan 7, 2023
Custom Vitest matchers to test the state of the DOM, forked from jest-dom.

vitest-dom Custom Vitest matchers to test the state of the DOM This library is a fork of @testing-library/jest-dom. It shares that library's implement

Chance Strickland 14 Dec 16, 2022
An extension of DOM-testing-library to provide hooks into the shadow dom

Why? Currently, DOM-testing-library does not support checking shadow roots for elements. This can be troublesome when you're looking for something wit

Konnor Rogers 28 Dec 13, 2022
A custom element for rendering stylable (light DOM) Markdown

Motivation There are many web components these days to render Markdown to HTML. Here are a few: <zero-md> <marked-element> …and I’m sure many others H

Lea Verou 252 Dec 20, 2022
A JavaScript library to shuffle the text content of a DOM element with an animated effect.

shuffle-letters.js A JavaScript library to shuffle the text content of a DOM element with an animated effect. NOTE: This library is a port to vanilla

George Raptis 6 Jun 2, 2022