Skip to content

Commit

Permalink
Merge pull request #181 from gitmrwick/179-productsvariable
Browse files Browse the repository at this point in the history
removing global variable products
  • Loading branch information
chrisdavidmills committed Feb 4, 2020
2 parents 83ffb71 + 5f3f516 commit 4522ea5
Showing 1 changed file with 4 additions and 6 deletions.
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

0 comments on commit 4522ea5

Please sign in to comment.