GithubHelp home page GithubHelp logo

haydermabood / rxjs-jsx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ryansolid/rxjs-jsx

0.0 0.0 0.0 54 KB

Dom JSX bindings for RxJS

License: MIT License

JavaScript 0.82% TypeScript 99.18%

rxjs-jsx's Introduction

RxJS JSX

This library is an experiment to use RxJS as a fine grained DOM renderer with RxJS Autorun.

It accomplishes this with using Babel Plugin JSX DOM Expressions. It compiles JSX to DOM statements and wraps expressions in functions that can be called by the library of choice. In this case autorun wrap these expressions ensuring the view stays up to date. Unlike Virtual DOM only the changed nodes are affected and the whole tree is not re-rendered over and over.

To use include 'babel-plugin-jsx-dom-expressions' in your babelrc, webpack babel loader, or rollup babel plugin

"plugins": [["jsx-dom-expressions", {moduleName: 'rxjs-jsx'}]]

Installation

> npm install rxjs-jsx babel-plugin-jsx-dom-expressions

Example:

Counter

API

For example:

import { BehaviorSubject } from 'rxjs';
import { render, $ } from 'rxjsx'

const Greeter = (props) =>
  <div onClick={props.onClick}>Hello {props.name || 'World'}</div>

function App() {
  const name = new BehaviorSubject('John');
  return <>
    <h1>Greeting Example</h1>
    <Greeter name={$(name)} onClick={() => name.next('Jake')}/>
  </>;
}

render(App, document.getElementById('main'));

Control flow works the way you generally would JSX. However for performant list rendering I have added a fn on subscribable called memoMap that will optimally handle arrays.

<ul>{
  <For each={$(list)}>{item => <li>{item}</li>}</For>
}</ul>

Example

Non-Precompiled

For those who do not wish to use Babel to precompile, the RxJSX supports Tagged Template Literals or HyperScript render APIs. These are available when you install the companion library and throw import of 'rxjsx/html' and 'rxjsx/h'. Refer to the docs on Lit DOM Expressions, and Hyper DOM Expressions, respectively.

import { BehaviorSubject } from 'rxjs';
import { h, $, render } from 'rxjsx/h';

const Greeter = props =>
  h('div', {onclick}, 'Hello', () => props.name || 'World');

function App() {
  const name = new BehaviorSubject('John');
  return h('div', [
    h('h1', 'Greeting Example'),
    h(Greeter, {name: () => $(name), onClick: () => name('Jake')})
  ]);
}

render(App, document.getElementById('main'));

rxjs-jsx's People

Contributors

ryansolid avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.