Comments (3)
@sqren Sorry I didn't see your comment until now. For some reason didn't have notifications on for this repo.
I'm confused as to how having multiple listeners with the same name would work.
Let's say:
- I'm on window A.
- I send
foo
message to window B. - Window B has 2 listeners for
foo
Which listener on window B gets called?
If you're suggesting that both should be called, that also wouldn't work too well with post-robot, since the listener can also return something to the other window:
postRobot.on('myEventName', function() {
return 5;
});
postRobot.on('myEventName', function() {
return 10;
});
If we were to call both listeners, how would we know whether to return 5 or 10 to the other window?
It's better to think of post-robot as letting you create global functions that you can call from other windows. Like any function, you call it once, and you get a single return value (or exception).
I think, if you want multiple event listeners, and you're not interested in the return value, you can always use something like EventEmitter to broadcast the event on the target window. So:
var emitter = new EventEmitter();
postRobot.on('myEventName', function() {
emitter.emitEvent('myEventName');
});
emitter.addListener('myEventName', function() {
// Do something
});
emitter.addListener('myEventName', function() {
// Do something else
});
Does that work for your use-case?
from post-robot.
@bluepnume Now it's my time to apologise for the slow reply. On a completely unrelated node I stumbled upon this article and was like: wait? wasn't that the post-robot guy - who wrote a reply last week...
Aaaanyways :)
I went exactly the route you suggested above. Didn't think about the return values being an issue - makes sense.
Thanks.
from post-robot.
Cool! Glad it worked :)
from post-robot.
Related Issues (20)
- how to install it in VUE HOT 1
- Mismatch between post-robot and @types/post-robot HOT 1
- post-robot in React - cannot read properties of undefined (send) HOT 2
- Getting Error: when doing async communication
- WeakMap expected key HOT 1
- Missing timeout on function HOT 5
- Serializing circular objects and toJSON HOT 2
- Permission denied to access object on Firefox HOT 4
- postRobot.send block Angular Material 7 change detection HOT 3
- Cross domain, with 3rd party cookies blocked. HOT 3
- Postrobot fails after 2000ms because of failed ack sending HOT 4
- Listen for (or send) events on multiple domains HOT 1
- Uncaught DOMException: Blocked a frame with origin "<origin name>" from accessing a cross-origin frame. HOT 3
- No handler found for post message, using in chrome extension HOT 3
- IE / Edge Prompting to Install App for mock://foo.com with bridge
- Create TypeScript typings HOT 13
- Not working on newer versions of Google Chrome? HOT 3
- React Native webview HOT 5
- Sending Messages from Parent to IFrames seems to not work HOT 1
- Window did not load after 5000ms
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from post-robot.