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

@qvvg/sos

v3.2.2

Published

State Owned State

Downloads

11

Readme

State Owned State

Free the state, so your views can focus on the visual stuff.

People keep pretending they can make things hierarchical, categorizable and sequential when they can't. Everything is deeply intertwingled. –Theodor Holm Nelson

Install

npm install --save @qvvg/sos

Examples

Please see the examples directory for more.

// counter-domain.js
import {
  Domain,
  label,
  withName,
  deps,
  config,
  broadcast,
  handleInit,
  handleTell,
  handleContinue,
} from '@qvvg/sos'
import * as api from '../api/counter.js'

export default Domain([
  label('counter'),
  withName(),

  deps(() => ({
    getCount: api.getCount,
    saveCount: api.saveCount,
  })),

  config('delta', 1),

  broadcast('count', state => ({
    id: state.id,
    count: state.count,
  })),

  handleInit(async (ctx, id) => {
    const count = await ctx.deps.getCount(id)
    const subs = new Set()
    return ctx.Ok({id, count, subs})
  }),

  handleTell('subscribe', (ctx, state, sub) => {
    state.subs.add(sub)
    ctx.broadcast.count([sub], state)
    return ctx.Ok(state)
  }),

  handleTell('unsubscribe', (ctx, state, sub) => {
    state.subs.delete(sub)
    return ctx.Ok(state)
  }),

  handleTell('inc', (ctx, state, delta = ctx.config.delta) => {
    state.count += delta
    ctx.broadcast.count(state.subs, state)
    return ctx.Ok(state, ctx.Continue('save'))
  }),

  handleTell('dec', (ctx, state, delta = ctx.config.delta) => {
    state.count -= delta
    ctx.broadcast.count(state.subs, state)
    return ctx.Ok(state, ctx.Continue('save'))
  }),

  handleContinue('save', (ctx, state) => {
    ctx.deps.saveCount(state.id, state.count)
    return ctx.Ok(state)
  }),
])
// counter-sidecar.js
import {withSidecar, label, handleInit, handleTell, handleTerminate} from '@qvvg/sidecar'
import counter from './counter-domain.js'

export default withSidecar(
  label('counterSidecar'),

  deps(() => ({
    counter,
  })),

  handleInit((ctx, props) => {
    ctx.deps.counter.init(props.id)
    ctx.deps.counter.tell(props.id, 'subscribe', ctx.self())
    return ctx.Ok({id: props.id})
  }),

  handleTell(counter.events.count, (ctx, state, {count}) => {
    ctx.setProps({count})
    return ctx.Ok(state)
  }),

  handleTerminate((ctx, state, reason) => {
    ctx.deps.counter.tell(state.id, 'unsubscribe', ctx.self())
    return reason
  })
)
// counter-component
import React from 'react'
import withCounter from './counter-sidecar.js'
import counter from './counter-domain.js'

export const Counter = ({id, count, inc, dec}) =>
  count == null ? null : (
    <div>
      <h3>
        {id}: {count}
      </h3>
      <div>
        <button onClick={() => dec(id, 5)}>-5</button>
        <button onClick={() => dec(id)}>-1</button>
        <button onClick={() => inc(id)}>+1</button>
        <button onClick={() => inc(id, 5)}>+5</button>
      </div>
    </div>
  )

Counter.defaultProps = {
  count: null,
  inc: (id, ...args) => counter.tell(id, 'inc', ...args),
  dec: (id, ...args) => counter.tell(id, 'dec', ...args),
}

export default withCounter(Counter)
import React from 'react'
import Counter from './counter-component.js'

export default () => (
  <div>
    <Counter id="foo" />
    <Counter id="bar" />
    <Counter id="baz" />
  </div>
)