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

circuit-js

v0.0.3-alpha

Published

Functional JavaScript in a hash

Downloads

5

Readme

Circuit-js

Build Status

A library for building applications using circuit architecture - a functionally declarative software pattern that promotes application development through pure functions, composition and associativity - wrapped in a JavaScript hash.

Installation

npm install --save circuit-js

The basics

Circuit-js uses standard object syntax to define connectible signals that propagate data state changes though a circuit.

import React from 'react'
import {render} from 'react-dom'
import Circuit from 'circuit-js'

// Some functions to change state
const add = (list, item) => list.concat(item)
const remove = (list, idx) => list.filter((_, i) => i !== idx)
const bind = channel => ({target, keyCode}) => keyCode === 13 && channel(target.value)

// A function to generate a view
const view = ({items}) => {
  const {add, remove} = todos.channels.items
  return <div>
    <h1>todos</h1>
    <ul>{items.map((item, i) => <li key={i}>
      <span>{item} </span>
      <button onClick={() => remove(i)}>x</button>
      </li>)}
    </ul>
    <input key={items} placeholder="What do you want to do?" onKeyDown={bind(add)}/>
  </div>
}

// a function to mount a component
const app = component => render(component, document.querySelector('#todo'))

// A circuit to pull it all together.
const {circuit, merge} = new Circuit()
const todos = circuit({
  items: merge({add, remove}) // merge add and remove channels into items
})

todos.map(view).tap(app)

// go!
todos.input({items: ['first entry']})

So what just happened?

An app was born.

There are three signals in this app: add, remove and items, each correlating to a function on the object passed in to the circuit function:

const todos = circuit({
  items: merge({
    add,
    remove
  })
})

The circuit function returns an active circuit todos with three input channels connected to the underlying signals. The app binds two of them, channels.add and channels.remove in the view so that when the user types in a new todo, or clicks on remove todo, the circuit is activated through the bindings.

The circuits delivers the bound values to the appropriate functions and they return their values back into the circuit! Where do these values go? They bubble up through the circuit. The add signal value is merged into the items signal. The items signal value is joined to the circuit (there's no merge function here), and the circuit signal value is mapped and tapped over the view and app functions respectively.

A signal propagation diagram shows what is happening in the circuit:

PROPAGATION
| SIGNALS   TIMELINE ->
| add:      --------------v2---------------------------------->
| remove:   ----------------------------------1--------------->
| items:    ---------------[v1, v2]-----------[v1]------------>
V circuit:  {items: [v1]}---{items: [v1, v2]}--{items: [v1]}-->

Round up

  • distinct separation of concerns - circuits, channels and overlays
  • consistent and predictable logic - composable, associative signals
  • functional behaviour - map, tap, reduce etc..
  • extensible - custom signals through binding and middleware

Copyright

Source code is licensed under the ISC License (ISC). See LICENSE.txt file in the project root. Documentation to the project is licensed under the CC BY 4.0 license.