Live data from Hacker News

Architecting UIs for Change

joreteg.com

11–20 of 29 posts

Re: Architecting UIs for Change

#11
post #7
post #6

While I don't use Redux anymore, one point in the article really resonated with me: having a single source of truth for the entire app state enables you to "run an entire functional application without any visual components having been built whatsoever". This decoupling of state (and its reducers/actions) from view is a powerful architecutral pattern that I learned from Redux, and I've built every React application (…

Hi, I have exactly the same conclusion as you - you can check my demo todo app - where the UI is an extension to the app. I'm having React and Mustache renders to demonstrate how the view is totally decoupled from the app logic. It have SSR, both for React and Mustache, Service worker for offline usage. Redux for state management. I'm using typescript. https://drmzn-todo-app.herokuapp.com/ https://github.com/max0xff/…

That diagram is wonderful, every part of it makes sense. I also liked how you describe the "lifecycle" step by step. In a way, it made me realize how the Redux pattern fits in with an evolution of MVC.

I think I'm similar to you, in that I've been developing my own solution to manage the whole app lifecycle in a way that makes sense to me, with a library of (mostly) my own modules so I can reuse it across all apps I build.

At the same time, there's value in following "community standards", generic libraries and patterns that most people are familiar with. So, I'm a bit torn on creating my own patterns/utilties versus adapting existing ones that everyone's using.

Re: Architecting UIs for Change

#12
re-frame (https://github.com/Day8/re-frame) essentially implements the ideas and patterns presented in the article/post. Of course you would need to learn ClojureScript to use it, but that might be worth it.

I really like the "selector" pattern. Your app state should not have to reflect your UI component tree. Rather you use selectors to subscribe to some part(s) of your application state and derive any necessary values in the subscription/selector function.

Representing your app state as a single source of truth and expressing all changes to state as effect handling functions means you can now easily test your front-end app without involving a dom at all! It is state transitions that are interesting.

Of course there are other options like Redux and Vuex for React and Vue respectively as well as the elm language if you want to go all in on static types and compile time error checking.

Re: Architecting UIs for Change

#14
post #7

Earlier quoted context omitted.

Hi, I have exactly the same conclusion as you - you can check my demo todo app - where the UI is an extension to the app. I'm having React and Mustache renders to demonstrate how the view is totally decoupled from the app logic. It have SSR, both for React and Mustache, Service worker for offline usage. Redux for state management. I'm using typescript. https://drmzn-todo-app.herokuapp.com/ https://github.com/max0xff/…

That diagram is wonderful, every part of it makes sense. I also liked how you describe the "lifecycle" step by step. In a way, it made me realize how the Redux pattern fits in with an evolution of MVC. I think I'm similar to you, in that I've been developing my own solution to manage the whole app lifecycle in a way that makes sense to me, with a library of (mostly) my own modules so I can reuse it across all apps I…

Thank you so much for checking it out. I'm so happy that diagram makes sense to you.

One of my favorite talks is from Robert Martin, the first link on the bottom of the about.md - when he explains the history of MVC, I realised that the original idea for MVC is exactly what Redux is. But in the years people changed the meaning of MVC and that's why now it seems different. For me, Redux is 1:1 as M from original MVC docs from the 70s.

I'm also torn on using "standards" vs my own implementation. I feel kinda like an outcast, using my own "framework".

Side joke: With hooks and functional components, the React community is moving in our direction. I cannot wait for the next logical conclusion - Lets move the hooks out of the components :)

I would like to see some of your code, if you like to share it, please send me an email: alex.tzvetanov at gmail com

Thank you again for spending time on my code and thanks for the feedback!

Re: Architecting UIs for Change

#15
I think there actually is an issue with our data models. REST apis have moved a lot of the complexity of data fetching on the client apps since it is basically a 1 to 1 mapping of the database schemas. Making connections between the different data types becomes a frontend concern which is not ideal since frontend has to deal with partial data and full network latency / failures.

Thinking in graphs and query languages like GraphQL makes building for change a lot easier. Your api now defines all the possible data types and their associations (think nodes and edges). This completely eliminates the need to write data management code as a graphql client library can take care of fetching, normalizing and providing the data to components since it knows about the data schema.

Queries can also be composed from fragments which goes very well with the React component model. This allow each component to define the data it needs and then all those fragments can be composed to generate a query. This query will only fetch the exact data it needs for what is displayed wherever the data comes from.

It does move back a bit of the complexity to the backend (defining schema, fetching connections between the different data types) but this is a lot easier to implement since you have full access to all resources. It is also easier to iterate on the implementations since code shipped to client apps can be hard to update when considering mobile apps.

Re: Architecting UIs for Change

#17
post #8
post #6

While I don't use Redux anymore, one point in the article really resonated with me: having a single source of truth for the entire app state enables you to "run an entire functional application without any visual components having been built whatsoever". This decoupling of state (and its reducers/actions) from view is a powerful architecutral pattern that I learned from Redux, and I've built every React application (…

Do you store all UI state in redux as well as all 'resource state'? Phrased as an example... If you store a JSON object that can be edited in your store do you also store a Boolean value for whether the dialog is open that can be used for editing that JSON object?

My determination is:

Do I want this state to survive a page reload, new browser session, or coming from a bookmark?

The value in a drop-down box in some random form? Non-global state.

The main page active tab that they were probably reading? Global state.

Scroll position? Global.

Tooltip Position? Probably not useful, non-global.

Something like a dialog or modal depends on the situation of how important it was and if the user would expect it to be there.

Re: Architecting UIs for Change

#18
post #16

What would be the difference (if any) from the selector concept presented in the article vs the reducer pattern in redux?

The reducer persists the state in the store, the selector projects the store.

Another way to put it selectors are a particular view of the data that's in the store.

Re: Architecting UIs for Change

#19
post #8

Earlier quoted context omitted.

Do you store all UI state in redux as well as all 'resource state'? Phrased as an example... If you store a JSON object that can be edited in your store do you also store a Boolean value for whether the dialog is open that can be used for editing that JSON object?

Hmm, typically, I do store "UI state" (or parts of it) in the top app state if that UI state is shared among pages/routes. In your example, if I want that dialog state to be "persistent" - say, the user goes to another route then comes back, if the dialog state should be kept. Otherwise, I store them in the route component's state, which gets created anew every time. But your question makes me think, if I store any U…

Unless you have code that depends on state that supposed to be kept UI-only.

Then when you expand to an API or CLI interface the web state being tracked no longer makes sense and might be extra ram or loading time.

Re: Architecting UIs for Change

#20

re-frame ( https://github.com/Day8/re-frame ) essentially implements the ideas and patterns presented in the article/post. Of course you would need to learn ClojureScript to use it, but that might be worth it. I really like the "selector" pattern. Your app state should not have to reflect your UI component tree. Rather you use selectors to subscribe to some part(s) of your application state and derive any necessary v…

Hey, author of the post here... reframe does seem very similar conceptually (I wasn't aware of it, thanks for the link).

Another interesting parallel between the two is that I implement a "loop" mechanism as well. Essentially, if no actions are fired for a while, and APP_IDLE action is dispatched which just updates "appTime" in redux store. As a result any selectors that depend on time as an input will recompute. This allows for actions to be fired over time based on age of the data, etc.

Elm and others are very cool. I just think a pure JS solution is nice, since that's what the browser runs.

Post reply on HN