how to extract modules to separate files
See original GitHub issueHi there, I’m using the latest version and it’s great and it’s working fine if I set everything up from inside the store.js file
but I would like to abstract my resources to separate files, or at the very least to one file called Apis.js which is inside ./modules/Apis.js
Clearly I’m just brain-farting here but I don’t know how to make this work. This is what I’ve got so far
store.js:
import { topics, nav } from './modules/Apis';
const store = new Vuex.Store({
modules: {
topics,
nav,
},
});
Apis.js:
import Vapi from 'vuex-rest-api';
const topics = new Vapi({
baseURL: '/api',
state: {
topics: [],
},
})
.get({
action: 'getTopic',
property: 'topic',
path: ({ id }) => `/topics/${id}`,
})
.get({
action: 'getTopics',
property: 'topics',
path: ({ limit }) => `/topics?limit=${limit}`,
})
.post({
action: 'updateTopic',
property: 'topic',
path: ({ id }) => `/topics/${id}`,
})
.getStore();
const nav = new Vapi({
baseURL: '/api',
state: {
nav: [],
},
})
.get({
action: 'getNav',
property: 'nav',
path: ({ season }) => `/nav?season=${season}`,
})
.getStore();
export default {
topics,
nav,
};
And then in my components I want to call (for example the nav) like this:
export default {
computed: {
...mapState({
nav: state => state.nav.nav,
pending: state => state.nav.pending,
error: state => state.nav.error,
}),
},
methods: {
...mapActions(['getNav']),
},
created() {
this.getNav({ params: { season: this.currentSeason } });
},
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Separating Modules into Different Files - The Rust ...
First, we'll extract the front_of_house module to its own file. Remove the code inside the curly brackets for the front_of_house module, leaving only...
Read more >Split a module across several files - rust - Stack Overflow
I think the key here is to make use of pub use , which will allow you to re-export identifiers from other modules....
Read more >Separating Modules into Different Files - The Rust ...
You can do this by specifying absolute or relative paths. These paths can be brought into scope with a use statement so you...
Read more >Dividing a Large file into Separate Modules in C/C++, Java ...
It is similar to Python. Navigate to the new directory to save the project files and in all of the sub program write:...
Read more >Day 21: Splitting Code Into Multiple Files - Teclado
Why split your code into files? · Separating concerns and ease of organization · Improved readability · Easier to reuse code.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry, I don’t understand your question. Could you please be more specific?
Every Vapi instance is made to create one store (or module if you need to create many respectively). So If you need multiple modules you could just separate every one in a single file.
Example:
@vesper8 If you want to use destructuring on default exports you could do it this way: https://github.com/babel/babel/issues/3049#issuecomment-286205548