Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
hyperapp-actionpack
Advanced tools
This is a proof of concept of how to build actions in a service container that you can manage globally.
This is a proof of concept of how to build hyperapp actions in a container that you can manage globally.
See composable-state for documentation on state updates.
npm install --save hyperapp-actionPack
How to wire your actions into your app.
import ActionPack from 'hyperapp-actionPack';
import { app, h, text } from 'hyperapp';
import { select, replace } from 'composable-state';
const actions = new ActionPack();
actions.declare('++', (props) => composable.select('counter', composable.replace(old => old + 1)));
actions.declare('--', (props) => composable.select('counter', composable.replace(old => old - 1)));
app({
init: {
counter: 0,
},
view: (state) => {
return h('div', { style: { display: 'flex', justifyContent: 'center', alignItems: 'center' } }, [
h('button', { type: 'button', onclick: actions.act('--') }, text('-1')),
h('div', {}, text(`${state.counter}`)),
h('button', { type: 'button', onclick: actions.act('++') }, text('+1')),
]);
},
});
Get access to the global state to decide how to properly update the state.
import ActionPack from 'hyperapp-actionPack';
import { select, replace, collect } from 'composable-state';
const actions = new ActionPack();
actions.declare('play-sound', (props, state) => (
state.enabled
? select('audioSrc', props.audioSrc)
: collect([])
));
As a convenience, all composable-state mutators are available as a third parameter to your state-mutator method.
import ActionPack from 'hyperapp-actionPack';
const actions = new ActionPack();
actions.declare('++', (props, _state, { select, replace }) => select('counter', replace(old => old + 1)));
And of course, your actions can schedule side-effects, too.
import ActionPack from 'hyperapp-actionPack';
const actions = new ActionPack();
const effectFx = (dispatch, props) => {
console.log(`Hello ${props.name} from my side-effect`);
};
const effect = (props) => [effectFx, props];
actions.declare('runMyEffect', (props, _state, { collect }) => [
collect([]),
effect({ name: 'world' }),
]));
Chaining actions together has never been easier
import ActionPack from 'hyperapp-actionPack';
const actions = new ActionPack();
actions.declare('step1', (props, _state, { collect }) => [
collect([]),
actions.andThen('step2', props),
]);
actions.declare('step2', (props, _state, { collect }) => collect([]));
For now, debugging is strictly console/devtools based.
To turn it on, just pass the global console
object into the constructor.
In the future, I may write proper debug/devtools adapter using the console api.
import ActionPack from 'hyperapp-actionPack';
const actions = new ActionPack(console);
actions.declare('++', (props, _state, { select, replace }) => (
select('counter', replace(old => old + 1))
);
If you want to split up your actions across multiple file, you can do-so easily with the handle singleton static method.
actions1.js
import ActionPack from 'hyperapp-actionPack'
const actions = ActionPack.singleton();
actions.declare('foo', (_props, _state, { select, replace }) => select('name', replace('foo')));
actions2.js
import ActionPack from 'hyperapp-actionPack'
const actions = ActionPack.singleton();
actions.declare('bar', (_props, _state, { select, replace }) => select('name', replace('bar')));
app.js
import ActionPack from 'hyperapp-actionPack';
import { app, h, text } from 'hyperapp';
const actions = ActionPack.singleton();
app({
init: { name: null },
view: (state) => h('div', {}, [
h('div', {}, `Hello${state.name ? `, ${state.name}` : ''}`),
h('button', { type: 'button', onclick: actions.act('action1.foo') }, text('Foo')),
h('button', { type: 'button', onclick: actions.act('action2.bar') }, text('Bar')),
]),
});
FAQs
This is a proof of concept of how to build actions in a service container that you can manage globally.
The npm package hyperapp-actionpack receives a total of 1 weekly downloads. As such, hyperapp-actionpack popularity was classified as not popular.
We found that hyperapp-actionpack demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.