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

elm-system

v2.0.0

Published

Deploy a system of Elm applications as a single-page web app.

Downloads

10

Readme

elm-system

Elm System helps you compose many Elm programs into a web application.

Associate an Elm program with a route, and all requests to that route will be handled by that program. You can also use a headless Elm program as middleware, which could redirect a request as necessary or add flags that will be passed to the route program.

Elm Version

  • Elm System 2.x requires Elm 0.19
  • Elm System 1.x requires Elm 0.18

Example

var System = require("elm-system")
var AuthProgram = require("./elm/Authorization.elm")
var LoginProgram = require("./elm/Login.elm")
var ShowProgram = require("./elm/ShowStuff.elm")

var system = System()

system.useFlags({ baseUrl: "/api" })

system.useProgram(AuthProgram.Elm.Authorization)

system.route("/login").program(LoginProgram.Elm.Login)

system.route("/stuff/:stuffId").program(ShowProgram.Elm.ShowStuff, {}, function(app) {
  app.ports.doSomething.subscribe(function(things) {
    //some javascript
  })
})

system.mount(document.getElementById("main"))

Setup

To facilitate communication between the Elm programs that compose your web application and Elm System, you'll need to add some ports to your programs.

For the Html program associated with a route, you must add:

port request : (a -> msg) -> Sub msg

where a is the record type you expect. By subscribing to this port, your program will be notified whenever a new request to the program's associated route is received. The incoming record is composed of route parameters (see below) and any flags added by middleware.

For middleware, you must add two ports:

port request : (a -> msg) -> Sub msg
port next : b -> Cmd msg

where a is the record type you expect for each request and b is the record type passed on to the route program. The middleware program is notified via the request subscription on every request. The following flags are passed on each request:

{ path: '/the-current-path'
}

Once the middleware program has completed any processing, it must call next to send the command that will pass the request to the route program. The route program will receive any flags passed with this command.

Any type of program may add the following port:

port changeLocation : String -> Cmd msg

This function creates a command that changes the location to the path provided. With Elm System, you must use this port command to update the location (instead of, for example, elm-lang/navigation).

Configuration

Global Flags

Specify flags that will be passed to each program upon initialization:

system.useFlags({ aFlag: "flag1", bFlag: "flag2" })

Middleware

Specify a headless Elm program that will handle each request:

system.useProgram(MyElm.Worker, someProgramFlags, callback)

where someProgramFlags are the flags to pass to the program upon initialization and callback is a function that takes the initialized program. Use callback to configure the worker once it has been initialized (add any extra ports, etc).

Routing

Specify a route and associate it with an Elm program like so:

system.route("/my/route").program(MyElm.App, someProgramFlags, callback)

where someProgramFlags are the flags to pass to the program upon initialization and callback is a function that takes the initialized program. Use callback to configure the program once it has been initialized (add any extra ports, etc).

The route may contain wildcards using the * character. The route path may contain parameters. These will be passed to the Elm program as part of the record sent to the request port. So, if you configure a route like so:

system.route("/my/:thing/:id/*").program(MyElm.App)

then a request to /my/books/17/otherStuff will result in the request port being called with a record that looks like:

{ thing = "books"
, id = "17"
}

Note that all the values are strings.

Mounting

Once you have configured Elm System, just call mount with an Html Element. The programs will be mounted under this node.

system.mount(document.getElementById("main"))

Development

To run the tests:

npm test