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.

How to put() within a callback?

See original GitHub issue

There have been a few instances where I’ve wanted to put within a callback to realize that the action never gets reduced on. Is it possible to do the following with sagas?

function* hideNotification() {
  let clearTimer = null;
  const { SET_NOTIFICATION, CLEAR_NOTIFICATION } = NotificationActions.actionTypes;

  while(true) {
    const action = yield take([SET_NOTIFICATION, CLEAR_NOTIFICATION]);
    if (clearTimer) {
      clearTimeout(clearTimer);
      clearTimer = null; 
    }

    if (action.type === SET_NOTIFICATION) {
      clearTimer = setTimeout(() => put(NotificationActions.clearNotification()), 300);
    }
  }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:18
  • Comments:36 (11 by maintainers)

github_iconTop GitHub Comments

13reactions
MrsBookikcommented, Mar 26, 2017

I still don’t get it. I’ve read several issues and other texts about this topic… Mostly they solve complex problems and not a simple thing like mine. Can someone point me to a tutorial or something else that shows me how to pass a simple “yield put” within a callback?

In my scenario i have to place a callback to receive the progress of a download-task and i want to put it into the redux-store with “yield put”.

All i want to do is something like this:

function onDownloadFileProgress(data) {
  yield put({type: ACTIONS.S_PROGRESS, progress})
}

How to achieve that simple case? And why is it so difficult?

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Callback Functions – What are Callbacks in JS and ...
In JavaScript, the way to create a callback function is to pass it as a parameter to another function, and then to call...
Read more >
How to access the correct this inside a callback
We explore the methods for accessing the correct this in a callback by explicitly forcing a context binding to point to our object...
Read more >
How to access the correct `this` inside a callback?
Approach: First create an object and enter sample properties. Make sure you add a function for one key, in that function add a...
Read more >
javascript - How to access the correct `this` inside a callback
1. Use the bind() function. function MyConstructor(data, transport) { this.data ...
Read more >
Mastering 'this' in JavaScript: Callbacks and bind(), apply(), call()
Mastering 'this' in JavaScript: Callbacks and bind(), apply(), call(). Mar 2nd, 2018 10:23am by Michelle Gienow.
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