SHARE
TWEET

Untitled

a guest Sep 19th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { htmlToElement } from './utils';
  2.  
  3. export default class App {
  4.   //...
  5.  
  6.   addNewItem(itemName) {
  7.     //...
  8.  
  9.     const item = htmlToElement(`
  10.     <li class="flex py-4 border-b border-gray-900 item"> <!-- add class 'item' -->
  11.       //...
  12.     </li>
  13.     `);
  14.  
  15.     item.getElementsByClassName('delete-button')[0].addEventListener('click', () => this.deleteItem(item));
  16.  
  17.     this.listRoot.appendChild(item);
  18.     this.evaluateEmptyState()
  19.     this.input.value = '';
  20.   }
  21.  
  22.   deleteItem(item) {
  23.     item.remove();
  24.     this.evaluateEmptyState();
  25.   }
  26.  
  27.   evaluateEmptyState() {
  28.     if (this.listRoot.getElementsByClassName('item').length === 0) {
  29.       this.listRoot.appendChild(this.emptyState);
  30.       return;
  31.     }
  32.  
  33.     const emptyState = document.getElementById('empty-state');
  34.  
  35.     if (emptyState) {
  36.       emptyState.remove();
  37.     }
  38.   }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top