DEV Community

artydev
artydev

Posted on • Edited on

2

DML is to Javascript what Tailwind is to CSS.

I am still impressed by the way it works.
Look at this piece of code :

function topBar (appName) {
  let _styleTopBar = {style :`
      background:orange;
      line-height:50px;
      display: flex;
      justify-content: space-between;
      margin-bottom: 50px;
      padding-left:10px;
      padding-right:10px;
      box-shadow: 0 5px 5px rgba(0,0,0,0.13);           
  `}
  let topBar = selectBase(div("", _styleTopBar )); 
  let _styleItems = {style:"cursor:pointer"}
  let brand = div("brand", _styleItems); 
  let title = div(appName, _styleItems); 
  let help = div("Help", _styleItems);        
  unselectBase(); // topBar
  for (let item of [brand, title, help]) {
    item.onclick = () => alert(item.innerText);
  }
  return topBar;
}

let topbar = topBar("DML Demo");

console.log(topbar);
Enter fullscreen mode Exit fullscreen mode

Here is the result of the output:

<div style="background: orange none repeat scroll 0% 0%; line-height: 50px; display: flex; justify-content: space-between; margin-bottom: 50px; padding-left: 10px; padding-right: 10px; box-shadow: rgba(0, 0, 0, 0.13) 0px 5px 5px;">...</div>
Enter fullscreen mode Exit fullscreen mode

As Eckehard says, the author of DML, topBar acts as a function generator, it generates a real UI Element.

And to prove it, you can use your favorite framework to render it on a page (but you don't have to :-))

Here is how to render a topbar with Preact

You can test it here Topbar/Preact

const { render }  =  preact;

function topBar (appName) {
  let _styleTopBar = {style :`
      background:orange;
      line-height:50px;
      display: flex;
      justify-content: space-between;
      margin-bottom: 50px;
      padding-left:10px;
      padding-right:10px;
      box-shadow: 0 5px 5px rgba(0,0,0,0.13);           
  `}
  let topBar = selectBase(div("", _styleTopBar )); 
  let _styleItems = {style:"cursor:pointer"}
  let brand = div("brand", _styleItems); 
  let title = div(appName, _styleItems); 
  let help = div("Help", _styleItems);        
  unselectBase(); // topBar
  for (let item of [brand, title, help]) {
    item.onclick = () => alert(item.innerText);
  }
  return topBar;
}

render(topBar("Demo DML"), document.body);
Enter fullscreen mode Exit fullscreen mode

But you can simply render topBar natively TopBar :

 topBar("Demo DML")
 topBar("Demo DML-2")
Enter fullscreen mode Exit fullscreen mode

Amazing :-)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay