JavaScript Views, the Hard Way – A Pattern for Writing UI
1–10 of 141 posts
Re: JavaScript Views, the Hard Way – A Pattern for Writing UI
#2The design pattern is based on convention only. This means that a developer is free to stray from the convention whenever they want. In a complex app that many developers work on concurrently, it is very likely that at least one of them will stray from the convention at some point.
In comparison, a class based UI framework like UIKit on iOS forces all developers to stick to using a standard set of APIs to customize views. IMO this makes code way more predictable and this also makes it much more maintainable.
Re: JavaScript Views, the Hard Way – A Pattern for Writing UI
#3The read me says this approach is extremely maintainable, but I’m not sure I agree. The design pattern is based on convention only. This means that a developer is free to stray from the convention whenever they want. In a complex app that many developers work on concurrently, it is very likely that at least one of them will stray from the convention at some point. In comparison, a class based UI framework like UIKit…
I think the maintainability comes from easy debugging. Stack traces are sensible and the code is straightforward. Look at a React stack trace and nothing in the trace will tell you much about _your_ code.
I'd also point out that this looks like it's about seven years old. We've shifted a lot of norms in that time.
Re: JavaScript Views, the Hard Way – A Pattern for Writing UI
#41 - https://github.com/victorqribeiro/TinyJS
2 - https://github.com/victorqribeiro/Chip8js/blob/master/js/Col...
Re: JavaScript Views, the Hard Way – A Pattern for Writing UI
#5A significant issue I have with writing code this way is that the functions nest and it becomes very difficult to make them compose in a sane way.
function printPosts(posts) {
let content = ""
posts.forEach((post, i) => {
content += printPost(post)
})
window.posts.innerHTML = content
}
function printPost(post) {
return `
${post.parsed_text}
${post?.image_urls?.length > 0 ? printImage(`https://imghost.com${post.image_urls[0].original}`) : ''}
${post?.url_preview ? `${printPreview(post.url_preview)}` : ''}
${post?.quote_data ? `${printQuote(post.quote_data)}` : ''}
${post?.filtered ? `filtered by: ${post.filtered}` : ''}
`
}Re: JavaScript Views, the Hard Way – A Pattern for Writing UI
#6I came up with something similar recently, except it doesn't use template elements. It just uses functions and template literals. The function returns a string, which gets dumped into an existing element's innerHTML. Or, a new div element is created to dump it into. Re-rendering is pretty quick that way. A significant issue I have with writing code this way is that the functions nest and it becomes very difficult to…
Re: JavaScript Views, the Hard Way – A Pattern for Writing UI
#7Re: JavaScript Views, the Hard Way – A Pattern for Writing UI
#8It appears to be exactly the kind of manual-update code that reactive view libraries exist to replace.
Re: JavaScript Views, the Hard Way – A Pattern for Writing UI
#9I came up with something similar recently, except it doesn't use template elements. It just uses functions and template literals. The function returns a string, which gets dumped into an existing element's innerHTML. Or, a new div element is created to dump it into. Re-rendering is pretty quick that way. A significant issue I have with writing code this way is that the functions nest and it becomes very difficult to…
Re: JavaScript Views, the Hard Way – A Pattern for Writing UI
#10I came up with something similar recently, except it doesn't use template elements. It just uses functions and template literals. The function returns a string, which gets dumped into an existing element's innerHTML. Or, a new div element is created to dump it into. Re-rendering is pretty quick that way. A significant issue I have with writing code this way is that the functions nest and it becomes very difficult to…
I like it. Not only does it move the UI into JavaScript, but it moves the scripting into the HTML!