Skip to content

ClientSide Callbacks Promise Handling #1364

Closed
@jmSfernandes

Description

@jmSfernandes

It would be a nice funcionallity to be able to return promises in the clientside callbacks.
Right now it is impossible to make web requests in the clientside.
This would help to take some load from the server side, which would greatly improve the dash apps performance

Example of what I mean:

async function MakeWebRequest(type) {
    var _url = "https://test.api.com/entities/?type="+type
    var headers = {
        "Accept":"application/json"
    }
    var config = {
        url: _url,
        headers: headers,
        method: 'get'
    }
    return await axios(config)
        .then(data => {
            return data
        })
        .catch(error => {
            console.log(error);
            return error;
        });
}

async function updateDropdown(name, path, previous_value) {

    var disabled = false
      ...
    if (courseID !== '') {
        var options = await MakeWebRequest("course");
    
        return [disabled,courseID, options]
    }
}

window.dash_clientside = Object.assign({}, window.dash_clientside, {
    newQuestionnaire: {
    updateDropdown: async function (name, path, previous_value) {
                return await updateDropdown(name, path, previous_value);
            }
}

This raises this type of error in the Web Page:
image

I think this should be a feature to really consider in future releases.
I really like how dash lets you abstract from javascript, But it is still lacking the the ability to offload demanding jobs to the clientside...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions