Skip to main content

Posts

Dispatching multiple Redux actions

I was working in my Redux app today and was facing the question of how best to submit a “create” API call to the backend and then transition to a “confirm” page. I wired up my router to be sensitive to the Redux store, so a reducer could trigger the page change. I’m using redux-pack to handle async events, which I find quite pleasant so far (though I haven’t gotten deep into testing it, which is a bit awkward because it requires faking out some internals). One solution is to have the component that is handling the “submit” button dispatch the API call action and then use the Promise that redux-thunk provides as a return value to chain the router action. But, the Promise will always resolve when the action completes, even if the API call was not successful, leading to some awkwardness in detecting if the create actually happened without error before doing the redirect. I also have a fantasy of generically dispatching actions via POSTs on the backend (“isomorphic Redux,” if you w...
Recent posts

Separation of Concerns Leading to Implicit Dependencies

I’ve been building a toy app to feel out server-side React, Redux, GraphQL, &c . to explore ways to build my next webapp(s). One thing this has introduced me to is react-router . react-router has good support for SSR because it lets you statically determine the set of Component classes that match a route so that you can load their data before rendering them. Its route descriptions allow nesting, which translates interestingly to your rendered UI. Here’s my routes.js file: <Route path="/" > <IndexRedirect to="/rails/rails" /> <Route path=":ownerName/:repoName" component={App}> <IndexRoute component={IssueListPage} /> <Route path=":number" component={IssuePage} /> </Route> </Route> This is used to make pages that look something like these: (When in doubt, make a GitHub viewer.) The App component renders the header with the repo name, and react-router passes it a child component,...

Convention vs. Abstraction to Prevent Bugs

When I was working on Blogger, I caught the dependency injection bug and led a conversion of the frontend code to a new, DI-heavy pattern. This greatly helped our testability, as it let us move away from the service locator   anti-pattern we had been relying on. I got a bit carried away, though. One piece that I generalized out was the concept of a link to another part of the UI. All these links had to have a blogID query parameter to work, but exposing that to the page controller was a mixture of concerns, right? We could instead inject type-checked BlogUri representations of these URLs into the page controllers, and they could render them without ever having to know the right blogID to use. This code enforced that you could never write bugs about linking to the wrong page, or using the wrong blogID parameter. Useful, right? Nope. Those are two bugs that people basically will never write. If you’re on a settings page, linking to a template page, there’s no circumstanc...

Vue.js and server-side rendering

I’m thinking about how I want to build webapps for the next six months, and I’ve gathered some requirements: Nothing too esoteric. Handing off to junior engineers is a priority. Server-side first. JavaScript as a progressive enhancement. Structured with React or some other component-based framework, not nested templates. Mobile friendly, even mobile-first. Ruby on Rails certainly satisfies the first two requirements, but not the third. I’m feeling very drawn to a server-side rendered JavaScript framework because it can give a smooth transition from server-rendered content to a more interactive site. Though I’d default to React because it’s my first JS framework love, I’ve heard enough people mention Vue.js that I needed to get up to speed on it. Vue.js bills itself as a reactive component framework, similar to React, but with a smaller footprint, greater performance, and more in-house ecosystem pieces ( vue-router , vuex ). A more proscriptive ecosystem has its advant...