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

bib-elm

v0.2.2

Published

Simple to use .createElement helper

Downloads

3

Readme

Elm - Simple to use .createElement helper

Example

var cancel = Elm({ tag: "button", class: "btn",
	textContent: "Cancel",
	onclick: function () { console.log("Cancel"); }
});

var el = Elm({ tag: "span", class: "btn-group", children: [
	{ tag: "button", class: "btn",
		textContent: "Send",
		onclick: function () { console.log("Send"); }
	},
	cancel // cancel is DOM node
]});

// rerender
Elm({ tag: "span", class: "btn-group", children: [
	{ tag: "button", class: "btn disabled", // change class
		textContent: "Send",
		onclick: function () { console.log("Send"); }
	},
	cancel // cancel doen't change
]}, el);

// or alternative syntax
Elm({ tag: "span", attrs: { class: "btn-group" }, children: [
	{ tag: "button", attrs: { class: "btn disabled",
		textContent: "Send",
		onclick: function () { console.log("Send"); }
	}},
	cancel // cancel doen't change
]}, el);

Elm(options, [node])

If node is specified Elm incrementally rerenders node with given ast.

Note! Root node tag couldn't be changed.

options properties may be any DOM node properties or attributes, all unknown properties become node attributes

Special properties of options:

tag - tag, by default "div"

attrs - object, attributes, properties for DOM node, including style object

children - array of children, each child may be options object, DOM node, any object with poroperty .el which is DOM node, text string. If child is null/undefined it's ignored

style - string or object which sets inline style through node.style, { "fontSize": "10px" }

beforeCreate - function/array of function(options) which is called with current options before DOM node is rendered

afterCreate - function/array of function(el), called after DOM node created

beforeRemove - function/array of function(el), called before DOM node is removed

remove - function/array of function(el), removes DOM node

afterRemove - function/array of function(el), called after DOM node is removed, ignored when remove specified

Rerending

Rerending is done id D3.js-like way with update/create/remove sections.

When rerendered all childrens properties and attributes are overwritten, if there are more nodes in the new tree - nodes are created, if there are less - removed from the DOM. Nodes are created and removed only at the end of children array.

For example:

var el = Elm({ children: [
	{ class: "task", textContent: "Task 1" },
	{ class: "task", textContent: "Task 2" },
	{ class: "task", textContent: "Task 3" }
]});

Mark second task done:

Elm({ children: [ // root left intact
	{ class: "task", textContent: "Task 1" }, // `class`, `textContent` overwritten
	{ class: "task done", textContent: "Task 2" }, // `class`, `textContent` overwritten
	{ class: "task", textContent: "Task 3" } // `class`, `textContent` overwritten
]}, el);

Then add task 4:

Elm({ children: [ // root left intact
	{ class: "task", textContent: "Task 1" }, // `class`, `textContent` overwritten
	{ class: "task done", textContent: "Task 2" }, // `class`, `textContent` overwritten
	{ class: "task", textContent: "Task 3" }, // `class`, `textContent` overwritten
	{ class: "task", textContent: "Task 4" } // node created
]}, el);

Remove task 2:

Elm({ children: [ // root left intact
	{ class: "task", textContent: "Task 1" }, // `class`, `textContent` overwritten
	{ class: "task", textContent: "Task 3" }, // task 2 node, `class`, `textContent` overwritten
	{ class: "task", textContent: "Task 4" } // task 3 node, `class`, `textContent` overwritten
	// task 4 node removed
]}, el);