Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow creating new instances #306

Merged
merged 5 commits into from Dec 17, 2019

Conversation

@mercs600
Copy link
Contributor

mercs600 commented Nov 4, 2019

This PR resolves #286.

I added new method for create copy of $axios instance based on default settings.
After that the copy is independent and may get new options so we can extend it.
Right now we can't use nuxt/axios in our module, because we won't override axios instance created by user.

How it works ?
$axios.create method returns new Axios instance, you can pass additional options to merge.

const newInstance = this.$axios.create({
  headers: {
    common: {
      Accept: 'text/plain, */*'
    }
  }
})

After that you can use methods from this module, without override base $axios instance.

newInstance.setBaseURL('https://yourapi.com')

I also extended test/fixture/pages/ssr.vue to present how the new instance behaves.

@pi0 Have a look at it please.

@mercs600 mercs600 mentioned this pull request Nov 4, 2019
@codecov

This comment has been minimized.

Copy link

codecov bot commented Nov 4, 2019

Codecov Report

Merging #306 into dev will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@         Coverage Diff         @@
##            dev   #306   +/-   ##
===================================
  Coverage   100%   100%           
===================================
  Files         1      1           
  Lines        30     30           
  Branches     13     13           
===================================
  Hits         30     30

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 520d6d7...9c5f562. Read the comment docs.

lib/plugin.js Outdated Show resolved Hide resolved
@ricardogobbosouza ricardogobbosouza requested a review from pi0 Nov 5, 2019
Copy link
Member

pi0 left a comment

Thanks for initial PR 👍

@mercs600 mercs600 requested review from pi0 and ricardogobbosouza Nov 6, 2019
@@ -91,7 +113,7 @@ const setupCredentialsInterceptor = axios => {
}<% } %>

<% if (options.progress) { %>
const setupProgress = (axios, ctx) => {

This comment has been minimized.

Copy link
@mercs600

mercs600 Nov 6, 2019

Author Contributor

I removed ctx here, because it is not used

@mercs600

This comment has been minimized.

Copy link
Contributor Author

mercs600 commented Nov 13, 2019

@pi0 Is it suitable to merge ? This is not breaking change, but it would be helpful to implement nuxt-axios in other modules. Let me know please :)

@nachogarcia

This comment has been minimized.

Copy link

nachogarcia commented Dec 17, 2019

Any news from this @pi0 ?
There's a MR in axios also axios/axios#2040

@pi0
pi0 approved these changes Dec 17, 2019
Copy link
Member

pi0 left a comment

Awesome! Thanks!

}
})
newInstance.setBaseURL('https://yourapi.com')

This comment has been minimized.

Copy link
@pi0

pi0 Dec 17, 2019

Member

Maybe we could document how to inject instance to CTX too?

This comment has been minimized.

Copy link
@mercs600

mercs600 Dec 17, 2019

Author Contributor

Sure, I can add it

@pi0 pi0 changed the title feat: add method to create new copy based on default instance feat: allow creating new instances Dec 17, 2019
@pi0 pi0 merged commit 2ca95e5 into nuxt-community:dev Dec 17, 2019
3 checks passed
3 checks passed
ci/circleci Your tests passed on CircleCI!
Details
codecov/patch Coverage not affected when comparing 520d6d7...9c5f562
Details
codecov/project 100% remains the same compared to 520d6d7
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.