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

removing global variable products #181

Merged
merged 1 commit into from
Feb 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions javascript/apis/fetching-data/can-store/can-script.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
// create a variable to store the products 'database' in
let products;

// use fetch to retrieve it, and report any errors that occur in the fetch operation
// use fetch to retrieve the products and pass them to init
// report any errors that occur in the fetch operation
// once the products have been successfully loaded and formatted as a JSON object
// using response.json(), run the initialize() function
fetch('products.json').then(function(response) {
return response.json();
}).then(function(json) {
products = json;
initialize();
initialize(products);
}).catch(function(err) {
console.log('Fetch problem: ' + err.message);
});

// sets up the app logic, declares required variables, contains all the other functions
function initialize() {
function initialize(products) {
// grab the UI elements that we need to manipulate
const category = document.querySelector('#category');
const searchTerm = document.querySelector('#searchTerm');
Expand Down