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

@livefir/fir

v0.3.0

Published

Alpinejs plugin for Fir: Fir is a go toolkit to build reactive web interfaces using: Go, html/template and alpinejs.

Downloads

160

Readme

Introduction

The @livefir/fir package is a companion alpine.js plugin for the Go library pkg.go.dev/github.com/livefir/fir. Fir is a Go toolkit to build reactive web interfaces using: Go, html/template and alpinejs.

Installation

The plugin can be included as a script tag before the alpine.js include.

    <head>
        <script
            defer
            src="https://unpkg.com/@livefir/fir@latest/dist/fir.min.js"></script>
        <script
            defer
            src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
    </head>

See example.

API

The plugin provides event handlers custom magic and directives.

Event handlers

Fir depends on alpinejs custom event handlers to update the DOM. Event handlers are of the syntax:

<x-on:@>:fir:event-id:event-state<ok|error|pending|done>::template-name<optional>

For e.g,

<div @fir:create-todo:ok::todo="$fir.prependEl()">
   {{ range .todos }}
       {{ block "todo" . }}

       {{end}}
   {{end}}
</div>

The expression @fir:create-todo:ok::todo means that if create-todoevent handler returns with a non-error response then re-render the template named todoand send the html to the browser. The event handler utility function $fir.prependEl()picks the returned html from event.detail.htmland prepends it to the current element. For a full list of utiliy functions see section Magics

The ::template-name binding is optional. It is useful for situations where one needs to re-use a template out-of-band like the example above.

Fir automatically extracts a template from any element which contains html/template actions.

For e.g.

<p @fir:create-todo:error="$fir.replace()">
    {{ fir.Error "create-todo.text" }}
</p>

Here Fir automatically extracts a template out of the content of ptag. Under the hood, this is how it looks like:

<p @fir:create-todo:error::fir-kxkccoas8d9="$fir.replace()">
    {{ fir.Error "create-todo.text" }}
</p>

Event states

  • ok: when OnEvent handler returns a non-error response.
  • error: when OnEvent returns an error response.
  • pending: client-only for loader states. triggered before the Event is sent to the server.
  • done: client-only for loader states. triggered on both ok and error response from the server.

Directives

x-fir-mutation-observer implements the https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver as an alpine directive. It allows you to observe changes to the DOM and react to them.

e.g.

x-fir-mutation-observer.child-list.subtree="if ($el.children.length === 0) { empty = true } else { empty = false }"

Magics

See api.md

Modifiers

.nohtml modifier tells the server to not send the resultant html to the client. This is useful in cases like these:

 @fir:create:ok.nohtml="$el.reset()"

 @fir:delete:ok.nohtml="$fir.removeEl()"