Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sslash
Copy link

@sslash sslash commented Sep 25, 2014

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
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
Copy link
Author

sslash commented Sep 29, 2014

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
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