Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28825 > unrolled thread

Promise and postMessage

Started byCezary Tomczyk <cezary.tomczyk@gmail.com>
First post2015-10-16 23:50 +0200
Last post2015-10-18 22:39 +0200
Articles 6 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#28825 — Promise and postMessage

FromCezary Tomczyk <cezary.tomczyk@gmail.com>
Date2015-10-16 23:50 +0200
SubjectPromise 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]


#28826

FromMartin Honnen <mahotrash@yahoo.de>
Date2015-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]


#28836

FromCezary Tomczyk <cezary.tomczyk@gmail.com>
Date2015-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]


#28828

FromMartin Honnen <mahotrash@yahoo.de>
Date2015-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]


#28837

FromCezary Tomczyk <cezary.tomczyk@gmail.com>
Date2015-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]


#28838

FromCezary Tomczyk <cezary.tomczyk@gmail.com>
Date2015-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