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

smrt

v1.0.0

Published

Small Reactive Templating

Downloads

12

Readme

SMRT

SMRT is a SMall experimental library from building functional and Reactive web Templates.

I am so smart, SMRT, I mean SMART.

Homer J. Simpson

SMRT can be used to add reactivity to an existing webpage, or to build a whole app.

🎮 View the Code Playground here

Getting Started

Add SMRT to your web page or app either as a package or as a script.

npm install smrt or <script src="https://unpkg.com/smrt"></script

Example

import smrt from 'smrt';

const myApp = smrt();

const helloWorldState = {
  userName: 'World',
};

const appTitle = {
  tag: 'h1',
  innerHTML: () => `Hello ${helloWorldState.userName} 👋`,
};

const userNameInput = {
  tag: 'input',
  value: () => helloWorldState.userName,
  events: {
    input: event => {
      helloWorldState.userName = event.target.value;
    },
  },
};

const helloWorldApp = {
  tag: 'div',
  children: [
    appTitle,
    userNameInput,
  ],
};

const parent = document.querySelected('#app');
myApp.run(helloWorldApp, parent, [myAppState]);

IMPORTANT Notice how in the example above userNameInput.value and appTitle.innerHTML are functions that return a value from helloWorldState? This makes that part of your DOM reactive to state changes.

Further examples can be found here

Docs

Reactivity

Component values can be reactive, or non reactive. A value will only be reacted to if it is read from a function in a components spec.

How Reactivity Works

Reactivity works by replacing each value in a state with a pair of getters and setters. When a component is first rendered, any template updates that require a value from state are recorded again that state item (in an array of observers). Then when a state item is change, the recorded updates are replayed, keeping the DOM upto date.

Creating Components

A component can be defined as either a function (returning a spec) or an object following the spec. Functions are useful for a few reasons:

  • If you want to pass a value to a component when it's fist rendered e.g. a prop,
  • You may want to create helpers for commonly used elements,
  • You may want to run an action when you component is first rendered e.g. a call to the server.

Otherwise most components will be simple objects.

Component Spec

possible component spec values: {
    tag: String: html tag name,
    attrs: {
      [any html attribute e.g. id]: value or function,
    },
    events: {
      any dom event e.g. click, change: function
    },
    value: value or function,
    children: array or function returning an array of components
}