Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28825 > unrolled thread
| Started by | Cezary Tomczyk <cezary.tomczyk@gmail.com> |
|---|---|
| First post | 2015-10-16 23:50 +0200 |
| Last post | 2015-10-18 22:39 +0200 |
| Articles | 6 — 2 participants |
Back to article view | Back to comp.lang.javascript
Promise and postMessage Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2015-10-16 23:50 +0200
Re: Promise and postMessage Martin Honnen <mahotrash@yahoo.de> - 2015-10-17 11:34 +0200
Re: Promise and postMessage Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2015-10-17 20:17 +0200
Re: Promise and postMessage Martin Honnen <mahotrash@yahoo.de> - 2015-10-17 12:18 +0200
Re: Promise and postMessage Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2015-10-17 21:06 +0200
Re: Promise and postMessage Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2015-10-18 22:39 +0200
| From | Cezary Tomczyk <cezary.tomczyk@gmail.com> |
|---|---|
| Date | 2015-10-16 23:50 +0200 |
| Subject | Promise and postMessage |
| Message-ID | <ec087$56217102$6def49cc$20239@nntpswitch.blueworldhosting.com> |
I use the Promise and postMessage together. Here is the example: http://www.ctomczyk.pl/lab/postmessage/ Instead of getting two different responses in two different Promises, I've got same response in two Promises from postMessage. See developer console. Why am I getting same response in two Promises when I see two different data send from iframe? -- Cezary Tomczyk http://www.ctomczyk.pl/
[toc] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2015-10-17 11:34 +0200 |
| Message-ID | <mvt4m8$g5n$1@news.albasani.net> |
| In reply to | #28825 |
Cezary Tomczyk wrote: > I use the Promise and postMessage together. Here is the example: > > http://www.ctomczyk.pl/lab/postmessage/ > > Instead of getting two different responses in two different Promises, > I've got same response in two Promises from postMessage. See developer > console. > > Why am I getting same response in two Promises when I see two different > data send from iframe? Firefox reports ReferenceError: event is not defined postmessage:42:3 when loading the page. So which browser have you tried with?
[toc] | [prev] | [next] | [standalone]
| From | Cezary Tomczyk <cezary.tomczyk@gmail.com> |
|---|---|
| Date | 2015-10-17 20:17 +0200 |
| Message-ID | <987e5$5622909b$6def49cc$31599@nntpswitch.blueworldhosting.com> |
| In reply to | #28826 |
W dniu 10/17/2015 o 11:34 AM, Martin Honnen pisze: > Cezary Tomczyk wrote: >> I use the Promise and postMessage together. Here is the example: >> >> http://www.ctomczyk.pl/lab/postmessage/ >> >> Instead of getting two different responses in two different Promises, >> I've got same response in two Promises from postMessage. See developer >> console. >> >> Why am I getting same response in two Promises when I see two different >> data send from iframe? > > Firefox reports > > ReferenceError: event is not defined postmessage:42:3 Sorry. I left "event" there accidentaly. However, it is not affecting on anything ;-) > when loading the page. > > So which browser have you tried with? Interesting that Chrome "Version 46.0.2490.71 m" didn't show specified error, but Firefox did. -- Cezary Tomczyk http://www.ctomczyk.pl/
[toc] | [prev] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2015-10-17 12:18 +0200 |
| Message-ID | <mvt78p$klk$1@news.albasani.net> |
| In reply to | #28825 |
Cezary Tomczyk wrote: > I use the Promise and postMessage together. Here is the example: > > http://www.ctomczyk.pl/lab/postmessage/ > > Instead of getting two different responses in two different Promises, > I've got same response in two Promises from postMessage. See developer > console. > > Why am I getting same response in two Promises when I see two different > data send from iframe? I have tried now with Microsoft Edge, I think the problem is that a sequence of code is for example - [createIframe] init - [createIframe] onLoad - [processPromise] [object Object] - [processPromise] [object Object] At that state you have two event listeners set up for the 'message' event and then the first message from the iframe is received by both event listeners and as the event listeners call 'resolve' both the first Promise as well as the second are fulfilled by the same message. And as you remove the event listeners you do not even see the second message.
[toc] | [prev] | [next] | [standalone]
| From | Cezary Tomczyk <cezary.tomczyk@gmail.com> |
|---|---|
| Date | 2015-10-17 21:06 +0200 |
| Message-ID | <77e43$56229c13$6def49cc$32071@nntpswitch.blueworldhosting.com> |
| In reply to | #28828 |
W dniu 10/17/2015 o 12:18 PM, Martin Honnen pisze: > Cezary Tomczyk wrote: >> I use the Promise and postMessage together. Here is the example: >> >> http://www.ctomczyk.pl/lab/postmessage/ >> >> Instead of getting two different responses in two different Promises, >> I've got same response in two Promises from postMessage. See developer >> console. >> >> Why am I getting same response in two Promises when I see two different >> data send from iframe? > > I have tried now with Microsoft Edge, I think the problem is that a > sequence of code is for example > > - [createIframe] init > - [createIframe] onLoad > - [processPromise] [object Object] > - [processPromise] [object Object] > > At that state you have two event listeners set up for the 'message' > event and then the first message from the iframe is received by both > event listeners and as the event listeners call 'resolve' both the first > Promise as well as the second are fulfilled by the same message. And as > you remove the event listeners you do not even see the second message. Looks like I need only one event listener for all Promises and implement communication between parent and iframe using postMessage and channels. Does that sounds reasonable? -- Cezary Tomczyk http://www.ctomczyk.pl/
[toc] | [prev] | [next] | [standalone]
| From | Cezary Tomczyk <cezary.tomczyk@gmail.com> |
|---|---|
| Date | 2015-10-18 22:39 +0200 |
| Message-ID | <a056d$5624036e$6def49cc$18933@nntpswitch.blueworldhosting.com> |
| In reply to | #28828 |
On 10/17/2015 o 12:18 PM, Martin Honnen wrote: > Cezary Tomczyk wrote: >> I use the Promise and postMessage together. Here is the example: >> >> http://www.ctomczyk.pl/lab/postmessage/ >> >> Instead of getting two different responses in two different Promises, >> I've got same response in two Promises from postMessage. See developer >> console. >> >> Why am I getting same response in two Promises when I see two different >> data send from iframe? > > I have tried now with Microsoft Edge, I think the problem is that a > sequence of code is for example > > - [createIframe] init > - [createIframe] onLoad > - [processPromise] [object Object] > - [processPromise] [object Object] > > At that state you have two event listeners set up for the 'message' > event and then the first message from the iframe is received by both > event listeners and as the event listeners call 'resolve' both the first > Promise as well as the second are fulfilled by the same message. And as > you remove the event listeners you do not even see the second message. I have updated the code: http://www.ctomczyk.pl/lab/postmessage/2/ Looks like now it works as I expect. I am not sure whether my approach is right, but would be nice to get some other opinions. -- Cezary Tomczyk http://www.ctomczyk.pl/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web