Giter VIP home page Giter VIP logo

transform-tagged-diffhtml's Introduction

diffHTML Babel Plugin

Latest stable version: 1.0.0-rc.2

Build Status

Plugin for babel 6.x to enable tagged template compilation for diffHTML

This plugin transforms tagged template strings in your projects to diffHTML Virtual Tree's.

Note! This plugin has been built for use in Babel 6.x environments, and will not work with Babel 5.x ( deprecated) or older versions.*

How to install

npm i --save-dev transform-tagged-diffhtml

How to use

Add the plugin to your package.json and update the plugin section in your .babelrc file. Or if your Babel settings are located inside the package.json - update the plugin section there.

You will then need to tag your diffHTML templates with the html function, examples below. This will only optimize tagged templates, allowing you to use the diffHTML runtime build avoiding runtime HTML parsing.

Example on a .babelrc file that will work with diffHTML:

{   
  "plugins": ["transform-tagged-diffhtml"]
}

Write a View view.js:

// Render a div with dynamic children and onclick
function renderComponent(time) {
  diff.innerHTML(document.body, html`
    <button onclick=${e => renderComponent(new Date())}>Get time</button>
    <output>${time}</output>
  `);
}

renderComponent(new Date());

Then compile it:

babel view.js -o view.es5.js

Specifying options

You can override three identifiers that are used within the transform:

  • tagName - The tagged template function name default is html.
  • createElement - The create element function default is diff.createElement
  • createAttribute - The create attribute function default is diff.createAttribute

Specifying the options in your .babelrc:

{
  plugins: [
    ["transform-tagged-diffhtml", {
      "tagName": "diff.html",
      "createElement": "createEl",
      "createAttribute": "createAttr"
    }]
  ]
}

How your source would look reflecting the options:

import * as diff from 'diffhtml';

const { createElement as createEl, createAttribute as createAttr } = diff;

diff.html`
  <div></div>
`;

transform-tagged-diffhtml's People

Contributors

tbranyen avatar

Watchers

Alex Maslakov avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.