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

node-red-contrib-reducere

v2.0.0

Published

Redux-like state management for Node-RED

Downloads

4

Readme

Node Red Contribution: Reducere State Management

Build Status npm version

A State Management solution for Node-RED heavily inspired by the popular JavaScript state container library Redux. Just like in Redux, one consistent ('Single source of truth') application state is maintained in form of a JSON object.

This project was developed within the context of the ProFi research project funded by the German Federal Ministry of Education and Research.

Project status

This is an early but usable version which has been used for keeping a consistent state in a sizable scenario, where each of the components of the scenario communicated via MQTT. Bugs will probably occur. Most everything is subject for change, backwards compatibility is not the biggest concern at this stage.

Installation

This assumes you have Node-RED already installed and working, if you need to install Node-RED see here.

Navigate to your Node-RED user directory:

# Windows default path
$ cd 'C:\Users\YOUR_USER_NAME\.node-red'

# Linux default path
$ cd ~/.node-red

Then install via Node Package Manager:

$ npm install node-red-contrib-reducere

After the installation is complete restart Node-RED. There should be a new section 'Reducere State Management' in the Nodes-pane on the left.

Future

If there is expressed interest in this project, the following list of features will be implemented:

  • [ ] Proper testing
  • [ ] Immutability checks for the substates and entire state
  • [ ] Checks for side effects in Reducer functions
  • [ ] In-project implementation for middlewares
  • [ ] Better documentation
  • [ ] A working example flow for better understanding

Included nodes

Currently three nodes are included in this project:

  • ActionCreator
  • Reducer
  • RootReducer

An explanation and example is given below. To obtain a better understanding for the concept behind a specific node please refer to the Redux documentation.

ActionCreator

Node that receives an event message and outputs an action.

Example

Possible received event message when a user hits a light switch:

{
  topic: "state/lightSwitch",
  payload: {
    lightSwitchStatus: "on"
  },
  _msgid: "6f907ddb.fdf2c4"  
}

Output action:

{
  type: "LIGHTSWITCH_ACTIVATED",
  status: "on"
}

Fields

  • Name: The name shown in the Node-RED workplace.
  • Type: The identifying type of the action. Choose a unique name that is descriptive of the event that occurred (E.g. LIGHTSWITCH_ACTIVATED).
  • Data Source: The name of the field in the incoming message's payload that contains the relevant data of the occurred event (E.g. 'lightSwitchStatus', which could contain the values 'on' or 'off').

Reducer

A node that takes an action and a current substate and returns a new substate.

Note: It is recommended to have an ActionCreator which creates an initialization action ('INIT') at the start of the application. This way the Reducer can return the initial substate it is responsible for.

Example

Possible initial state of a reducer:

{
  color: "red",
  status: "off"
}

Possible reducer function:

const reduce = (state, action) => {
  switch (action.type) {
    case 'INIT':
      return state;
    case 'LIGHTSWITCH_ACTIVATED':
      const newLightSwitchStatus = action.status;

      const updatedState = {
        ...state,
        status: newLightSwitchStatus
      }
      return updatedState;
    default:
      return state;
  }
}

Fields

  • Name: The name shown in the Node-RED workplace.
  • Initial State: The initial state of the substate this reducer is responsible for (E.g. {color: "green", status: "off"}).
  • Substate: The name of the substate this reducer is responsible for (E.g. "light").
  • Function: The actual reducer function that determines the new state.

RootReducer

A node that combines all Reducer nodes and sends out the full state on Output 1 and the current substate on Output 2. This way the relevant part of an application can simply listen to changes to the slice of the state that it is concerned with.

Simply route all the outputs of your Reducer nodes into the RootReducer's input. No further configuration is required.

Example

Possible full state for a simple IoT scenario:

{
  light: {
    color: "green",
    status: "off"
  },
  officeWindow: {
    open: "false"
  }
}

Each of the substates (light, officeWindow) are provided by a Reducer node.

Fields

  • Name: The name shown in the Node-RED workplace.