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

tinier

v0.5.1

Published

Tinier is a library for building tiny reactive components in JavaScript. Designed with D3.js in mind.

Downloads

21

Readme

Tinier

Tinier is a library for building tiny reactive components in JavaScript. Designed with D3.js in mind.

Development status

Tinier is Alpha software. It runs, but expect bugs and some changes to the API.

Documentation

Usage

Tinier is available as a UMD module on unpkg:

  • http://unpkg.com/tinier/lib/tinier.js
  • http://unpkg.com/tinier/lib/tinier.min.js

And it is on NPM:

https://www.npmjs.com/package/tinier

Components

Tinier components are created with the createComponent function.

MyComponent = createComponent({
  displayName: 'MyComponent',
})

The run function binds a Tinier component to the DOM and renders it.

var el = document.getElementById('my-container')
run(MyComponent, el)

Lifecycle

Components render when one of the following conditions is met:

  1. A new instance of a component is created.
  2. The binding (el) for a component is different than the last time it rendered.
  3. The shouldUpdate function returns true.

To decide whether a component renders when (1) and (2) are false, you can pass a function to the shouldUpdate option of createComponent. The default shouldUpdate function follows. It updates when the state changed based on an assumption of immutable state object (see the section on Reducers).

function shouldUpdate ({ state, lastState }) {
  return state !== lastState
}

A stricter approach utilizes the Boolean argument componentTriggeredUpdate. When componentTriggeredUpdate is true, that means the update was caused by a reducer of the given component. The following stricter shouldUpdate function calls for an update only if the given component was specifically responsible for the update. If a child or parent changes state, this shouldUpdate function returns false.

function shouldUpdate ({ state, lastState, componentTriggeredUpdate }) {
  return componentTriggeredUpdate && state !== lastState
}

You can also use shouldUpdate to change the rendering behavior with mutable state objects. For instance, you might check for changes in the values of essential state attributes.

const important_attributes = [ 'value', 'index' ]

function shouldUpdate ({ state, lastState }) {
  return important_attributes.reduce((accum, k) => {
    return accum || state[k] !== lastState[k]
  }, false)
}

Arguments vs. Properties

Tinier generally follows the approach taken by React for dealing with attributes and properties. All properties of a tag in JSX (or tinier.createElement) are set as attributes with the exception of the following that have special behavior.

Boolean attributes

Tinier will convert boolean values to the correct string values required by attributes. For example, the checked attribute can be set with:

<input checked=true />

Autofocus

Instead of autofocus, make a callback with didMount:

didMount: ({ el }) => {
  el.getElementsByClassName('new-todo')[0].focus()
},

Or use the special then attribute like this if you want it to run every time the component renders:

<input then={ el => el.focus() } />

API

tinier.createComponent({ ...args })

Arguments as args object:

  • displayName: String, default '' - A display name for the component mainly used for debugging.
  • model:
  • init: (Object) => Object, Default
  • signalNames: [String], default [] - A list of signal names as strings.
  • interface: tinier.Interface | null, default null - A Tinier Interface.