dojo / core

:rocket: Dojo 2 - language helpers and utilities.
http://dojo.io
Other
213 stars 58 forks source link

Provide total and lengthComputable data for xhr requests #405

Closed smhigley closed 6 years ago

smhigley commented 6 years ago

Type: feature

The following has been addressed in the PR:

Description:

When specifically using the xhr provider, the upload events allow access to data available from the native xhr progress event:

const xhr = xhr.post('http://www.example.com/', {
    body: someLargeString
});

xhr.upload.subscribe(uploadData => {
  const { loaded, total, lengthComputable } = uploadData;
    if (lengthComputable) {
        const percentComplete = loaded / total * 100;
    }
});

The node provider has also been updated for consistency:

const req = request.post('http://www.example.com/', {
    body: someLargeString
});

req.upload.subscribe(uploadData => {
    const { loaded } = uploadData;
    // do something with uploaded bytes
})
smhigley commented 6 years ago

Closed via https://github.com/dojo/framework/issues/11