How to handle the event triggered when the swagger docum is fully loaded - status set to 'success' ?

56 views
Skip to first unread message

Eric Rajkovic

unread,
Feb 23, 2018, 7:45:43 PM2/23/18
to Swagger
I am having trouble finding the right syntax / sample to only trigger the async callback I have registered once the swagger document has finish loading in the browser.

Right now, the code is being called twice, once when the swagger is starting loading and once when the it has completed.

here is my current test code, which does not work...

function HandleChangeSpecPlugin(system) {
return {
statePlugins: {
spec: {
wrapActions: {
updateUrl: function updateUrl(oriAction, system) {
return function (url) {
if (self.swaggerUi) {
console.log("status: "
+ self.swaggerUi.specActions.updateLoadingStatus());
}
// more custom code goes here ...
return oriAction(url);
};
}
}
}
}
};
}

I can put a breakpoint on download-url.js and watch the value changing on 'payload', but cannot 
figure out the correct way to access the value and only process the event when status is "success"...

    updateLoadingStatus: (status) => {
      let enums = [null, "loading", "failed", "success", "failedConfig"]
      if(enums.indexOf(status) === -1) {
        console.error(`Error: ${status} is not one of ${JSON.stringify(enums)}`)
      }

      return {
        type: "spec_update_loading_status",
>>        payload: status
      }
    }

Eric Rajkovic

unread,
Feb 23, 2018, 10:00:22 PM2/23/18
to Swagger
Found this code, but it's returning "success" twice - was expecting to get "loading" on the first call, so I am still missing something ...

self.swaggerUi.specSelectors.loadingStatus()

Kyle Shockey

unread,
Mar 4, 2018, 4:58:10 PM3/4/18
to Swagger
Hey Eric!

You can intercept the `updateLoadingStatus` action directly in order to check if the new status is going to be "success":

const MyDoneLoadingPlugin = function() {
 
return {
    statePlugins
: {
      spec
: {
        wrapActions
: {
          updateLoadingStatus
: (ori) => (...args) => {
           
const [loadingStatus] = args
           
if(loadingStatus === "success") {
              alert
("done loading!")
           
}
           
return ori(...args)
         
}
       
}
     
}
   
}
 
}
}

Hope this helps - let me know if this isn't what you're looking for!
Reply all
Reply to author
Forward
0 new messages