Skip to content

Instantly share code, notes, and snippets.

@psychicbologna
Created August 20, 2019 18:01
Show Gist options
  • Save psychicbologna/48ff19c6a91f96d5ea089f0ede83804d to your computer and use it in GitHub Desktop.
Save psychicbologna/48ff19c6a91f96d5ea089f0ede83804d to your computer and use it in GitHub Desktop.
Alex Fukui
Pseudocode for three functions in Shopping Items List
function render(){
//Re-renders list after changed are put through.
}
function handleNewItemSubmit() {
// this function will be responsible for when users add a new shopping list item
$('.js-shopping-list-form').submit(function (event) {
//Prevents form submit from default post.
event.preventDefault();
//Creates constant from input.
const newItemName = 'Test Item';
//Clears value in input.
$('.js-shopping-list-entry').val('');
//A function that adds the item to the shopping list in STORE.
addItemToShoppingList(newItemName);
//Re-render the list with the new item.
render();
});
console.log('`handleNewItemSubmit` ran');
}
function handleItemCheckClicked() {
// this function will be responsible for when users click the "check" button on
// a shopping list item.
console.log('`handleItemCheckClicked` ran');
//Activate when clicking the check toggle.
$('.js-shopping-list').on('click', '.js-item-toggle', event => {
//Retrieve id from element.
const id = 1;
//Toggle the 'checked' class onto the list item by id.
toggleCheckedForListItem(id);
//Reload the list with the newly checked/unchecked items.
render();
})
}
/**
* param {string} - Item pulled from input.
* return {array} - Returns new array with item added on.
*/
function addItemToShoppingList(item){
//Adds item to list in STORE from argument.
}
/**
* param {string} id - Item whose 'check' button is clicked on.
* return {string} foundItem.checked - Flips the boolean to indicate change.
*/
toggleCheckedForListItem(id){
//Toggles the checked class for a list item by id.
}
function handleDeleteItemClicked() {
// this function will be responsible for when users want to delete a shopping list
// item
//Delegate to check click.
$('.js-shopping-list').on('click', '.js-item-delete', event => {
//Retrieve index
const id = 4;
//delete the item
deleteListItem(id);
//render the updated shopping list
render();
});
console.log('`handleDeleteItemClicked` ran')
}
/**
* param {number} - id of the item to remove from list.
* return {} - new shopping list array with item removed.
*/
function deleteListItem(id){
//Finds the item in the STORE by id and removes it.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment