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 🙏

© 2025 – Pkg Stats / Ryan Hefner

protozoa

v1.9.3

Published

A micro-app generator

Readme

A micro-app generator.

Usage

See demo and demo source for an ES5 example. The protozoa package is also available on NPM.

The protozoa module itself is just one factory function that is called with a template. Calling it looks like this:

var element = protozoa({
  tag: 'div',
  children: [
    'Hello ',
    { tag: 'strong', children: 'world!' }
  ]
});

Template API

The template API borrows heavily from cell. All properties are optional:

  • tag: the name of the DOM node to create, if unspecified it will be a <div>
  • ref: the name of a property that the parent element can access for convenience
  • init: a function to run when the node is created, with the node as this
  • children: a string, number, function, or an array of values or nested templates
  • ch: an alias for children

The function returns an ordinary DOM node with a few additions. You can append this node anywhere in your HTML page:

document.body.appendChild(element);

DOM Node API

DOM nodes returned by protozoa have a special array property children which controls the node's contents. Assigning to this property will empty out the containing DOM node and append the new structure in its place:

element.children = ['Something Else'];

Don't ever run element.children.push() or anything like that, always assign a new array or value.

Advanced API

The template reserves an additional property: kernel. This property is used to set or retrieve the immutable kernel function that protozoa uses to walk recursively through a nested spec. If you didn't understand the previous sentence, you should probably leave it alone.

Other properties

That's pretty much it. All other properties are treated as native IDL attributes (with preprocessing for class, className and style). Specifying class OR className will set the node's class AND className attributes. Style has weird behavior and you can't use that property to store arbitrary strings. Anything not used by the browser is fair game for your functions, state objects, or whatever else your node needs.

See demo for an example using a flux-like message bus.

Concept

A "micro-app" is a web app that is all of the following:

  • Small (not rendering more than ten thousand items)
  • Composable (able to be controlled and extended with a simple API)
  • Embedded (no model, no viewmodel, no virtual DOM, just the real DOM)

It's just the DOM

The micro-app architecture is based on a restriction: All "components" must be DOM nodes, and all extra functionality must be built into those same objects. With ReactJS every component instance must be linked to a single DOM node, so why not just start with the real DOM node and build all the component functionality into that? Bam, no more headaches from immutable value props, the DOM node has a value and that's all that is necessary. This package should be mostly compatible back to IE9, but if IDL event or attribute compatibility is an issue, you can set up handlers with jQuery in the init() function instead of using those.

Remember back in the day when you could query the DOM and actually do something with an element? With this architecture, that's how everything works!

Now with JSX support

Transpile JSX into valid configuration objects with Protozoa-TSX:

npm install protozoa-tsx
./node_modules/protozoa-tsx/bin/tsc --jsx protozoa input.tsx

Safety not guaranteed

If you've worked with the real DOM, you should already know that there are significant pitfalls with any approach. This way is no different. Careful not to overwrite any important attributes with data, because that's the real DOM!

Custom properties on DOM nodes was looked down on for years probably because of this risk, but we're adults and we can be careful.

The real tradeoff is performance

A complex UI rendered by emptying out containers and dumping in new DOM nodes means a lot of screen repaints. This architecture should be chosen with the assumption that apps will be smaller and simpler. The init() template API makes it easy to only redraw certain parts of an app in response to any kind of state engine, so a UI built in this way can still be optimized. Metazoa is an attempt to inject DOM-diffing and other behaviors into a protozoa-like framework.

But sometimes the best solution is to break apart your page into smaller apps that communicate with each other but don't need to keep a huge state in sync with a huge UI. More on this approach soon.