question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding an "after" callback

See original GitHub issue

Interceptors are a nice way to add some behaviours before and after a Request. But there is no way to do the same thing for a single resource. There is a callback before wich is nice to display a loader but there is no after callback 😦

The idea would be to clone https://github.com/vuejs/vue-resource/blob/master/src/http/interceptor/before.js giving the response as a callback.

I can do the PR myself but I want to know if it would be accepted. Maybe you think people should use their own after interceptor.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
leixu2txtekcommented, Jul 4, 2017

@Grafikart Where this code is placed ? thx.

0reactions
bentarikcommented, Jul 12, 2018

@leixu2txtek you can add it in the main.js like this

Vue.http.interceptors.push((request, next) => { next((response) => { if (request.after) { request.after.call(this, response) } }) })

or create a function like this in the vue-resource.esm.js

function after (request, next) { next((response) => { if (isFunction(request.after)) { request.after.call(this, request);}})}

you need to add these as well

Http.interceptor = {before: before, after: after, method: method, jsonp: jsonp, json: json, form: form, header: header, cors: cors}; Http.interceptors = ['before','after' ,'method', 'jsonp', 'json', 'form', 'header', 'cors'];

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery Insert After Callback? - javascript - Stack Overflow
datetime() is a plugin that I am attaching to an input element with with class date . Obviously #1 doesn't work because that...
Read more >
jQuery callbacks.add() Method - GeeksforGeeks
The jQuery callbacks.add() method is used to add a callback or a collection of callbacks to a callback list. This method returns the ......
Read more >
JavaScript Callback Functions – What are Callbacks in JS and ...
Callbacks make sure that a function is not going to run before a task is completed but will run right after the task...
Read more >
Adding custom callbacks to existing JavaScript functions
This morning I was reading Adding your own callbacks to existing JavaScript functions by Dave Ward—which covers how to overwrite an existing ...
Read more >
Advanced Callbacks | Dash for Python Documentation | Plotly
It is possible for a callback to insert new Dash components into a Dash app's layout. If these new components are themselves the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found