Creating Initial Services
Create a services folder with the following files:
services/API.js
const API = {
// url: "https://firtman.github.io/coffeemasters/api/menu.json",
url: "/data/menu.json",
fetchMenu: async () => {
const result = await fetch(API.url);
return await result.json();
}
}
export default API;
services/Store.js
import API from './API.js'
const Store = {
menu: null,
cart: []
}
export default Store;
Back in app.js
import the two services as modules and create a global app variable.
import Store from './services/Store.js';
import API from './services/API.js';
window.app = {}
app.store = Store;