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

@ursi/support

v2.0.0

Published

The JavaScript component to the SupPort Elm package

Downloads

3

Readme

SupPort

This is the JavaScript component to the SupPort Elm Package. The documentation for using SupPort on the Elm side is in that package.

To get up and running with SupPort on the JS side, start by importing the SupPort function and creating your port handling function.

import SupPort from '@ursi/support';

const app = Elm.Main.init()

const port = SupPort(app.ports);

Full API

port(portName, handler [, inOnly [, useOutOnly]])

  • portName: This is a string that is equal to the first part of your In/Out port pair.

  • handler: This is an object whose keys correspond to the strings passed to the SupPort.out function (in Elm), and whose values are functions that take the Json.Encode.Values passed to SupPort.out as their arguments.

    The handler methods can return 4 different things:

    • A 2-tuple (array): The 2 values correspond to the appropriate value in the List ( String, Decoder Msg ) passed into SupPort.in_ in Elm.

      e.g. ['NumberReceived', 5]

    • Just a string: This is shorthand for sending a tuple using the given string and having the data equal to null.

    • A function: This is the most general case. The returned function takes in, as its only argument, a function of two arguments. These two arguments correspond to the appropriate value in the List ( String, Decoder Msg ) passed into SupPort.in_ in Elm.

      e.g.

      port(`timer`, {
          StartTimer() {
              return send => {
                  setInterval(() => send(`TimeReceived`, Date.now()), 1000);
              }
          };
      });
    • undefined: If nothing (undefined), is returned SupPort will not attempt to send any information back to Elm.

    The value of this in each of the handler methods is handler, so data can be shared between them without using the global scope.

  • inOnly: This is an object used to specify values that are sent into Elm without first needing to be set up by a value coming out of Elm. Maybe you just want to listen to the scroll event of the window at all times.

    Usually, the keys of this object represent the string part of data going into Elm. The values are functions that take 2 functions as their arguments.

    • send: This function takes a single argument - a value to be passed into Elm. The string that accompanies this value will be the name of the method.
    • sendTo: This function doesn't restrict which message you're sending back in. It takes 2 arguments. The first is a string, the second the value to be passed into Elm.

    Here is how you could write out the scroll example above:

    port(`ports`, {}, {
        Scrolled(send) {
            addEventListener(`scroll`, function() {send(this.scrollY);});
        }
    });
  • useOutOnly: If you only want to send values out of Elm, you can set this to true so that port doesn't throw an error when it can't find your in-port.