Calling actions from within an action
See original GitHub issueI am getting some results I’m finding difficult to comprehend when I am calling actions from within an action, eg. the action setS1rS2 (on button S1rS2) compared to action setS1S2 in jsfiddle https://jsfiddle.net/WarwickGrigg/eo537smc/
Using latest hyperapp v 1.0.1. Excerpt below:
const actions = {
setS1: dt => (_, actions) => { return {s1: dt} }, // changes state
setS2: dt => (_, actions) => { return {s2: dt} }, // changes state
setS1S2: dt => (_, actions) => {
actions.setS1(dt); // changes state
actions.setS2(dt); // changes state
},
setS1rS2:dt => (_, actions) => {
actions.setS1(dt); // no effect (!)
return {s2: dt}; // changes state for s2
},
Results are different but even more confusing (for me) if I remove the ‘=> (_, actions)’ action function wrapper. Is there something special about calling actions from within an action?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Call an action from within another action - vue.js
I want to be able to call one action from within another, so in this example I want to be able to call...
Read more >Call Vuex action from another action - Koen Woortman
You can call another Vuex action by passing the name of that action as a string as the first argument of dispatch :...
Read more >Calling action inside another action in Vuex - Vue Forum - Vue.js
I have the following actions in Vue.js project Vuex store: import { HTTP } from '@/services/http' import router from '@/router' export const ...
Read more >calling actions from within an action? #344 - reduxjs/redux
So yes, indeed, these should be two separate actions called by one component. If one of them becomes async, the distinction is even...
Read more >Calling an Action inside another - ACCELQ
To call an action in the logic, type "call" and then select the Action to call. If the called Action requires any input...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, I found the fix changing line 107 to:
The interesting part is:
that basically computes the slice afresh.
Thanks, Jorge. And thank you for hyperapp - very promising and elegant. I’ve created a jsfiddle fork here https://jsfiddle.net/WarwickGrigg/rqqzqb9n/ with the action functions omitting the => (_, actions) wrapper, annotating the results: