@@ -389,7 +389,7 @@ InputRadiogroup.define('input-radiogroup')
389389class LazyLoad extends UIElement {
390390 static observedAttributes = [ 'src' ]
391391 static attributeMap = {
392- src : v => v . map ( src => {
392+ src : v => v . map ( src => {
393393 let url = ''
394394 try {
395395 url = new URL ( src , location . href ) // ensure 'src' attribute is a valid URL
@@ -402,20 +402,20 @@ class LazyLoad extends UIElement {
402402 }
403403 return url . toString ( )
404404 } )
405- }
405+ }
406406
407407 connectedCallback ( ) {
408408
409- // show / hide loading message
409+ // Show / hide loading message
410410 this . first ( '.loading' )
411411 . forEach ( setProperty ( 'ariaHidden' , ( ) => ! ! this . get ( 'error' ) ) )
412412
413- // set and show / hide error message
413+ // Set and show / hide error message
414414 this . first ( '.error' )
415415 . map ( setText ( 'error' ) )
416416 . forEach ( setProperty ( 'ariaHidden' , ( ) => ! this . get ( 'error' ) ) )
417417
418- // load content from provided URL
418+ // Load content from provided URL
419419 effect ( enqueue => {
420420 const src = this . get ( 'src' )
421421 if ( ! src ) return // silently fail if no valid URL is provided
@@ -434,7 +434,7 @@ class LazyLoad extends UIElement {
434434 } )
435435 } )
436436 this . set ( 'error' , '' )
437- } else {
437+ } else {
438438 this . set ( 'error' , response . status + ':' + response . statusText )
439439 }
440440 } )
@@ -525,118 +525,112 @@ class MediaContext extends UIElement {
525525MediaContext . define ( 'media-context' )
526526
527527class TodoApp extends UIElement {
528- connectedCallback ( ) {
528+ connectedCallback ( ) {
529529 const [ todoList , todoFilter ] = [ 'todo-list' , 'input-radiogroup' ]
530530 . map ( selector => this . querySelector ( selector ) )
531531
532532 // Event listener on own element
533- this . self
534- . map ( on ( 'add-todo' , e => todoList ?. addItem ( e . detail ) ) )
535-
536- // Coordinate todo-count
537- this . first ( 'todo-count' )
538- . map ( pass ( { active : ( ) => todoList ?. get ( 'count' ) . active } ) )
539-
540- // Coordinate todo-list
541- this . first ( 'todo-list' )
542- . map ( pass ( { filter : ( ) => todoFilter ?. get ( 'value' ) } ) )
543-
544- // Coordinate .clear-completed button
545- this . first ( '.clear-completed' )
546- . map ( on ( 'click' , ( ) => todoList ?. clearCompleted ( ) ) )
547- . map ( pass ( { disabled : ( ) => ! todoList ?. get ( 'count' ) . completed } ) )
548- }
533+ this . self . forEach ( on ( 'add-todo' , e => todoList ?. addItem ( e . detail ) ) )
534+
535+ // Coordinate todo-count
536+ this . first ( 'todo-count' ) . forEach ( pass ( {
537+ active : ( ) => todoList ?. get ( 'count' ) . active
538+ } ) )
539+
540+ // Coordinate todo-list
541+ this . first ( 'todo-list' ) . forEach ( pass ( {
542+ filter : ( ) => todoFilter ?. get ( 'value' )
543+ } ) )
544+
545+ // Coordinate .clear-completed button
546+ this . first ( '.clear-completed' )
547+ . map ( on ( 'click' , ( ) => todoList ?. clearCompleted ( ) ) )
548+ . forEach ( pass ( { disabled : ( ) => ! todoList ?. get ( 'count' ) . completed } ) )
549+ }
549550}
550551TodoApp . define ( 'todo-app' )
551552
552553class TodoCount extends UIElement {
553554 connectedCallback ( ) {
554- this . set ( 'active' , 0 , false )
555- this . first ( '.count' )
556- . map ( setText ( 'active' ) )
557- this . first ( '.singular' )
558- . map ( setProperty ( 'ariaHidden' , ( ) => this . get ( 'active' ) > 1 ) )
559- this . first ( '.plural' )
560- . map ( setProperty ( 'ariaHidden' , ( ) => this . get ( 'active' ) === 1 ) )
561- this . first ( '.remaining' )
562- . map ( setProperty ( 'ariaHidden' , ( ) => ! this . get ( 'active' ) ) )
563- this . first ( '.all-done' )
564- . map ( setProperty ( 'ariaHidden' , ( ) => ! ! this . get ( 'active' ) ) )
565- }
555+ this . set ( 'active' , 0 , false )
556+ this . first ( '.count' ) . forEach ( setText ( 'active' ) )
557+ this . first ( '.singular' ) . forEach ( setProperty ( 'ariaHidden' , ( ) => this . get ( 'active' ) > 1 ) )
558+ this . first ( '.plural' ) . forEach ( setProperty ( 'ariaHidden' , ( ) => this . get ( 'active' ) === 1 ) )
559+ this . first ( '.remaining' ) . forEach ( setProperty ( 'ariaHidden' , ( ) => ! this . get ( 'active' ) ) )
560+ this . first ( '.all-done' ) . forEach ( setProperty ( 'ariaHidden' , ( ) => ! ! this . get ( 'active' ) ) )
561+ }
566562}
567563TodoCount . define ( 'todo-count' )
568564
569565class TodoForm extends UIElement {
570566 connectedCallback ( ) {
571567 const inputField = this . querySelector ( 'input-field' )
572568
573- this . first ( 'form' )
574- . forEach ( on ( 'submit' , e => {
575- e . preventDefault ( )
576- setTimeout ( ( ) => {
577- this . dispatchEvent ( new CustomEvent ( 'add-todo' , {
578- bubbles : true ,
579- detail : inputField . get ( 'value' )
580- } ) )
581- inputField . clear ( )
582- } , 0 )
583- } ) )
584-
585- this . first ( 'input-button' )
586- . forEach ( pass ( {
587- disabled : ( ) => inputField . get ( 'empty' )
588- } ) )
569+ this . first ( 'form' ) . forEach ( on ( 'submit' , e => {
570+ e . preventDefault ( )
571+ setTimeout ( ( ) => {
572+ this . dispatchEvent ( new CustomEvent ( 'add-todo' , {
573+ bubbles : true ,
574+ detail : inputField . get ( 'value' )
575+ } ) )
576+ inputField . clear ( )
577+ } , 0 )
578+ } ) )
579+
580+ this . first ( 'input-button' ) . forEach ( pass ( {
581+ disabled : ( ) => inputField . get ( 'empty' )
582+ } ) )
589583 }
590584}
591585TodoForm . define ( 'todo-form' )
592586
593587class TodoList extends UIElement {
594- connectedCallback ( ) {
595- this . set ( 'filter' , 'all' ) // set initial filter
588+ connectedCallback ( ) {
589+ this . set ( 'filter' , 'all' ) // set initial filter
596590 this . #updateList( )
597591
598592 // Event listener and attribute on own element
599- this . self
600- . map ( on ( 'click' , e => {
601- if ( e . target . localName === 'button' ) this . removeItem ( e . target )
602- } ) )
603- . map ( setAttribute ( 'filter' ) )
604-
605- // Update count on each change
606- this . set ( 'count' , ( ) => {
607- const tasks = this . get ( 'tasks' ) . map ( el => el . signal ( 'checked' ) )
608- const completed = tasks . filter ( fn => fn ( ) ) . length
609- const total = tasks . length
610- return {
593+ this . self
594+ . map ( on ( 'click' , e => {
595+ if ( e . target . localName === 'button' ) this . removeItem ( e . target )
596+ } ) )
597+ . forEach ( setAttribute ( 'filter' ) )
598+
599+ // Update count on each change
600+ this . set ( 'count' , ( ) => {
601+ const tasks = this . get ( 'tasks' ) . map ( el => el . signal ( 'checked' ) )
602+ const completed = tasks . filter ( fn => fn ( ) ) . length
603+ const total = tasks . length
604+ return {
611605 active : total - completed ,
612606 completed,
613607 total
614608 }
615- } )
616- }
609+ } )
610+ }
617611
618- addItem = task => {
619- const template = this . querySelector ( 'template' ) . content . cloneNode ( true )
620- template . querySelector ( 'span' ) . textContent = task
621- this . querySelector ( 'ol' ) . appendChild ( template )
622- this . #updateList( )
623- }
612+ addItem = task => {
613+ const template = this . querySelector ( 'template' ) . content . cloneNode ( true )
614+ template . querySelector ( 'span' ) . textContent = task
615+ this . querySelector ( 'ol' ) . appendChild ( template )
616+ this . #updateList( )
617+ }
624618
625- removeItem = element => {
626- element . closest ( 'li' ) . remove ( )
627- this . #updateList( )
628- }
619+ removeItem = element => {
620+ element . closest ( 'li' ) . remove ( )
621+ this . #updateList( )
622+ }
629623
630- clearCompleted = ( ) => {
631- this . get ( 'tasks' )
632- . filter ( el => el . get ( 'checked' ) )
633- . forEach ( el => el . parentElement . remove ( ) )
634- this . #updateList( )
635- }
624+ clearCompleted = ( ) => {
625+ this . get ( 'tasks' )
626+ . filter ( el => el . get ( 'checked' ) )
627+ . forEach ( el => el . parentElement . remove ( ) )
628+ this . #updateList( )
629+ }
636630
637631 #updateList( ) {
638- this . set ( 'tasks' , Array . from ( this . querySelectorAll ( 'input-checkbox' ) ) )
639- }
632+ this . set ( 'tasks' , Array . from ( this . querySelectorAll ( 'input-checkbox' ) ) )
633+ }
640634
641635}
642636TodoList . define ( 'todo-list' )
0 commit comments