Readit News logoReadit News
tomger commented on My daughter (7 years old) used HTML to make a website   naya.lol... · Posted by u/fintler
tomger · a year ago
Good webpage
tomger commented on Drawing.garden   drawing.garden/... · Posted by u/nivethan
tomger · 2 years ago
Can you make it store my garden?
tomger commented on Atari Video Music   en.wikipedia.org/wiki/Ata... · Posted by u/rbanffy
SeenNotHeard · 2 years ago
"According to Atari design engineer, Al Alcorn, when Atari was on tour promoting the device, a Sears representative asked what the developers were smoking when they invented it. With that, a technician stepped forward holding up a lit joint."
tomger · 2 years ago
The demo video’s length is 4:20
tomger commented on RabbitOS   rabbit.tech/... · Posted by u/omarfarooq
saagarjha · 2 years ago
Wagering $20 right now that this has nothing to do with an actual OS.
tomger · 2 years ago
I think they misspelled API
tomger commented on The pneumatic tube mail system in New York City   untappedcities.com/2023/1... · Posted by u/geox
tomger · 2 years ago
Roosevelt Island NY has a pneumatic trash system https://untappedcities.com/2020/04/09/inside-roosevelt-islan...
tomger commented on Privacy Nightmare on Wheels’: Every Car Brand Reviewed by Mozilla   foundation.mozilla.org/en... · Posted by u/sandermvanvliet
tomger · 2 years ago
I’m privacy conscious, and on the side of Mozilla here. But I wish the article showed examples of how the data is actually being shared rather than an analysis of the terms. What’s an example of my health data being used somewhere else. I know it’s hard to get proof of this but that is what would make the public more aware.
tomger commented on If Web Components are so great, why am I not using them?   daverupert.com/2023/07/wh... · Posted by u/emegeve83
andrewmcwatters · 2 years ago
Because React is good enough. I think that's mostly why.

Here's legacy React's like_button.js, without JSX, from their old documentation:

    'use strict';

    const e = React.createElement;

    class LikeButton extends React.Component {
      constructor(props) {
        super(props);
        this.state = { liked: false };
      }

      render() {
        if (this.state.liked) {
          return 'You liked this.';
        }

        return e(
          'button',
          { onClick: () => this.setState({ liked: true }) },
          'Like'
        );
      }
    }

    const domContainer = document.querySelector('#like_button_container');
    const root = ReactDOM.createRoot(domContainer);
    root.render(e(LikeButton));
Here's the equivalent using the Web Components specification[1]:

    // https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements
    // Create a class for the element
    class LikeButton extends HTMLElement {
      static get observedAttributes() { return ['liked']; }

      constructor() {
        // Always call super first in constructor
        super();

        this.liked = false;

        // Create a shadow root
        /* const shadow = */ this.attachShadow({mode: 'open'});
      }

      get liked() { return this.hasAttribute('liked'); }
      set liked(state) { this.toggleAttribute('liked', Boolean(state)); }

      attributeChangedCallback(name, oldValue, newValue) {
        this.render();
      }

      connectedCallback() {
        this.render();
      }

      render() {
        const shadow = this.shadowRoot;

        if (this.liked) {
          shadow.innerHTML = 'You liked this.'
          return;
        }

        shadow.innerHTML = `<button onclick="this.parentNode.host.liked = true;">
      Like
    </button>`;
      }
    }

    // Define the new element
    customElements.define('like-button', LikeButton);
The React API is slightly nicer to use, especially with JSX.

[1]: https://github.com/andrewmcwatters/custom-elements

tomger · 2 years ago
Lit framework provides a bunch of sugar that brings the dev experience closer to JSX

https://lit.dev/

u/tomger

KarmaCake day354September 23, 2010View Original