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

element-action

v1.0.2

Published

A simple, fast and composable library for creating reactive web interfaces

Downloads

17

Readme

Element Action

This is a simple, composable and extensible library for creating reactive web interfaces. It exports primitives which can be used to describe DOM operations with element attributes. It is based on the class-action and action-object libraries.

Element-action operates based on a Component typw which is a ClassAction sub-type that recursively processes elements to interprete attribute directives. Other class actions (known as component actions) are nested within the component to perform the interpretative functions. This affords enormous flexibility in what meanings can be attached to directives. Component actions for common functions, like linking element properties to javascript variables, have been implemented. Further actions may be created by 3rd-party providers or users themselves.

Installation

npm i element-action

Usage

<h1>Planets</h1>
<main>
    <h2 t>#planets.mercury</h2>
    <section t>$planets.mercury2</section>
    <section t>#planets.venus</section>
    <aside textContent-p="#sun"></aside>
    <div class-a="#colors.light" t>#planets.earth</div>
</main>
<footer></footer>
import { Component } from "element-action";
import { ActionObject } from "active-object";

const root = {
    sun: 0,
    planets: {
        mercury: 1,
        mercury2() { return 11;},
        venus: 2,
        earth: 3,
        mars: 4,
        jupiter: 5
    },
    colors: {
        light: 'yellow',
        dark: 'navy',
        medium: 'red'
    }
}

const component = new Component();
const actionRoot = new ActionObject(root);
const element = document.querySelector('main');
component.act({element, actionRoot})

const colors = actionRoot.getChild('colors');
const planets = actionRoot.getChild('planets')
// 1 link to property set:

// 1.1 linked attribute
colors.set('light', 'green');  
console.log(element.querySelector('div').getAttribute('class'));   // green

// 1.2 linked text content
planets.set('mercury', 'sub-heading 1');  
console.log(element.querySelector('h2').textContent);   // sub-heading 1 

// 2 link to method call:
planets.call('mercury2');  
console.log(element.querySelector('section').textContent);  // 11

Documentation

This library exports class actions for common reactive actions, like data binding. Learn about them here. Loops and conditionals have been deliberately omitted to avoid complicating the library. In scenarios where you need those functions, it is best to use the library within your code to achieve whatever effect you need. This is trivial to implement.

Contributing

Help improve Element-action by contributing to this project. You can contribute in many ways. See the contributing guidelines. You can also show your support by sponsoring us.

Thank you for contributing.

Sponsors

...