How to dispatch in event handler?
See original GitHub issueI have this function that I call inside one of my sagas
function getDeviceTokenAsync() {
return new Promise((s,e) => {
if (window.PushNotification) {
let push = window.PushNotification.init({
android: {
senderID: GCM_SENDER_ID,
icon: "ic_notification",
iconColor: PRIMARY_COLOR,
},
ios: {
alert: true,
badge: false,
sound: false,
},
windows: {
},
})
push.on("registration", s)
push.on("notification", (data) => {
console.info("notification: " + JSON.stringify(data))
//put(actions.refreshPendingTransactions())
})
push.on("error", e)
} else {
e(new Error("No push notification available"))
}
})
}
I call it with
yield call(getDeviceTokenAsync)
The question is, how do I dispatch an action to the store whenever the onnotification
handler is called by the push service?
Should I hand in a function to getDeviceTokenAsync
and that function yields a put
effect then?
Issue Analytics
- State:
- Created 7 years ago
- Comments:26 (25 by maintainers)
Top Results From Across the Web
EventTarget.dispatchEvent() - Web APIs | MDN
The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected EventListener s in the ...
Read more >Dispatching custom events - The Modern JavaScript Tutorial
Unlike "native" events, which are fired by the browser and invoke event handlers asynchronously via the event loop, dispatchEvent() invokes ...
Read more >JavaScript dispatchEvent(): Generate Events programmatically
JavaScript dispatchEvent · First, create a new Event object using Event constructor. · Then, trigger the event using element.dispatchEvent() method.
Read more >Handling and dispatching events with Node.js - LogRocket Blog
Learn how to create, dispatch, and manage events in Node.js. ... Instead, we'll discuss how to handle and dispatch events in Node.js.
Read more >Create and Dispatch Events - Salesforce Developers
Create and dispatch events in a component's JavaScript class. To create an event, use the CustomEvent() constructor. To dispatch an event, call the...
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 FreeTop 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
Top GitHub Comments
@pke eventChannels are now part of redux-saga API
https://redux-saga.github.io/redux-saga/docs/advanced/Channels.html
In your example, it’d be something like
So if you’re really really stuck:
Wherever you’re creating the store:
Wherever you need dispatch: