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

xcontrol

v0.1.5

Published

A flux implementation

Downloads

25

Readme

xcontrol

A lightweight state management library for browsers and node.

Related packages

API

  • Reactive(Super)

Overrides the Super's store get/set to notify all subscribers.

  • Subscribe(Super)(controllers, mapState, mapActions)

Subscribes the Super's store to the result of calling mapState with the combined state of all controllers. This value is recomputed whenever any controller's store update.

Concepts

xcontrol is a flux interpretation powered by four core constructs:

  • 💾 models
  • 🎮 controllers
  • 📡 subscribers
  • 💥 actions

Models store the state. They allow reading and writing state.

A Controller is a subsclass of Model, which overrides the Model's base state getters and setters. Controllers can have side effects whenever the Model's state is changed. These changes are intercepted in getters and setters. Therefore, by definition, any subclass of Model which overrides get/set state to cause side effects is a Controller.

One possible side effect is notifying subscribers of state changes. This is implemented by the reactive HOC. For instance, reactive(Model) enables subscribing to the Model's state changes. Whenever its state changes, all the subscribers are notified with the new state.

Subscribers consume a controller's state and cause actions. They connect to the store by passing it a function of state. Whenever the state updates, the function is called by the controller. Subscribers cause actions which may change the state.

Actions take a controller's current state and arguments, and compute the new state. They cause the controller to notify all subscribers by passing the new state to the callback they provided when subscribing.

There are two major types of actions.

Pure actions only modify the state, with no side effects. That is, in pseudocode: action = (state1, ...args) => state2.

Unpure actions cause side effects (other actions, logging, rendering, network calls... ). They can cause actions both from their own controller and from other controller instances. That is, unpure actions can subscribe to other controllers (they can read the state and cause actions). Unpure actions can also be asynchronous.

Classes

Model

a Model is a state container. It contains state, which cannot be accessed. It serves as a way of abstracting the process of reading / writing state. The basic Model prohibits reading the state, and allows setting it.

More complex models can be engineered. An idiomatic one could be TimeTravelModel. Whenever the state is set, a record of the previous state is kept. Calling timeTravelModel.back(n) method reverts the state to the nth previous state. Similarly for .forward(n).

Controller

a Controller is a Model with added functionality. It adds a publish/subscribe mechanism to a model. Whenever the model's state is set (ie.changes), it notifies all the subscribers with the new state.

Classes extending a controller implement actions.