npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

doremifa

v1.0.20

Published

Reactive DOM library based on template literals

Downloads

6

Readme

Doremifa

Reactive view library based on tagged template literals. It is special compared to other similar libraries in that it implements it's own XHTML/HTML parser.

The main features are

  • Reactive template literals where only changed parts are re-rendered
  • Event handler support
  • SVG support
  • Has reactive global state, which can be used (not mandatory)
  • Router baked in (or you can use your own)

A simple TypeScript example

import * as Doremifa from 'doremifa'

const html = Doremifa.html;
const setState = Doremifa.setState

Doremifa.setState({
  time:(new Date).toTimeString(),
})
Doremifa.mount(document.body, state => html`<div>Hello World! ${state.time}</div>`)
setInterval( _ => { setState({time:(new Date).toTimeString()})},1000)

Hello World in CodePen Router Example in CodePen

Usage and Install

npm i doremifa

And then

import { mount, router, getState, setState, html, drmfComponent, drmfTemplate } from 'doremifa';
// or
import * as Doremifa from './index';

html -literal

To construct a Template you can write JavaScript template literal

  html`<div>${"Hello World"}</div>`

Doremifa.mount

Mount render function to some element

Doremifa.mount(document.body, state => html`<div>Hello World!</div>`)

Functions

Any function which returns drmfTemplate can be used as a component

function message(txt) {
  return html`<div>${txt}</div>`
}
const example = html`<div>${message(txt)}</div>`

Objects

Objects which implement render() -function and inherit from drmfComponent can be used as part of templates.

class Hello extends drmfComponent {
  render() {
    return html`<div>Hello World </div>`
  }
}
const obj = new Hello(); // create and re-use if needed
Doremifa.mount(document.body, state => html`<div>${obj}</div>`)

Attributes can be set by value without quotes

const style='color:blue;'
html`<div style=${style}/>`

Events

Event handlers get two params:

  • e the HTML event
  • tpl the drmfTemplate -object which can old ID or list values
html`<button onclick=${(e, tpl) => {
  // tpl holds the template object
}}>Click me!</button>`

References

References are collected from templates to two colletions:

  • ids holds elements having "id" attribute set
  • list holds elements having list="something" set

The are also available to event handlers.

html`<div>
  <input id="name" />
  <div list="divs" />
  <div list="divs" />
  <button onclick=${(e, tpl) => {
    alert(tpl.ids.name)           // value of input 
    alert(tpl.list.divs.length)   // 2
}}>Click me!</button>
</div>`

Event after template is assigned

Sometimes you want to manipulate DOM after the template has been rendered

html`<div></div>`.onReady( tpl => {
  // tpl.ids
  // tpl.list
})

Custom Tags?

There are no custom tags, just functions or objects.

State and rendering

The application has a global state which is accessed using

  • getState()
  • setState({...})

When state is updated, rendering is triggered and all parts of the application are processed. This should be extremely fast, since templates are cached and only changed parts are updated.

Promises inside View?

No. Promises are not part of view tree. Just update state and view changes reactively.

Doremifa.router

Build -in router router uses window.location.hash and acceptse links in format

  <a href="#page1/param1/value1/param2/value2">Link to page 1</a>
  <a href="#page2/param1/value1/param2/value2">Link to page 2</a>

Then you can define router anywhere in templates like

html`<div>  
    ${Doremifa.router({
        page1 : (state) => html`page1`,
        page2 : (state) => html`page2`,
      })
    </div>`

The router component gets the state having following variables set

{
  "page": "page2",
  "params": {
    param1 : value1,
    param2 : value2
  }
}

Other Similar libraries

  • hyperHTML
  • lit-html
  • YallaJS

Tutorials on similar subjects

  • https://www.twilio.com/blog/2018/05/building-a-chat-with-twilio-lit-html-parcel-and-typescript.html
  • https://itnext.io/a-tiny-disastrous-ecmascript-change-fadc05c83e69

License

MIT.