Giter Site home page Giter Site logo

architecting-single-page-applications_vue's Introduction

Introduction

This repo is a re-implementation of @intojs/architecting-single-page-applications in Vue. I read Daniel Dughy's article describing this architecture and had to try it out.

Using Vue

Vue lived up to its "progressive framework" label, and worked as a drop in replacement for the React code in components/. The rest of the application's domain, services and store worked identically. Other than a bit of trouble getting Flow up and running for the first time, the port was very straightforward. Since the 'backend' (business logic?) was mostly kept out of the view components thats where I started. I made the mistake of starting to implement the store with Vuex before actually reading the code and realizing that ArticleStore was a minimal reimplementation of Flux ideas. For next steps I'd like to see how hard it would be to swap it out for a Vuex implementation.

For the components, I began by copying the markup for the presentational components without any of the Vue / React stuff. Next I made the container components, stubbing out their functionality and importing the necessary interactions with the services / store. Finally, I got into enabling all the Vue functionality.

This ended up being mostly syntactic changes. Everything in a React constructor became properties in the Vue components data(). There's no difference in readability between having methods in an explicit methods block (in a Vue component) versus having them declared on the class (in a React component).

One difference between React and Vue is their available lifecycle hooks. Sadly this application only made use of them in one place, so it was hard to get much a feel for their differences. In ArticleListContainer, the React version unsubscribed on componentWillUnmount. I chose beforeDestroyed as the closest Vue equivalent. For this usecase they seem equivalent, but I could imagine there might be other situations where I would need to do further reading on the precise differences.

Takeaways

I was very impressed with the separation of concerns this architecture gives by pulling domain logic out of the views themselves.

It seems like it would scale up well, although it was tough to tell with this small of an example. One question I have is where to put API interactions. They should probably live in the domain, and return promises for container components to consume, but I'd be interested to hear if anyone has found other solutions.

I'm also curious if anyone has alternatives to the container / presentational component setup. I don't have any specific criticisms of it, just interested in trying out other options.

architecting-single-page-applications_vue's People

Contributors

dlederle avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.