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!

On Friday, February 23, 2018 at 7:00:22 PM UTC-8, Eric Rajkovic wrote:
>
> 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()
>
>
> On Friday, February 23, 2018 at 4:45:43 PM UTC-8, Eric Rajkovic wrote:
>>
>> 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
>>       }
>>     }
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to