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

incremental-dom-loader

v0.0.6

Published

An incremental-dom loader for webpack. It compiles an HTML file into an incremental-dom script

Downloads

16

Readme

incremental-dom-loader

Build Status npm

An incremental-dom loader for webpack. It compiles an HTML file into an incremental-dom script.

Getting Started

Install incremental-dom-loader via npm:

$ npm install --save-dev incremental-dom-loader

then add it to your webpack.config.js:

module.exports = {
  ...
  module: {
    rules: [{
      test: /\.html$/,
      loader: 'incremental-dom-loader'
    }, ...]
  }
};

Usage

incremental-dom-loader transpiles HTML code into incremental-dom js scripts so that you can seamless include them as part of your webpack bundle.

In your project dir create a plain HTML file (e.g. simple.html):

<h1>Hello!</h1>

and in your js code require it as usual:

const simple = require('./simple.html');

During the build step the HTML file will be converted into:

var id = require('incremental-dom');

module.exports = function(state) {
  id.elementOpen('h1', 'lh5kf', []);
    id.text(`Hello!`);
  id.elementClose('h1');
};

that can be passed as argument of the patch function:

patch(root, function() {
  simple(data);
});

Rules

incremental-dom-loader levereges on htmlparser2 for the HTML code parsing. The build process follows the following rules:

  • Static suffix/prefix are added to the code including incremental-dom requires and exports,
  • An open tag is converted into:
id.elementOpen('tagName', 'an unique id', [ 'static', 'attribute' ], 'dynamic', 'attribute');
  • A text element is converted into:
id.text(`Hello!`);
  • A close tag is converted into:
id.elementClose('tagName');

Template

incremental-dom-loader provides a template engine system based on the ES6 template literals.

<h1>Hello!</h1>

<dom-if test="${ state.check() }">
  <dom-loop items="${ state.items }">
    <h2>${ value.title }</h2>
    <p>${ value.text }</p>
    <button onclick="${ state.love }">Show Love!</button>
  </dom-loop>
</dom-if>
var id = require('incremental-dom');

module.exports = function(state) {
  id.elementOpen('h1', 'hio0k', []);
    id.text(`Hello!`);
  id.elementClose('h1');
  if(state.check()) {
    for(const key of Object.keys(state.items)) {
      const value = state.items[key];
      id.elementOpen('h2', `ncj5k-${ key }`, []);
        id.text(`${ value.title }`);
      id.elementClose('h2');
      id.elementOpen('p', `jde79-${ key }`, []);
        id.text(`${ value.text }`);
      id.elementClose('p');
      id.elementOpen('button', `eima7-${ key }`, [], 'onclick', state.love);
        id.text(`Show Love!`);
      id.elementClose('button');
    }
  }
}

All the attributes/text nodes containing ${ ... } are converted into js template litterals. The state variable represents the argument you pass to the template function.

The dom-if and dom-loop pseudo-elements can be used to create if and for statements:

dom-if

<dom-if test="${ state.check() }">
  <!-- if test is true -->
</dom-if>
if(state.check()) {
  // ...
}

dom-loop

<dom-loop items="${ state.items }">
  <!-- loop over state.items -->
</dom-loop>
for(const key of Object.keys(state.items)) {
  const value = state.items[key];
  // ...
}

License

MIT