Skip to content

Support for async request-respond through post-message#2

Open
sslash wants to merge 2 commits into
masterfrom
support_postMessaging
Open

Support for async request-respond through post-message#2
sslash wants to merge 2 commits into
masterfrom
support_postMessaging

Conversation

@sslash

@sslash sslash commented Sep 25, 2014

Copy link
Copy Markdown

There are cases when banners need to communicate with the parent, and be notified when there is a response.

Example use:

// host-plugin
pluginApi.reqres.respondTo('some:ext-event', function(evt, done) {
    // do stuff with evt.data.foo
    done(someValueToBePassedDown);
});

// ext-plugin
pluginApi.reqres.request(window, 'some:ext-event', {foo:bar}, function(evt) {
    // do something with the value that was passed down through evt.data
});

@sveisvei

Copy link
Copy Markdown
Contributor

reqres seams non-intuitive namespace, maybe choose a better name (transport/messageBus etc?) - or remove the namespace.

Can the ext plugin pass anything else than window to the request function? I see no reason for this first arg.

@sslash

sslash commented Sep 29, 2014

Copy link
Copy Markdown
Author

Naming it a message bus is a bit overkill imo, in adherence to the messaging design pattern. The pluginAPI itself is a simple pub/sub system. This service however is more specialized and conforms to the request/response pattern (with an asynchronous response handler). I think that should be expressed in the API name. But yes, reqres might not be very intuitive. Maybe I shouldn't have abstracted out these two functions, but instead have them directly on the pluginApi. What do you think?

request needs a window reference, because it depends on xde, which uses for post messaging.

@sveisvei

Copy link
Copy Markdown
Contributor
// host-plugin
pluginApi.respondToPostmessage('endPoint', function(payload, done) {
    //data
    done(Math.random());
});

// ext-plugin
pluginApi.postMessage('endPoint', {'foo': bar}, function(err, result) {
    // error is e.g. reference error
    // do something with the value that was passed down through evt.data
}, window);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants