Building Your Own JavaScript Framework by Vlad Filippov
Author:Vlad Filippov
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2023-10-16T00:00:00+00:00
Utilizing libraries
It makes sense to commit to specific JavaScript libraries before developing a new framework. The use of existing JavaScript libraries will save you timeâtime you can use to focus on the frameworkâs features and technical architecture. It is a common pattern for frameworks to rely on libraries to build out the internals. These libraries often indirectly enable the framework feature set behind the scenes, including features such as data management, routing, interacting with the DOM, and abstracting away JavaScript runtime complexity. As the framework covers a more extensive feature set and shapes the development experience, the internal libraries focus on delivering a precise solution to a particular problem.
Choosing the right set of libraries can significantly impact the development process and the shape of your framework. The libraries you utilize in your framework will likely make you an expert user of them. However, balancing the benefits of using libraries with potential downsides, such as compatibility problems, API restrictions, and ongoing maintenance, is necessary.
As we explore other JavaScript frameworks, we can identify libraries they rely on for specific functionality. Depending on the architecture, your framework can build the library right into the framework or use it to extend aspects of your framework. If we look at Angular, we will find that it utilizes RxJS (rxjs.dev) for reactive programming, including features such as data observables, iteration, value mapping, and more. The RxJS library can be used directly from within Angular components, such as the following BookService service:
import { HttpClient } from '@angular/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { map, retry } from 'rxjs/operators'; @Injectable() export class BookService { private baseUrl = '...'; constructor(private http: HttpClient) {} getWeather(latitude: number, longitude: number): Observable<any> { const url = `${this.baseUrl}?latitude=${latitude} &longitude=${longitude}¤t_weather=true`; return this.httpClient.get(url).pipe(retry(3)); }}
The preceding code uses the Observable class to return the getWeather function first. From within your Angular classes, you can rely upon RxJS to provide many data-operating operators. In addition, the RxJS library provides error-handling operators, as seen in the retry call in the preceding code. A detailed explanation of the libraryâs operators can be found at rxjs.dev/guide/operators.
Exploring the RxJS example
The chapter5 directory in the book repository includes an example of using Angular with the RxJS library. You can try this out on your own computer by running the interactive script from the chapter directory or executing npm install, and then npm run dev from the angular-rxjs directory.
The example application will utilize the BookService service presented previously to fetch data. The API data comes with additional properties that you can use to extend the existing application. Refer to the README.md files for additional information.
In another example of library usage, Vue.js initially used Vuex as a library for centralized state management. However, as the framework developed, the approach to managing the state changed. Vue has switched over to recommending and utilizing Pinia (pinia.vuejs.org) for state management. With an intuitive approach based on the Flux architecture, the library closely related to Vue, it allows developers to use
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Web Development with Julia and Genie by Ivo Balbaert & Adrian Salceanu(6002)
State Management with React Query by Daniel Afonso(3360)
Eleventy by Example by Robinson Bryan;(3287)
Architecting Vue.js 3 Enterprise-Ready Web Applications by Solomon Eseme(2993)
Building Python Web APIs with FastAPI by Abdulazeez Abdulazeez Adeshina(2889)
Digital Marketing with Drupal by José Fernandes(2821)
Becoming an Enterprise Django Developer by Michael Dinder(1238)
Building Python Web APIs with FastAPI: A fast-paced guide to building high-performance, robust web APIs with very little boilerplate code by Abdulazeez Abdulazeez Adeshina(1170)
Operator Training Simulator Handbook by Joseph Philip(1142)
Practical WebAssembly: Explore the fundamentals of WebAssembly programming using Rust by Sendil Kumar Nellaiyapen(1068)
Google Workspace User Guide: A Practical Guide to Using Google Workspace Apps Efficiently While Integrating Them With Your Data by Balaji Iyer(1057)
Hands-on Cloud Analytics with Microsoft Azure Stack: Transform Your Data to Derive Powerful Insights Using Microsoft Azure by Prashila Naik(1036)
State Management with React Query by Afonso Daniel;(1004)
Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python by Andros Fenollosa(990)
Modern Frontend Development with Node.js by Florian Rappl(920)
High Performance with Laravel Octane by R. Butti(909)
Kubernetes Design Patterns and Extensions by Onur Yilmaz(899)
Building Data Science Applications with FastAPI by François Voron(881)
JavaScript from Frontend to Backend by Unknown(807)
