Hacker News new | past | comments | ask | show | jobs | submit login

    const EditableList = ui.component({
      render: ({ props }) => {
        return `
          <ul>
            ${each(Object.keys(props).filter((p) => p.startsWith('list-item-')), (p) =>
               `<li>${props[p]}</li>`
             )}
          </ul>
        `;
      },
    });

    // Usage:
    ${component(EditableList, {
        ['list-item-0']: 'First item on the list',
        ['list-item-1']: 'Second item on the list',
        ['list-item-2']: 'Third item on the list',
        ['list-item-3']: 'Fourth item on the list',
        ['list-item-4']: 'Fifth item on the list',
    })}
edit: used each(), which doesn't change the point that you can make a bad component API in any framework.




Re: your edit, that's not a bad component API, that's bad JavaScript (intentionally written by the author, in this case).


This is exactly my point. The MDN element is bad (the component has a bad API), and made bad by the component author, not the web components APIs.


Which highlights that there is a lack of clear prescription around how to handle a list in a component at the (Web Components) API level. Contrast that with what I linked from my own framework where there's zero uncertainty as to how to handle a list.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: