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

refable

v0.0.19

Published

Super simple JS framework.

Downloads

7

Readme

Refable

Super simple JS framework inspired by Stimulus.

Installation

npm install refable --save-dev

Application

Application is the main class for bootstrapping. Controllers are registered on an application instance. For registering glob of controllers please refer to your bundler's documentation.

import { Application } from "refable";
import Search from "./controllers/search";

const application = new Application();

application.register("search", Search);

application.run();

Controllers

Controllers are instances of classes that you register in your application. Each controller class inherits from the Controller base class. Controllers can be nested within controllers and can be referenced in the parent controller.

<div data-controller="search">
  <div data-controller="result"></div>
</div>
import { Controller } from "refable";
import Result from "./controllers/result";

export default class extends Controller {
  declare readonly resultController: Result;
  declare readonly resultControllers: Result[];

  created() {
    //
  }

  connected() {
    //
  }

  disconnected() {
    //
  }

  resultControllerConnected(result: Result) {
    //
  }

  resultControllerDisconnected(result: Result) {
    //
  }
}

Controller classes are templated so more specific elements can be used if needed.

import { Controller } from "refable";

export default class extends Controller<HTMLElement> {
  //
}

Values

<div data-controller="search" data-some-value="1"></div>
import { Controller } from "refable";

export default class extends Controller {
  declare readonly someValue: string;

  someValueChanged(value: string) {
    //
  }
}

Targets

Targets map important elements to controller properties.

<div data-controller="search">
  <div data-target="result"></div>
</div>
import { Controller } from "refable";

export default class extends Controller {
  declare readonly resultTarget: Element;
  declare readonly resultTargets: Element[];

  resultTargetConnected(el: Element) {
    //
  }

  resultTargetDisconnected(el: Element) {
    //
  }
}

Actions

Actions are for handling DOM events in controllers.

<div data-controller="search">
  <button data-action="click->find">Find</button>
</div>
import { Controller } from "refable";

export default class extends Controller {
  find() {
    //
  }
}

Action Options

You can append one or more action options to an action descriptor if you need to specify event listener options.

<button data-action="click->find[:option]">Find</button>

Following action options are supported:

:capture
:once
:passive
:stop
:prevent

Events

The Controller class has a method called dispatch that fires custom events. It takes an event name and an optional payload as arguments.

<div data-controller="search">
  <button data-action="click->find">Find</button>
</div>
import { Controller } from "refable";

export default class extends Controller {
  find(event: Event) {
    this.dispatch("found", { result: "found" });
  }
}

The dispatched event can be catched with an action in a parent element and handled in a different controller like an action. Optional payload is in event parameter's detail property.

Plain JS Example

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
  </head>
  <body data-controller="home">
    <script type="module">
      import {
        Application,
        Controller,
      } from "https://cdn.jsdelivr.net/npm/[email protected]/+esm";

      class Home extends Controller {
        connected() {
          console.log("Connected");
        }
      }

      const application = new Application();

      application.register("home", Home);
      application.run();
    </script>
  </body>
</html>