ZjsComponent: A Pragmatic Approach to Reusable UI Fragments for Web Development
51–60 of 65 posts
Re: ZjsComponent: A Pragmatic Approach to Reusable UI Fragments for Web Development
#52Shameless plug; I'm the author. Criticism welcome. I use this for client-side includes and web components. No build process, no web-packer, no framework, no npm requirement. Just include the JS in your HTML and then you can create and include components.
I always love seeing more done in the web component space. I think Lit has the no build process captured pretty well and they include things such as a router. I do prefer the style of of your components more, where you separate out the script and styles with html tags. I don't know if one way or the other is superior for performance, I but just like the separation verse the templated strings in Lit. With build tools…
Re: ZjsComponent: A Pragmatic Approach to Reusable UI Fragments for Web Development
#53Earlier quoted context omitted.
OP doesn’t feel that novel. I read the code and it all has been done before.
> OP doesn’t feel that novel. I read the code and it all has been done before. Thank you for reading the code. Where was this done before? A few projects were mentioned in this page (Yoffee, Lit, etc) but after closer examination none of them appear to be "define an object in simple terms, then use HTML to inline it", where object is "HTML fragment with methods in a script element that are scoped only to that specifi…
From very simple (https://github.com/include-html/include-html.github.io/blob/..., from 3 years ago), to more sophisticated, including script execution (https://github.com/SirPepe/html-import/blob/master/src/html-..., from 4 years ago; or even https://github.com/webcomponents/html-imports/blob/master/sr..., dating back 9 years). I haven't checked all of them but there's a decent chance there's something that covers each feature of OP, maybe even at once.
Re: ZjsComponent: A Pragmatic Approach to Reusable UI Fragments for Web Development
#54Earlier quoted context omitted.
> OP doesn’t feel that novel. I read the code and it all has been done before. Thank you for reading the code. Where was this done before? A few projects were mentioned in this page (Yoffee, Lit, etc) but after closer examination none of them appear to be "define an object in simple terms, then use HTML to inline it", where object is "HTML fragment with methods in a script element that are scoped only to that specifi…
There are quite a few HTML include components out there. A quick GH search return a lot of results. From very simple ( https://github.com/include-html/include-html.github.io/blob/... , from 3 years ago), to more sophisticated, including script execution ( https://github.com/SirPepe/html-import/blob/master/src/html-... , from 4 years ago; or even https://github.com/webcomponents/html-imports/blob/master/sr... , dating…
The ZjsComponent thing I use is unlike those things; while the goal of those (and other similar projects) is primarily to perform client-side includes, the goal of zjs-component is to provide client-side object instantiation using a remote object definition.
The paper itself may be a bit arcane and obscure, but as a quick example of what zjs-component was intended to do, see the GH page: https://github.com/lelanthran/ZjsComponent/tree/master?tab=r...
As you'll see from the above link, the goal was not to simply include remote fragments (with some execution behaviour), but to instantiate a local instance of an object defined in a remote file fragment and support instance-scoped code and HTML.
IOW, it's the scoping to a specific instance that is different from the existing `include` or `import` libraries.
It means when you do this (assuming you wrote a counter-obj.zjsc object):
You will get two independent instances of the counter object, each with their counter variables scoped to their own instance, and each with their HTML scoped to their own instance.Re: ZjsComponent: A Pragmatic Approach to Reusable UI Fragments for Web Development
#55Earlier quoted context omitted.
Angular has nothing to do with web components. It isn't even a way to write web components. If anything is the "Google blessed" way of writing web components (Google doesn't really work that way), it's Lit: https://lit.dev/
I'm aware of Lit and thought about mentioning some of its past versions too from the pre-spec era, but I think those are even more forgotten. Around Angular 8-14 era Angular had a lot of "Angular is Web Components" marketing and assured devs at the time that the Angular way including CSS Modules support and its HTML Template language (and its super complex compiler) were "browser standards and the future of Web Compo…
"pre-spec days"? What are you even talking about?
Re: ZjsComponent: A Pragmatic Approach to Reusable UI Fragments for Web Development
#56Earlier quoted context omitted.
There are quite a few HTML include components out there. A quick GH search return a lot of results. From very simple ( https://github.com/include-html/include-html.github.io/blob/... , from 3 years ago), to more sophisticated, including script execution ( https://github.com/SirPepe/html-import/blob/master/src/html-... , from 4 years ago; or even https://github.com/webcomponents/html-imports/blob/master/sr... , dating…
Thanks to the availability of ChatGPT and Claude, I have actually checked all those links prior to creating my own. The ZjsComponent thing I use is unlike those things; while the goal of those (and other similar projects) is primarily to perform client-side includes, the goal of zjs-component is to provide client-side object instantiation using a remote object definition. The paper itself may be a bit arcane and obsc…
I mean, web components are JS with HTML in them and you have all the power of JS to manage state and functionality. In case of zjs you have HTML with JS in it and you get an entry point callback to set up your instance (and another to clean it up).
BTW, the API is a little awkward (`exports.onConnect = function () { /.../ }`) and easy to mix up with the standard syntax (`export function onConnect() { /.../ }`) which you can't actually use here.
In either case you have to include a script into your page to make the component work. But also when you have many different components in case of regular webcomponents you use a somewhat readable markup:
With zjs you have to use the same tag for everything:
To me this looks not unlike the primordial div soup. And on top of it it's 1 more request as compared to regular webcomponents.The point is if HTML inclusion is not the main feature, but rather the per-instance state then regular WebComponents seem like a better solution if only for being a standard. When a reader sees a WebComponent they immediately know what they're dealing with. zjs appears to solve the same problem but differently, yet uses WebComponint API itself.
Re: ZjsComponent: A Pragmatic Approach to Reusable UI Fragments for Web Development
#57Earlier quoted context omitted.
Thanks to the availability of ChatGPT and Claude, I have actually checked all those links prior to creating my own. The ZjsComponent thing I use is unlike those things; while the goal of those (and other similar projects) is primarily to perform client-side includes, the goal of zjs-component is to provide client-side object instantiation using a remote object definition. The paper itself may be a bit arcane and obsc…
How is this different to the standard WebComponents then? I mean, web components are JS with HTML in them and you have all the power of JS to manage state and functionality. In case of zjs you have HTML with JS in it and you get an entry point callback to set up your instance (and another to clean it up). BTW, the API is a little awkward (`exports.onConnect = function () { / ... / }`) and easy to mix up with the stan…
Yes, they are better, but they also require more lines of code to express the same component; I consider zjs-component more as a low-code alternative to extending HTMLElement than as a replacement for HTMLElement.
For example, extending HTMLElement into a `` element and a `` element is much more boilerplate than simply writing the header and footer fragments into an HTML file and doing `` for `header.zjsc` and `footer.zjsc`. No class definition, no component registration, no shadow DOM/light DOM distinction.
At this point it is nothing more than a fancy include/import library.
Now once you have that, maybe for some of those remote sources you want some code to execute (headers for example may want to make an additional request to determine how many notification counts to display).
You can, in the header.zjsc file, export a constructor function. No boilerplate, no `class` keyword, no element registration, etc.
Maybe you need a `check for new notifications` button in the header at some later stage, then you can export a function `updateNotifications()` in header.zjsc, add a button somewhere in that file, and set the attribute `onclick="ZjsCompontent.send(this, 'updateNotifications')`.
So, sure, you can do all this with a little bit of boilerplate using standard web components, but I got tired of writing what is essentially 90% the same code for fairly trivial components.
I really really wanted client side includes, but I also really really wanted them to be cheap to write, as in "here's some HTML + JS that comprises an object, with exactly zero boilerplate".
With webcomponents I'd use custom events to ensure that any child element can invoke a method in the webcomponent (adding or removing itself from a menu, for example). Creating the custom event is unwieldy in HTML onclick attributes; can be done but is very much mostly boilerplate.
The zjs-component approach is to use the static method to dispatch an instance method name and arguments to that method call directly in the onclick (or other) attributes.
When I use terms like "lightweight" and "heavyweight", I do not mean in terms of runtime bloat/lack of bloat. I mean in amount of boilerplate lines that are repeated for every component that is created.
The last thing I did not like about web components was the potential for clashes. Where you see:
> To me this looks not unlike the primordial div soup.
because it's all the same tag, I see potential clashes because one library might register the same tagname as another, overwriting it. With web components there is no safe way to have two different menu libraries if both of them register the same tagname.
This problem does not exist if the component is written as a zjs-component because, by necessity alone, it is not possible to have two different components at the same `remote-src` path.
So, yeah, "it's all divs" is a valid complaint, but it does fix a potential clashing when using different components from different authors.
Re: ZjsComponent: A Pragmatic Approach to Reusable UI Fragments for Web Development
#58Shameless plug; I'm the author. Criticism welcome. I use this for client-side includes and web components. No build process, no web-packer, no framework, no npm requirement. Just include the JS in your HTML and then you can create and include components.
1) I thought that React already worked this way until I learned it, and was horrified. Similar disillusionment with Ruby on Rails, Objective-C on iOS and Java on Android. Why someone would want to mix code and markup, rather than define components via code to be used within markup, blows my mind. Said as someone who uses PHP daily and sees JSX as its frontend analog.
2) I appreciate that async/await and promises were deliberately left out of the spec. I view their use as an anti-pattern, since I've programmed both async/nonblocking and sync/blocking sockets logic, and view sync as far superior if deterministic behavior is the goal. I know this is a contentious subject, but IMHO async will someday be considered the goto of the web and be deprecated across most languages. Better approaches such as scatter/gather arrays, coroutines and channels (like in Go) exist to remove the temporal/imperative aspect of logic and make it declarative without requiring red/blue functions.
3) The main problem I've encountered with React is that it's nearly untraceable in web inspector. It's impossible to tell which component object instance is associated with an HTML element. It's hard to tell where attribute values came from, unlike function arguments: are they props that aren't declared in a function prototype? are they magically mapped from redux state? are they derived neither in the constructor nor componentDidMount() or affected by an affect they weren't supposed to be? etc etc etc. Component methods are buried in dozens of anonymous functions and boilerplate. Promise values can't be inspected until their then() method without using tricks like Promise.resolve(), which don't always match intuition. Redux state can't be conveniently inspected without adding debug lines to the source code and/or installing a browser extension. Code gets mutated by the build pipeline so it's hard to find code snippets to set breakpoints. I could go on. Have you found ZjsComponent easier to debug, and if so, how?
4) I applaud your use of caching for client-side includes. IMHO much of the complexity of React is around its deliberate rejection of HTTP idioms and metaphors. We already solved these problems declaratively in the mid 1990s, why are we manually managing initialization and state, even if through Redux? That was a rhetorical question, but really, React doesn't seem nearly as reactive as something like a spreadsheet that just re-renders cells that reference cells that changed. Basically all of its component methods could be replaced by the render() method containing a JSX template, with the state boilerplate handled by the framework internally via declarative and data-driven techniques like observing variables for changes. Instead, they put the onus on developers, which wastes all of our time and sanity.
5) Do advanced use cases such as components built with other components, subresource integrity (SRI) and observing variables similarly to Vue.js watchers "just work"? I'd be curious to hear your vision for the future.
6) (Special mention) after driving myself crazy manually managing recycler views in iOS, Android and React, I wanted to highlight https://github.com/splinesoft/SSDataSources and https://github.com/SDWebImage/SDWebImage (no affiliation with either). The idea is to populate callbacks to handle the lifecycle of table view cells. That way, an array or generator in memory can be mapped to a table and automagically handle all scrolling and resizing edge cases. Including dynamically loading images and other async data with caching via SDWebImage, without crashing when navigating between view controllers that get disposed, while running as fast as possible. With these metaphors, all other GUI elements can be derived. These are the only frameworks that I've ever used that do all of this correctly. Which let me do declarative web-style programming natively by treating tables as already fully populated, rather than building rows and columns programmatically. Perhaps something in this could inspire a ZjsComponent that "just works" like an ordinary web table, but fast, without the memory hogging of the browser DOM or React's virtual DOM.
Re: ZjsComponent: A Pragmatic Approach to Reusable UI Fragments for Web Development
#59Earlier quoted context omitted.
I'm aware of Lit and thought about mentioning some of its past versions too from the pre-spec era, but I think those are even more forgotten. Around Angular 8-14 era Angular had a lot of "Angular is Web Components" marketing and assured devs at the time that the Angular way including CSS Modules support and its HTML Template language (and its super complex compiler) were "browser standards and the future of Web Compo…
> Lit was never quite so extreme in its worst pre-spec days "pre-spec days"? What are you even talking about?
A decorators proposal (and it was a different one than what Google was building stuff off of in 2019) didn't make it to Stage 3 until 2022 (and still hasn't made it to Stage 4).
This also contributed to the idea for years that Web Components were more complicated to support in non-Google browsers or without complicated build processes.
Re: ZjsComponent: A Pragmatic Approach to Reusable UI Fragments for Web Development
#60Earlier quoted context omitted.
> Lit was never quite so extreme in its worst pre-spec days "pre-spec days"? What are you even talking about?
Lit 1.0 used non-standard decorators in 2019: https://lit.dev/blog/2019-02-05-lit-element-and-lit-html-rel... A decorators proposal (and it was a different one than what Google was building stuff off of in 2019) didn't make it to Stage 3 until 2022 (and still hasn't made it to Stage 4). This also contributed to the idea for years that Web Components were more complicated to support in non-Google browsers or without c…
Lots of developers like decorators, we gave them the option. _shrug_