rtmpl
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

rtmpl

Reactive tagged template literals.

Installation

npm install rtmpl --save

Usage

The concept of this library arose from the requirement to dynamically generate the text output of CLI applications. However, this may not be the only reasonable usage scenario. Therefore, this library contains only the conceptual core in the form of the so-called template nodes. These nodes can be nested within each other in a tree structure and are observable.

To learn how to generate the text output of CLI applications using this library, please refer to the README of project @rtmpl/terminal.

Types

TemplateNode

class TemplateNode<TValue> {
  static create<TValue>(
    template: TemplateStringsArray,
    ...children: (TemplateNode<TValue> | TValue)[]
  ): TemplateNode<TValue>;

  subscribe(observer: TemplateNodeObserver<TValue>): () => void;

  update(
    template: TemplateStringsArray,
    ...children: (TemplateNode<TValue> | TValue)[]
  ): this;

  on(event: 'observe' | 'unobserve', listener: () => void): () => void;
}
type TemplateNodeObserver<TValue> = (
  template: TemplateStringsArray,
  ...values: TValue[]
) => void;

TemplateNodeList

class TemplateNodeList<TValue> {
  static join<TValue>(
    itemNodes: readonly (TemplateNode<TValue> | TValue)[],
    options?: TemplateNodeListOptions<TValue>
  ): [
    template: TemplateStringsArray,
    ...children: (TemplateNode<TValue> | TValue)[]
  ];

  readonly node: TemplateNode<TValue>;

  constructor(options?: TemplateNodeListOptions<TValue>);

  add(
    template: TemplateStringsArray,
    ...children: (TemplateNode<TValue> | TValue)[]
  ): TemplateNode<TValue>;

  delete(itemNode: TemplateNode<TValue>): void;
}
interface TemplateNodeListOptions<TValue> {
  readonly separator?: TemplateNode<TValue> | NonNullable<TValue>;
}

Copyright 2021 Clemens Akens. All rights reserved. MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i rtmpl

Weekly Downloads

114

Version

1.3.0

License

MIT

Unpacked Size

93.4 kB

Total Files

29

Last publish

Collaborators

  • clebert