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.

What if it was only actions?

See original GitHub issue

I am rewriting parts of the documentation and currently revisiting the eternal reducers Vs effects.

Why do we need to force users to think about reducers and effects instead of just actions?

If an action returns a promise, we know it’s an effect, otherwise it’s a reducer.

app({
  model: {
    counter: 0,
    waiting: false
  },
  actions: {
    add: model => ({ counter: model.counter + 1 }),
    toggle: model => ({ waiting: !model.waiting }),
    waitThenAdd: (model, actions) => {
      actions.toggle()
      return new Promise(resolve => setTimeout(_ => resolve(), 1000))
        .then(actions.add)
        .then(actions.toggle)
    }
  },
  view: (model, actions) =>
    <button
      onclick={actions.waitThenAdd}
      disabled={model.waiting}
    >
      {model.counter}
    </button>
})

The only drawback is that Promises are not supported in IE11, so obviously we can’t change this right now.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:48 (30 by maintainers)

github_iconTop GitHub Comments

2reactions
nichothcommented, Mar 4, 2017

@dodekeract Isn’t that how it works currently? You can just call multiple actions from within an action, don’t return anything.

effects: {
    asyncThing: function (state, actions) {
        actions.startRequest()
        fetch(function (err, resp) {
            if (err) return actions.error()
            actions.resolve()
            actions.setState(resp)
        }
    }
}
2reactions
nichothcommented, Mar 4, 2017

Ok, it sounds like it is a style thing. I generally prefer callback hell over new language syntax.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I never worry about action, but only... Winston Churchill - Forbes
I never worry about action, but only about inaction. ... Rightness expresses of actions, what straightness does of lines; and there can no...
Read more >
Harm Principle Overview & Examples - Study.com
The harm principle is the principle that only those actions that create harm should be prevented. The British philosopher John Stuart Mill ...
Read more >
Assign and Assign only actions - Anapedia - Anaplan
Assign only enables you to assign list items to a parent, but not unassign items that have already been assigned. List items can...
Read more >
What are your thoughts on the saying 'there is no right ... - Quora
What they mean is that there are no moral absolutes. Nothing is ever completely right or completely wrong. The rightness or wrongness of...
Read more >
Can You Beat Borderlands 2 With ONLY Action Skills?
This video is sponsored by Ridge Wallet: https://www.ridge.com/DIAPERBOOTY Use Code "DiaperBooty" for 10% off your order!
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