Fork me on GitHub
#polylith
<
2024-05-13
>
growthesque10:05:14

I am curious about the relationship between front-end component design and polylith. I know the polylith team is working on bringing polylith tool to the front-end, but would like to hear more experienced developers if they granularize their front-end react or other components according to pl guidelines and if they have found this useful or not.

Mark Sto09:06:50

Nope. So far the only option out there was to have all your FE code in a separate base or in an independent sub-dir in the workspace (that is used as a :local/root dependency of some project). But these thinks are just about to change.

growthesque10:05:54

Something like this for example:

// Component for user image
class UserImage extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.innerHTML = `
      <style>
        img { width: 100px; height: auto; }
      </style>
      <img src="${this.getAttribute('src')}" alt="User Image">
    `;
  }
}

// Component for user name
class UserName extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.textContent = this.getAttribute('name');
  }
}

// Component for user bio
class UserBio extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.textContent = this.getAttribute('bio');
  }
}

// Registering components
window.customElements.define('user-image', UserImage);
window.customElements.define('user-name', UserName);
window.customElements.define('user-bio', UserBio);

growthesque10:05:44

Obviously these are useless components just to serve as an example.