For my sideproject ( https://profilehunt.net ) I have been using a somewhat similar approach. I use Github ViewComponents ( https://github.com/github/view_component ) for componentization of Rails views. It helps with more modular views which are easier to debug (errors usually point directly to the line in view code, unlike Rails views). I use StimulusJS ( https://stimulus.hotwire.dev/ ) for Javascript interactivity…
I am still wondering if ViewComponent will ever officially make it into Rails.
How we use web components
41–50 of 84 posts
Re: How we use web components
#42Earlier quoted context omitted.
You can totally write web components with Preact: https://preactjs.com/guide/v10/web-components/ From a quick skim of their docs, it looks like AMP still uses web components. The nice part about web components is that the users of a library don't have to care about how it's implemented, so switching to preact is a transparent change.
React still doesn't play seamlessly with WC right?
Re: How we use web components
#43Something I've never understood how to handle with vanilla web components: if there's some state that needs to be shared and kept in sync between multiple components, how do you do it? (For comparison, in React you can pass the state down as props from a common ancestor, and in Clojure frameworks all app state is in a giant object referenced by components as needed.)
I recently took the time to explore a new idea I haven’t seen explored before —- services as DOM elements:
https://www.vadosware.io/post/sade-pattern-services-as-dom-e...
Straight to the repo:
https://gitlab.com/mrman/services-as-dom-elements
The idea is simple, use references to get at other DOM elements that happen to act like whatever kind of store you need
Re: How we use web components
#44The big thing holding back webcompinents at this point is a data sharing strategy, and I think we could get away with actually using components to store and manage data:
https://www.vadosware.io/post/sade-pattern-services-as-dom-e...
The github repo (which also happens to contain how to write a web component in lit-element, slim.js, tonic, vue, svelte):
Re: How we use web components
#45I have a very dumb question. I'm currently trying to implement web components into a pretty basic flask site, and I'm really having trouble. Does anyone know any resources about basic implementation that I can review? I was interested in Lit, and am try to bundle that, but it's not working at all, and I really feel like I'm missing something.
Especially their code examples
Re: How we use web components
#46Earlier quoted context omitted.
How do u append stuff to the DOM, new Hotwire or Rails ujs?
Clicking on buttons triggers Ajax request via stimulus controller (this takes care of CSRF and session) and fetches just the required HTML from route and appends using innerHTML ( https://developer.mozilla.org/en-US/docs/Web/API/Element/inn... ). an example following is an event listener in a JS controller. openAddJob(event) { this.openDialogAddClasses(); this.modalPanelTarget.innerHTML = MODAL_SPINNER_HTML; $.ajax({…
Re: How we use web components
#47Would love to see why they did not choose lit-element, it was one of the best I tried in a recent experiment of ~5 libs. The big thing holding back webcompinents at this point is a data sharing strategy, and I think we could get away with actually using components to store and manage data: https://www.vadosware.io/post/sade-pattern-services-as-dom-e... The github repo (which also happens to contain how to write a web…
Most likely explanation: It simply didn't exist yet when they chose.
Also, lit-element requires elements use its own base class while Catalyst doesn't.
Re: How we use web components
#48Would love to see why they did not choose lit-element, it was one of the best I tried in a recent experiment of ~5 libs. The big thing holding back webcompinents at this point is a data sharing strategy, and I think we could get away with actually using components to store and manage data: https://www.vadosware.io/post/sade-pattern-services-as-dom-e... The github repo (which also happens to contain how to write a web…
Re: How we use web components
#49Re: How we use web components
#50Absolutely great for the developer that wants to ship pre-built components that cannot be affected by the CSS of the site they're used in; absolutely useless when you want to make re-usable components for your own app, where you very much want slot content to be styled using the CSS you already have.