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 🙏

© 2025 – Pkg Stats / Ryan Hefner

immstruct-actions

v0.9.0

Published

A function dispatcher central to invoke actions for manipulating immstruct data.

Readme

immstruct-actions NPM version Build Status Dependency Status Gitter

A library helping structure functions intended as actions in a React or Omniscient.js architecture, for providing opinionated helpers and tools for easier use.

Can this be achieved with just functions? Yes. This is just a guide for helping organizing functions and streamlining how to pass functions around. A action dispatcher object has subscribe possibilites, but if used with immstruct, this isn't needed. But there is nothing forcing you to use immstruct with this library, even though it is called immstruct-actions.

Install

Install immstruct-actions through npm.

$ npm install --save immstruct-actions

Example Usage


// New empty actions
var actions = require('immstruct-actions');

// Immutable action dispatchers. Returns new ones
var myActions = actions.register(function double (n) {
  return n * 2;
});

var otherActions = actions.register('plus2', (n) => n + 2);

// Combine two actions
var combined = myActions.combine(otherActions);

// invoke one action
var num = combined.invoke('double', 4); //> 8

// Create composed invoker
var numPlus2 = combined.createComposedInvoker('double', 'plus2')(4); //> 10

Example In Omniscient

// Passing to components in React or Omniscient.js

var actions = require('immstruct-actions');
var component = require('omniscient');

var MyButton = component(({text, changeSomething}) =>
  <button onClick={changeSomething}>{text}</button>
);

// Use destructuring to unwrap changeSomething
var App = component({text, actions: { changeSomething }} =>
  <MyButton text={text} changeSomething={changeSomething} />
);

var myActions = actions.register(function changeSomething () {
  // Change some state.
});

myActions = myActions.subscribe(render);
render();
function render () {
  // Fetch all functions from myActions
  React.render(<Button text="Click me" actions={myActions.fn} />, el);
}

API Reference

actions

Returned when requiring the module.

Create a pocket of actions as defined by initial optional actions and optional subscribers. Used to create new immutable action dispatchers.

Example

var actions = require('immstruct-actions');
var myActions = actions.register(function double (i) { return i * 2; });
var double2 = myActions.invoke('double', 2); //> 4
var double = myActions.fn.double;

Properties

| property | type | description | | ------------- | ------------------------- | --------------------------- | | actions | Object.<String, Function> | attached to the dispatcher | | subscribers | Array. | attached to the dispatcher | | fns | Array. | attached to the dispatcher |

actions.invoke(actionName, rest)

Create a pocket of actions as defined by initial optional actions and optional subscribers. Used to create new immutable action dispatchers.

Example

var double2 = actions.invoke('double', 2); //> 4

Parameters

| param | type | description | | ------------ | --------------------- | ------------------------------------ | | actionName | Array.,String | Invoke a named function | | rest | Object | Optional arguments passed to action |

Returns Any,

actions.subscribe(fn)

Add subscriber. Is triggered when any action is invoked. This returns a new actions dispatcher, as action dispatchers are immutable.

Example

var newActionsWithSubscriber = actions.subscribe(function subscriber () {
 // ...
});

Parameters

| param | type | description | | ----- | -------- | -------------------- | | fn | Function | Subscriber function |

Returns actions,

actions.unsubscribe(fn)

Remove subscriber. This returns a new actions dispatcher, as action dispatchers are immutable.

Example

function subscriber () {
 // ...
}
var newActionsWithoutSubscriber = actions.unsubscribe(subscriber);

Parameters

| param | type | description | | ----- | -------- | -------------------- | | fn | Function | Subscriber function |

Returns actions,

actions.register([actionName], fn)

Register new action. This returns a new actions dispatcher, as action dispatchers are immutable.

If not actionName is defined, it uses name of function passed in.

Example

var actions = require('immstruct-actions');
var myActions = actions.register(function double (i) { return i * 2; });
var double2 = myActions.invoke('double', 2); //> 4
var double = myActions.fn.double;

Parameters

| param | type | description | | -------------- | -------- | ----------------------------------- | | [actionName] | String | optional: Name of action function | | fn | Function | Subscriber function |

Returns actions,

actions.remove(fn)

Remove existing action. This returns a new actions dispatcher, as action dispatchers are immutable.

Example

var actions = require('immstruct-actions');
var myActions = actions.register(function double (i) { return i * 2; });
myActions = myActions.remove('double');

Parameters

| param | type | description | | ----- | -------- | -------------------- | | fn | Function | Subscriber function |

Returns actions,

actions.createComposedInvoker(functions)

Create a composed invoker of two or more actions.

Example

var actions = require('immstruct-actions');
var myActions = actions.register(function double (i) { return i * 2; });
myActions = actions.register(function plus2 (i) { return i + 2; });
var doublePlus2 = myActions.createComposedInvoker('double', 'plus2');

Parameters

| param | type | description | | ----------- | -------------- | -------------------------------------- | | functions | Array. | Functions names of actions to compose |

Returns Function,

undefined

fns

actions.combine(functions)

Combine one or more action dispatchers. Returns a new action dispatcher which has all the actions and subscribers of the action dispatchers passed as input.

Example

var actions = require('immstruct-actions');
var myAction1 = actions.register(function double (i) { return i * 2; });
var myAction2 = actions.register(function plus2 (i) { return i + 2; });
var myActions = myAction1.combine(myAction2);
doublePlus2 = myActions.createComposedInvoker('double', 'plus2');

Parameters

| param | type | description | | ----------- | -------------- | -------------------------------------- | | functions | Array. | Functions names of actions to compose |

Returns Actions,

actions.fn

Property getting all functions added as actions. Will trigger subscribers but can be used as standalone functions.

Example

var actions = require('immstruct-actions');
var myAction1 = actions.register(function double (i) { return i * 2; });
var double = myActions.fn.double;
// or with destructuring
var {double} = myActions.fn;

License

MIT License