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

zzzap

v0.2.2

Published

A zzzappy fork of choo API that uses virtual DOM

Downloads

5

Readme

A performant, zappy framework for a futuristic SPA apps with unbelievably simplistic API.

What is zzzap?

Other than an electric shock, zzzap originated as a fork of choo being ported to a very perfomant virtual DOM implementation (it utilizes amazing snabbdom API under the covers).

Why not just use choo?

Native DOM diffing has advantage of being very versatile and compatible with most of the regular DOM APIs/libraries, but it also suffers from a performance penalty when diffing over a large number of elements. And this is why zzzap happened.

Features

  • a very small and easy to understand API
  • very performant (snabbdom virtual dom API)
  • isomorphic / SSR ready

Installation

$ npm install zzzap

Example (original choo example):

var html = require('zzzap/html')
var log = require('choo-log') // anything compatible with choo 6.x.x API
var zzzap = require('zzzap')

var app = zzzap()
app.use(log())
app.use(countStore)
app.route('/', mainView)
app.mount('body')

function mainView (state, emit) {
  return html`
    <body>
      <h1>count is ${state.count}</h1>
      <button onclick=${onclick}>Increment</button>
    </body>
  `

  function onclick () {
    emit('increment', 1)
  }
}

function countStore (state, emitter) {
  state.count = 0
  emitter.on('increment', function (count) {
    state.count += count
    emitter.emit('render')
  })
}

For a Jsx example, please visit examples

Events

Events system is the very same, intact choo event API driven by nanobus.

Possible built-in events are:

  • DOMContentLoaded in state.events.DOMCONTENTLOADED
  • render in state.events.RENDER
  • navigate in state.events.NAVIGATE
  • pushState in state.events.PUSHSTATE
  • replaceState in state.events.REPLACESTATE
  • popState in state.events.POPSTATE
  • DOMTitleChange in state.events.DOMTITLECHANGE

State

One of the original advantages of choo is a well-though, simple concept of a shared state that is very fast and easy to reason about. It comprises of some built-in properties and interfaces such as:

  • state.events - a current track of all event emitter events
  • state.params - router parameters that are provided by nanorouter
  • state.query - router querystrings provided by nanorouter
  • state.href - a current href
  • state.route - current matched route
  • state.title - current DOM title, responds to DOMTitleChange event

Server-side rendering

Using app.toString() in NodeJs will call snabbdom's snabbdom-to-html and render the whole virtual DOM tree to string.

API

The following API section is mostly the exceprt from the original choo repository.

This section provides documentation on how each function in zzzap works. It's intended to be a technical reference.

app = zzzap([opts])

Initialize a new zzzap instance. opts can also contain the following values:

  • opts.history: default: true. Listen for url changes through the history API.
  • opts.href: default: true. Handle all relative <a href="<location>"></a> clicks and call emit('render')

app.use(callback(state, emitter))

Call a function and pass it a state and emitter. emitter is an instance of nanobus. You can listen to messages by calling emitter.on() and emit messages by calling emitter.emit(). Callbacks passed to app.use() are commonly referred to as 'stores'.

If the callback has a .storeName property on it, it will be used to identify the callback during tracing.

See #events for an overview of all events.

app.route(routeName, handler(state, emit))

Register a route on the router. The handler function is passed app.state and app.emitter.emit as arguments. Uses [nanorouter][nanorouter] under the hood.

See #routing for an overview of how to use routing efficiently.

app.mount(selector)

Start the application and mount it on the given querySelector. Uses [nanomount][nanomount] under the hood. This will replace the selector provided with the tree returned from app.start(). If you want to add the app as a child to an element, use app.start() to obtain the tree and manually append it.

tree = app.start()

Start the application. Returns a tree of DOM nodes that can be mounted using document.body.appendChild().

app.toString(location, [state])

Render the application to a string. Useful for rendering on the server.

zzzap/html

Create virtual DOM nodes from template string literals. Exposes snabbdom.

zzzap/html/h

Exposes virtual dom snabbdom-pragma. Requires additional .babelrc property and transform-react-jsx package:

{
  "plugins": [
    ["transform-react-jsx", {
      "pragma": "h"
    }]
  ]
}

Contribution

Anyone is welcome to contribute and submit PRs. Don't be shy!

License

MIT