Live data from Hacker News

None of my projects want to be SPAs

whatisjasongoldstein.com

351–360 of 362 posts

Re: None of my projects want to be SPAs

#351
post #297

Earlier quoted context omitted.

>exists only once and is needed in many parts. I think many people could argue that this concept itself is a bit misguided. There are plenty of application patterns and architectures that help you move stateful data around your app and translate it for the components who need to consume it or change it, while hiding it from components in the tree which do not interact with or care about the state. If you have many di…

Sorry to reply twice to the same comment, but if you have an instance of a user model, and you need to display the model data in the navigation bar, on the user profile page, and in a comment thread, how would you manage that data? And do you think that having a single source of truth reduces complexity or creates more problems than it solves?

There are definitely options and choices for all of this, but I can give my professional opinion.

First question (show user data in nav bar, user details page, and "comment thread"):

User profile page is obviously showing full user details, so you're going to want to have a separate endpoint for "getUserDetailsByUserId(int userId)" or however you want to name it.

What data are you showing in your nav bar? Is this just a user-avatar image link/button? You would rarely want to display anything other than an avatar and/or username in a navigation bar. You could maybe talk about a navigation drawer instead, where you have more simple details like maybe email address and phone number or something.

What about the "comment thread"? Are you showing anything more than an avatar and/or username? This sounds like the same use-case as the nav bar... how would the display differ here?

If you have use-cases for anything more than your basic "user avatar" and "full user profile," (and maaaybe "user basic info," for a "nav drawer" or something, although those are being phased out of most current design standards) then I would seriously urge you to re-think your app design. That polish of showing the user info in a slightly different slice on some specific page is almost never going to pay off for your company, imo.

Anyways, if you want to be naive about all of this, you just save the userId (and token or whatever, but that should be in your http middleware) after a new login session, and then you request separate "getUserNavBarInfo(userId)", "getUserDetails(userId)", and "getUserCommentInfo(userId)" and load the results of those into your UI views on-demand. If you need to progressively tune/cache your API, you do this separately based on usage stats for each of these 3 use-cases, you don't start with directly caching "Users" and adding the business logic client-side to translate into the 3 use-cases.

If you want to do a more thorough dependency-injection "user component," then this might vary depending on your DI framework, but the high-level idea would always just be to create a user module with all the info needed for a given user, wire it up to reload the module in your DI graph on new login and on-success of any request to update user info. You could have both your "login" and "update user" endpoints both return the full set of data needed for the "user module" on success. Then you need to set up your DI injection component scoping so that your user info injection component is dumped on user logout and settings change, and is recreated to do it's injections with the new/updated user module each time. A singleton DI "user component" that you must choose to inject into any UI component that wants to show user information seems much more constrained in complexity to me than just having the ability to arbitrarily pull out various bits of user info from a global redux state, at any place in your app.

Second question (single source of truth, increases or decreases complexity?):

I think this question is orthogonal to the capabilities Redux (and similar) provides. Redux has nothing to do with outright increases or decreases in app complexity, it is simply a tool that enables various (opinionated) architecture patterns. If you have a separate, domain-specific, well-defined event+data architecture that you are sticking to very strictly to keep a handle on complexity, then Redux can (imo) reduce boilerplate and allow very elegant interactions between various data/biz logic/UI components of your application, all without any "tight coupling". It's really just a message-bus pattern at some level. This sort of thing has been around longer than the concept of software itself, there are hardware components literally called "buses" that basically do the exact same thing (ship events and data around to various interested parties without requiring a direct circuit connection). The danger is that it opens up a TON of pathways to insane complexity and totally unintuitive event & data flows, because it kind of allows you to arbitrarily add "side effects" to basically anything in your application. VERY easy to foot-gun yourself here if you start getting lazy and just wiring up random shit instead of following strict event/data patterns and keeping the "feature code" as simple as possible (e.g. with a strict facade for writing new pages).

This might rustle some feathers on here, but I wish people would think of React/Redux sort of as "framework primitives" that are SUPER useful for constructing your own domain-specific client-app frameworks, but somewhat dangerous to open up directly to front-line product code written by junior devs. I would much rather see a few senior devs use React/Redux to construct a tightly-defined domain framework that exposes a simple facade to junior devs to construct new pages/routes/behaviors in your FE application. I think using these tools like this would greatly reduce the dreaded "React learning curve" of 3-4 months that everyone talks about. That could be done over time if you put in the work up front to build an internal facade pattern around your core React/Redux app architecture. Then junior devs could choose to dig into things behind the scenes as they go, instead of being forced to front-load the entire React/Redux knowledge stack up front right when they walk in the door.

Re: None of my projects want to be SPAs

#352
post #326

Earlier quoted context omitted.

I am interested in designs/technologies that could be viewed as alternatives to the usual tech stack for SPAs, even if these technologies are outdated but exhibit interesting properties compared to what we are used to today. That would include Smalltalk and Delphi yes. Sorry if I misunderstood your initial comment.

Well, Delphi is well alive and current: https://www.embarcadero.com/products/delphi (it have a free edition) and alzo exist Lazarus, a open source clone: https://www.lazarus-ide.org Is probably the most fleshed idea under more "traditional" paradigms (OOP, RAD, etc) Smalltalk and others are less popular(?) and only know them passing, so can't give too much of that. --- Another interesting stuff can be rebel/red: http…

Thank you!

Re: None of my projects want to be SPAs

#353

Earlier quoted context omitted.

That isn't a limitation of SPA or browser based apps though. For that matter, even having an option to open an app multiple times is often a limitation of desktop apps. That doesn't make them somehow deficient as a platform.

It does. You don't open the "app" multiple times, you open lists or records in separate windows and/or tabs. That is a thing in desktop apps also. SPAs usually break it by tunneling everything through a single url, perhaps with anchors.

But opening lists/records in another window/tab isn't a limitation of the browser environment, or SPA in particular. With proper router/caching in place it can be done within a browser app as well.

Re: None of my projects want to be SPAs

#354

We recently went in the opposite direction for a student project I'm working. We have a full SPA Angular frontend, and we use CouchDB as our datastore. There is a Node "backend," but it only serves things like Slack integration, the browser has a local PouchDB instance that directly syncs with the server's CouchDB. This way, we can deploy hotspots with nothing more than a Couch install and a static server for the SPA…

This sounds interesting. I'm light on details on how CouchDB and its sync works, but how do you deal with data validation/data conflict? Or maybe malicious actors tampering your data? Or is it a closed app that already have those dealt with in the spec? It would be awesome if you can share more about the project.

I'll email you a copy of the whitepaper once it is finished. The famous quote is, "CouchDB is bad at everything, except syncing." It has a built in revision system that will create two conflicting revisions on both ends, and allow your code to implement the business logic to determine the one true revision. This could be a prompt, or a rule based on the data (ex newer timestamp winds), or even an average of various data fields to create a whole new field.

http://guide.couchdb.org/draft/conflicts.html

Re: None of my projects want to be SPAs

#355

Earlier quoted context omitted.

This sounds interesting. I'm light on details on how CouchDB and its sync works, but how do you deal with data validation/data conflict? Or maybe malicious actors tampering your data? Or is it a closed app that already have those dealt with in the spec? It would be awesome if you can share more about the project.

I'll email you a copy of the whitepaper once it is finished. The famous quote is, "CouchDB is bad at everything, except syncing ." It has a built in revision system that will create two conflicting revisions on both ends, and allow your code to implement the business logic to determine the one true revision. This could be a prompt, or a rule based on the data (ex newer timestamp winds), or even an average of various…

Wow, the revision system is really interesting. Makes sense why you used it that way. Thanks for the link! Am excited to wait for the whitepaper.

Re: None of my projects want to be SPAs

#356
post #280

Earlier quoted context omitted.

You selectively quoted me, ignoring where I explained that synchronization isn't as big of a problem with passing properties into components. I already addressed your concern. Don't selectively quote me, it's rude and just shows you aren't following the conversation. Futher, Redux doesn't solve synchronization issues in situations where you can't represent the data the same way. In the most complicated situations, it…

I read the thread. You hand-waved away a non-trivial problem by "explaining" properties are a thing. Thanks, bud. I'm sorry I didn't cite your favorite source to your satisfaction, but I quoted the relevant parts of the post I replied to. > Futher, Redux doesn't solve synchronization issues in situations where you can't represent the data the same way. It's kind of the whole Redux philosophy that you won't do that. I…

But, in a project of any significant complexity, you will represent the data in different formats, because transforming data into different formats is one of the main functions of software. Relying on a framework that assumes you won't do something that you will do is a Very Bad Idea.

Re: None of my projects want to be SPAs

#357
post #250

Earlier quoted context omitted.

Okay, so the only way it's actually possible to have any refactoring of your data structures require only changing one selector is that you've got a single selector for literally every piece of data in your system, at which point you've had to manually flatten everything out into a bunch of selectors, and lost all the benefits of being able to read a structured chunk of data. If you actually do that (which I don't th…

Not at all; you can write selectors that return a branch of your state tree, and you can generally tell where the line should be (user makes more sense than userName and userEmail). You keep saying that you won't have these problems if you don't use redux, but I am arguing that _you do have these problems_, you're just creating ad-hoc solutions for everything that you would use redux for, except those solutions are s…

> Not at all; you can write selectors that return a branch of your state tree, and you can generally tell where the line should be (user makes more sense than userName and userEmail).

And then you're right back to any component that uses User being tightly coupled to the structure of the User, without any of the syntactic cues that allow you and your static tooling to connect the two.

> except those solutions are sprinkled into your UI components in a way that makes them full of mutable state that is impossible to test and a constant source of bugs.

That's not the case:

1. There's nothing preventing you from treating components as a pure function of their props.

2. At the top level, it's necessary to have some mutable state, but I'm not sure where you get the idea that this isn't testable. Redux doesn't remove mutable state: all redux is doing is a big complicated version of newState = pureFunction(oldState) which is perfectly possible to do using Vanilla JS functions.

Re: None of my projects want to be SPAs

#358
post #337

Earlier quoted context omitted.

Magpie test? I couldn't find an answer on google.

The article has a reference and link to [1], where the behavior of constantly looking for new and shiny tech is likened to that of a magpie. As Svelte is still fairly new and not widely used, I think maybe it is in that class of technology. 1: https://blog.codinghorror.com/the-magpie-developer/

Makes sense, thanks!

Re: None of my projects want to be SPAs

#359
post #299

Earlier quoted context omitted.

Some years ago, 3 of us picked React for a startup. I consider it the single biggest mistake in my career, but we picked it not for the reason you mention. We didn't think that far (I was perhaps a junior, but the others weren't). It was just a matter of picking the frontend framework that we liked the best (I think the options were between Backbone, Ember, AngularJS, React). In our minds we did pick the simple optio…

> I consider it the single biggest mistake in my career I have to ask... what went so wrong? If you had a time machine, what would you tell your younger self?

Oh I'm so sorry, I didn't see the replies.

It was a mistake because we needed to move fast and figure out if we had something or not. A simple CRUD website (say Ruby on Rails, Elixir/Phoenix, or even straight up Node/Express) would have been faster to build and iterate on.

There was one section of it that would benefit from being able to work while offline, so that could perhaps have been built as a small SPA. But the rest, that was in hindsight a mistake.

Re: None of my projects want to be SPAs

#360
post #284

Earlier quoted context omitted.

Some years ago, 3 of us picked React for a startup. I consider it the single biggest mistake in my career, but we picked it not for the reason you mention. We didn't think that far (I was perhaps a junior, but the others weren't). It was just a matter of picking the frontend framework that we liked the best (I think the options were between Backbone, Ember, AngularJS, React). In our minds we did pick the simple optio…

If you had to redo what would you pick? Why not jQuery?

jQuery would have been fine, but honestly the website did not need that much js (if any). It should just have been a CRUD website.
Post reply on HN