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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tide-fire

v2.0.0

Published

A plugin for tide that fires action

Downloads

18

Readme

Tide Fire

What?

A plugin for tide that fire actions.

Why?

There are a few things that are somewhat problematic with actions in tide.

First, invoking actions in tide is always synchronous. It looks something like this:

this.tide.bar.getBeer({type: 'Singha'})

This means the action object has to exist and be registered with the tide instance when you invoke it. As an application grows you might want to load action classes only when they are needed, rather then loading them all upfront, which becomes pretty tricky, since you have to be sure the action exists before you call it (or you would end up with Cannot call function 'getBeer' of undefined).

Second, action classes are not straightforward to test, since they rely heavily on this. They also have to be executed in the correct context (this must be the tide instance), which can lead to weird bugs if you are not careful (Cannot call function 'mutate' of undefined).

Tide-fire aims to solve these problems.

How?

Tide-fire exposes one function:

  • init, has to be called before any actions are fired. You'd usually call this right after you have created your tide instance.

init

Init sets up tide-fire and bind the fire function to the tide instance. A call to init can look something like this:

init(tide, {
  bar: {
    getBeer: (data) => fetch(`/beers/${data.type}`).then((res) => res.body),
    getDrink: () => new Promise((resolve) => {
      setTimeout(() => { resolve('Margerita') }, 100)
    }),
  },
  travel: () => import('./travel.js'),
})

Actions are organized into objects. Above, the object bar has two action handlers: getBeer and getDrink. In a larger application, you'd probably create a file called bar.js which exported functions getBeer and getDrink.

We can also pass promises or functions that return promises into the init function. This is nice if you want code-split and lazy-load some actions. In the example above, travel.js would contain some action handlers that we don't want in our main bundle. They would only be loaded when one of those actions are invoked.

fire

After init has been called, there will be a fire property on the tide instance. Invoking an action with tide-fire looks like this:

tide.fire('bar.getBeer', {type: 'Singha'})

The first argument is the action name and the second is the data that will be passed to the action handler. fire() returns a promise that resolves to the return value of the action handler.

Action handlers

Tide-fire action handlers are pure functions. They can look something like this:

function getBeer(data, {get, set}) {
  return fetch(`/beers/${data.type}`).then((res) => set(['beers', data.type], res.body))
}

Action handlers will be called with two arguments:

  • The first argument is data – whatever was sent as second argument in the fire call.
  • The second argument is an object with the following contents:
    • get, gets things off the tide state. (Usage: get(['beers', 'singha']))
    • set, sets things on the tide state. (Usage: set(['beers', 'singha'], {taste: 'bland'}))
    • tide, the tide instance

Pro tip: set is curried, so you can do const setSinghaCount = set(['beers', 'singha', 'count']) and later on setSinghaCount(5).

Middleware

The third argument to init is an optional array of middleware. These are functions that can wrap action handlers and perform tasks like logging. Middleware has to return action handlers.

Here's an example middleware that measure how long action handlers take to complete:

const timingMiddleware = (fn, name) => (...args) => {
    const start = new Date()
    const rv = fn(...args)
    const end = function(ret) {
      console.log(new Date() - start)
    }
    if (rv && typeof rv.then === 'function') {
      rv.then(end, end)
    } else {
      end()
    }
    return rv
  }
}

Reporting issues

Issues should be filed here on github.