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

app2app v2 compatibility #49

Open
wants to merge 1 commit into
base: v1.x/staging
Choose a base branch
from

Conversation

1000TurquoisePogs
Copy link
Member

Lacking string translations, but otherwise allows this app to submit and receive app2app V2 requests (and still support v1 requests)
This could serve as an example for developers that want to do the same.
Signed-off-by: 1000TurquoisePogs sgrady@rocketsoftware.com

Signed-off-by: 1000TurquoisePogs <sgrady@rocketsoftware.com>
@1000TurquoisePogs
Copy link
Member Author

This example uses app2app to SEND requests, but the receiving isnt in the PR.
To receive, you need to set an event listener and then assign a function to handle the data:

    ZoweZLUX.dispatcher.registerEventListener('org.zowe.zlux.sample.angular', (event:any)=> {
      let data = Object.assign(event.detail.data, {type:'set', _customEvent:true});
      event.detail.return = this.zluxOnMessage({data:data},false);
    },this.instanceId);

The shape of v2 data is slightly different from v1 data, which is why an Object.assign can make a little modification so that 1 handler function can support both v1 and v2

For example on the handling side:

  public zluxOnMessage(eventContext: any, fromLaunch: boolean): Promise<any> {
    this.log.info("handling app2app data=",eventContext);
    return new Promise((resolve,reject)=> {
      if (!eventContext || !eventContext.data) {
        return reject('Event context missing or malformed');
      }
      switch (eventContext.data.type) {
      case 'set':
        let setActions = eventContext.data.actions;

here, "set" could have been from app2app v1 with content {data: { type: set, a: b}} but in app2app v2, the type is the event name itself, so the Object.assign is just used to insert the type back into the object.

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.

1 participant