question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling actions from within an action

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
jorgebucarancommented, Jan 6, 2018

Okay, I found the fix changing line 107 to:

if (data && data !== (slice = get(path, state)) && !data.then) {
  repaint((state = set(path, copy(slice, data), state, {})))
}

The interesting part is:

slice = get(path, state)

that basically computes the slice afresh.

2reactions
warwickgriggcommented, Jan 6, 2018

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:

const actions = {
  setS1: dt => { return {s1: dt} }, // changes state
  setS2: dt => { return {s2: dt} }, // changes state
  setS1S2: dt => {
    actions.setS1(dt); // no effect
    actions.setS2(dt); // no effect
  },
  setS1rS2:dt => {
    actions.setS1(dt); // no effect (!)
    return {s2: dt};   // changes state for s2
  },
  setS1cS2:dt => {
    s1obj = actions.setS1(dt); // assume no effect (?), but returns obj
    return Object.assign([], s1obj, {s2: dt}); // changes state`
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found