0.2.0 • Published 2 years ago

@tronicboy/lit-observe-directive v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

License

Distributed under the MIT license.

About this package

This is a directive for Lit that allows you to subscribe to RxJS observables in html template literals.

Usage

import { LitElement, css, html } from "lit";
import { customElement } from "lit/decorators.js";
import { map, scan } from "rxjs";
import { webSocket } from "rxjs/webSocket";
import { observe } from "@tronicboy/lit-observe-directive";

const tagName = "wc-lit-websocket";

@customElement(tagName)
export class WcLitWebsocket extends LitElement {
  private socket$ = webSocket<string>({
    url: "ws://localhost:5200",
    protocol: "echo-protocol",
  });
  private messages$ = this.socket$.pipe(scan((acc, message) => [message, ...acc], [] as string[]));

  render() {
    return html`
      <ul>
        ${observe(this.messages$.pipe(map((messages) => messages.map((message) => html`<li>${message}</li>`))))}
      </ul>`;
  }
}

Little bit cluttered but it gets the job done.

Code Style: Google

0.1.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago