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

@coldwired/router

v0.11.4

Published

A router based on @remix-run/router and @coldwired/actions

Downloads

50

Readme

@coldwired/router npm package

Why?

At work we have a six-year-old reasonably big rails app. It powers quite a successful service while being run by a small team. It's an old school, server rendered rails app. The team is not interested at all in migrating to a JavaScript framework. But we do have some pieces of the app that requires dynamic components. Recently we introduced hotwired/turbo into our code base and it is quite a success. The team likes the minimal JavaScript API surface a lot. But turbo has problems. Those problems are very similar to the ones solved by @remix-run/router. The main one is coordinating multiple submitting forms on one page without full reloads.

How?

This project is an almost "drop in" replacement of turbo-drive with remix based router. It does several things:

  • intercepts click and submit events to navigate with client router
  • use morphdom to render pages
  • bypass in browser routing if data-turbo="false" is set on links and forms
  • provide a directive to register fetchers (data-turbo-fetcher)
  • provide a directive to submit forms on changes (data-turbo-submit-on-change)
  • provide a directive to revalidate pages (data-turbo-revalidate)
  • in fetcher responses, accepts turbo-stream format and bypass revalidation in those cases
  • if data-turbo-method is used on <a> it will submit the link instead of navigating
  • if data-turbo-disabled is used on <input>, <select> or <button> it will atomatically disable them during submission
  • if data-turbo-confirm is used on <a> or <form> it will ask for confirmation before submitting/navigating
  • preserve class attribute changes between renders unless data-turbo-force directive is used
  • preserve aria- and related attributes changes between renders unless data-turbo-force directive is used
  • preserve value on touched <input> and <select> between renders unless data-turbo-force directive is used
  • extends turbo-stream with ability to delay actions
  • extends turbo-stream with ability to pin actions between renders

Demo

@coldwired rails demo

Usage

In order to use this router you need to generate (or write) a JSON array of all the routes exposed by your server. You must add method to route handles in order for router to register loaders and actions. No nested routing for now – we might explore the possibility later but it will require a much more involved server. All the requests to your server will have a header x-requested-with: coldwire. In order for redirects to work properly you must respond with a 204 and a x-coldwire-redirect: <url> header instead of the usual 30* and a location: <url> header.

import { Application, type RouteObject } from '@coldwired/router';

const routes: RouteObject[] = [
  {
    path: '/',
    id: 'root',
    handle: { method: 'get' }
  },
  {
    path: '/login',
    id: 'login',
    handle: { method: ['get', 'post'] }
  }
];

const application = await Application.start({ routes });
<html>
  <body data-turbo>
    <form>
      (...)
    </form>

    <div data-turbo="false">
      <form>
        (...)
      </form>
    </div>

    <ul>
      <li id="item_1">
        <form data-turbo-fetcher>
          (...)
        </form>
      </li>
      <li id="item_2">
        <form data-turbo-fetcher>
          (...)
        </form>
      </li>
    </ul>
  </body>
</html>