Building Maintainable Web Applications Using React – an Evaluation of Architectural Patterns Conducted on Canvas LMS
Total Page:16
File Type:pdf, Size:1020Kb
Linköping University | Department of Computer and Information Science Master’s thesis, 30 ECTS | Datateknik 2020 | LIU-IDA/LITH-EX-A--20/004--SE Building maintainable web applications using React – An evaluation of architectural patterns conducted on Canvas LMS David Johansson Supervisor : Jonas Wallgren Examiner : Peter Fritzson Linköpings universitet SE–581 83 Linköping +46 13 28 10 00 , www.liu.se Upphovsrätt Detta dokument hålls tillgängligt på Internet - eller dess framtida ersättare - under 25 år från publicer- ingsdatum under förutsättning att inga extraordinära omständigheter uppstår. Tillgång till dokumentet innebär tillstånd för var och en att läsa, ladda ner, skriva ut enstaka ko- pior för enskilt bruk och att använda det oförändrat för ickekommersiell forskning och för undervis- ning. Överföring av upphovsrätten vid en senare tidpunkt kan inte upphäva detta tillstånd. All annan användning av dokumentet kräver upphovsmannens medgivande. För att garantera äktheten, säker- heten och tillgängligheten finns lösningar av teknisk och administrativ art. Upphovsmannens ideella rätt innefattar rätt att bli nämnd som upphovsman i den omfattning som god sed kräver vid användning av dokumentet på ovan beskrivna sätt samt skydd mot att dokumentet ändras eller presenteras i sådan form eller i sådant sammanhang som är kränkande för upphovsman- nens litterära eller konstnärliga anseende eller egenart. För ytterligare information om Linköping University Electronic Press se förlagets hemsida http://www.ep.liu.se/. Copyright The publishers will keep this document online on the Internet - or its possible replacement - for a period of 25 years starting from the date of publication barring exceptional circumstances. The online availability of the document implies permanent permission for anyone to read, to down- load, or to print out single copies for his/hers own use and to use it unchanged for non-commercial research and educational purpose. Subsequent transfers of copyright cannot revoke this permission. All other uses of the document are conditional upon the consent of the copyright owner. The publisher has taken technical and administrative measures to assure authenticity, security and accessibility. According to intellectual property law the author has the right to be mentioned when his/her work is accessed as described above and to be protected against infringement. For additional information about the Linköping University Electronic Press and its procedures for publication and for assurance of document integrity, please refer to its www home page: http://www.ep.liu.se/. © David Johansson Abstract Maintainability for web applications is increasingly important due to increasing de- mands for advanced functionality as well as a short time-to-market. Fixing errors, reusing functionality and adding new features efficiently are crucial for making the application profitable for the software organization as well as valuable for the end-user. Modern frame- works and libraries such as React assist web engineers in building sophisticated applica- tions using high-quality solutions called architectural patterns. In this thesis architectural patterns have been evaluated by performing static code analysis using well-established metrics. The evaluation was conducted using a Design Science Research approach on the Learning Management System Canvas. The results showed large variations in maintain- ability depending on the architectural pattern used. Acknowledgments I would like to thank VISIARC for giving me the opportunity to write this thesis covering an interesting subject, giving me supervision and a place to do the work. Furthermore, I would like to thank my supervisor Jonas Wallgren and examiner Peter Fritzson for providing assistance and valuable guidance throughout the work keeping the thesis on the right path and help to achieve the best results possible. Last, but not least, a big thanks to my family and friends for the endless support during this thesis, my studies at Linköping University and every other challenge I encounter in life. iv Contents Abstract iii Acknowledgments iv Contents v List of Figures viii List of Tables ix Listings x 1 Introduction 1 1.1 Motivation . 1 1.2 Aim............................................ 2 1.3 Research questions . 2 1.4 Delimitations . 2 2 Theory 3 2.1 Canvas LMS . 3 Canvas LMS API . 4 2.2 Software . 4 Patterns . 4 Quality . 5 Standards . 6 Measurements . 8 Automated static code analysis . 8 2.3 Maintainability . 9 Metrics . 9 Lines Of Code . 10 Cyclomatic Complexity . 10 Coupling . 11 Cohesion . 11 Design Complexity of Card and Agresti . 12 Software Science Effort . 13 2.4 Javascript . 14 ECMAScript . 14 Engines . 15 Node.js . 15 Node Package Manager . 15 2.5 Web applications . 15 Single Page Application . 16 Fetching data . 16 v REST API . 17 GraphQL API . 17 Relay schema specification . 19 2.6 Frameworks and Libraries . 19 React . 20 Component . 20 States and props . 20 Class-based components . 21 Life-cycle methods . 21 Function components . 22 React Hooks . 22 Virtual DOM . 22 Context API . 23 create-react-app . 24 2.7 Architectural patterns . 25 Model-View-Controller . 27 Model-View-ViewModel . 28 Flux . 30 Architectural pattern in Redux . 31 Redux in React . 32 Architectural pattern in Apollo Client . 32 Apollo Client in React . 33 2.8 Design Science Research . 35 3 Method 37 3.1 Study object . 37 Users administration page architecture . 39 3.2 Preparation . 40 Dependencies . 40 Setting up Plato . 41 3.3 Initial implementation . 42 Source code . 42 Measurements . 44 3.4 Design Science Research approach . 47 Iteration 1 - Redux connect . 48 Awareness of Problem . 48 Suggestion . 48 Development . 49 Evaluation . 50 Iteration 2 - GraphQL, Apollo Client Cache and React Context API . 53 Awareness of Problem . 53 Suggestion . 53 Development . 54 Evaluation . 55 Iteration 3 - GraphQL and Apollo Client Cache without React Context API . 57 Awareness of problem . 57 Suggestion . 58 Development . 58 Evaluation . 58 4 Results 61 5 Discussion 63 vi 5.1 Results . 63 5.2 Method . 64 5.3 Source criticism . 65 5.4 The work in a wider context . 65 6 Conclusion 66 6.1 Research questions . 66 6.2 Future work . 67 Bibliography 68 vii List of Figures 2.1 The control flow graph for.