0.15.5 ā€¢ Published 4 years ago

ullr v0.15.5

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

Functional Web Components

Building Web Components with Functional Programming.

CI Published on npm

      ___                                       ___
     /__/\                                     /  /\
     \  \:\                                   /  /::\
      \  \:\    ___     ___   ___     ___    /  /:/\:\
  ___  \  \:\  /__/\   /  /\ /__/\   /  /\  /  /:/~/:/
 /__/\  \__\:\ \  \:\ /  /:/ \  \:\ /  /:/ /__/:/ /:/___
 \  \:\ /  /:/  \  \:\  /:/   \  \:\  /:/  \  \:\/:::::/
  \  \:\  /:/    \  \:\/:/     \  \:\/:/    \  \::/~~~~
   \  \:\/:/      \  \::/       \  \::/      \  \:\
    \  \::/        \__\/         \__\/        \  \:\
     \__\/                                     \__\/

Installation

Add to lit-html project:

npm i ullr

When creating a new project using lit-html as template and RxJS as the state management:

npm i ullr lit-html rxjs

Partially supports run on Node.js (with jsdom).

APIs

component

component is a lit-html directive.

Encapsulate the template with Shadow DOM.

import { html } from 'lit-html'
import { component } from 'ullr/directive'

export const main = (title: string, desc: string) =>
	component(html`
		<style>
			h1 {
				color: blue;
			}
		</style>
		<main>
			<h1>${title}</h1>
			<p>${desc}</p>
		</main>
	`)
BrowserNode.js
āœ…šŸšø Shadow Dom isn't supported. An inside content of Shadow Dom is shown as just an innerHTML.

šŸ’” How to preprocess style tags with PostCSS: šŸ’… https://github.com/aggre/lit-style

subscribe

subscribe is a lit-html directive.

Subscribe to Observable<T> of RxJS and re-rendering with a callback function.

When the directive part is removed, it will automatically unsubscribe.

import { html } from 'lit-html'
import { subscribe } from 'ullr/directive'
import { timer as _timer } from 'rxjs'

export const timer = (initialDelay: number, period: number) =>
	subscribe(
		_timer(initialDelay, period),
		(x) => html` <p>${x}</p> `,
		html` <p>Default content</p> `
	)
BrowserNode.js
āœ…šŸšø Create string as a DOM is supported. But auto-unsubscribe isn't supported.

customElements

customElements creates a class that can be passed to customElements.define.

import { customElements } from 'ullr'
import { main } from './main'

const observedAttributes = ['title', 'desc']

const template = ([title, desc]) => main(title, desc)

window.customElements.define(
	'x-app',
	customElements(template, observedAttributes)
)
BrowserNode.js
āœ…āŒ

0.15.5

4 years ago

0.15.2

4 years ago

0.12.6

5 years ago

0.12.5

5 years ago

0.12.4

5 years ago

0.12.3

5 years ago

0.12.2

5 years ago

0.12.1

5 years ago

0.12.0

5 years ago

0.11.0

5 years ago

0.10.4

5 years ago

0.10.3

5 years ago

0.10.2

5 years ago

0.10.1

6 years ago

0.10.0

6 years ago

0.9.8

6 years ago

0.9.7

6 years ago

0.9.6

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.1

6 years ago