All frameworks allow developers to use domain-specific languages (DSLs) in order to build web applications. DSLs can't be read by the browser directly; they must be transformed into JavaScript or HTML first using Transformation tools. However, framework tooling generally includes the required tools to handle this step, or can be adjusted to include this step. When embracing DSLs, it would be easier to find help from the communities around those frameworks
Example of JSX syntax as the DSL of ReactJS framework
The curly braces around subject on line 4 tell the application to read the value of the subject constant and insert it into our h1
Render a specific component (which will probably be inside another component) by giving it their props
<AuthorCredit
src="./assets/zelda.png"
alt="Portrait of Zelda Schiff"
byline="Zelda Schiff is editor-in-chief of the Library Times."
/>
When ultimately rendered by the browser, the above snippet will produce HTML that looks like this
<figure>
<img
src="assets/zelda.png"
alt="Portrait of Zelda Schiff"
>
<figcaption>
Zelda Schiff is editor-in-chief of the Library Times.
</figcaption>
</figure>
State
A robust state-handling mechanism is key to an effective framework
Each component may have data that needs its state controlled
This state will persist in some way as long as the component is in use
Use useState Hook to give an initial data value, will keep track of that value as it is updated
Use an entirely different language and have it transformed into a web-compatible language
Sass/SCSS: This CSS extension allows developers to use variables, nested rules, mixins, functions, and many other features, some of which are available in native CSS (such as variables), and some of which aren't.
Write code using the latest language features and have that transformed into code that works on everyday devices
PostCSS: Transpile the CSS stylesheets. If there isn’t an equivalent way to do something using older CSS features, PostCSS will install a JavaScript polyfill to emulate the CSS effect.
Use UI-libraries for frameworks
TailwindCSS, Material UI, Chakra UI, etc: Provide ready-to-use components for frameworks
2.4 Handling dependencies
Handling dependencies <=> using components inside other components
Components tend to import components into other components using the standard JavaScript module syntax
Our App component has data that our AuthorCredit component needs --> we need to pass the props down from the App --> Home --> Article in order to use the props in the AuthorCredit. The problem of passing data through many layers of components is called prop drilling
Frameworks provide functionality known as dependency injection, which is a way to get certain data directly to the components that need it, without passing it through intervening levels.
ReactJS has ContextAPI, Angular calls this as dependency injection, Vue has provide() and inject() component methods
2. Framework main features
Reference: Framework main features
2.1 Domain-specific languages
All frameworks allow developers to use domain-specific languages (DSLs) in order to build web applications. DSLs can't be read by the browser directly; they must be transformed into JavaScript or HTML first using Transformation tools. However, framework tooling generally includes the required tools to handle this step, or can be adjusted to include this step. When embracing DSLs, it would be easier to find help from the communities around those frameworks
Example of
JSX
syntax as theDSL
ofReactJS
frameworkh1
2.2 Writing components
Most frameworks have some kind of component model. Each framework's components offer a way to describe
properties
they may needstate
that the component should manageevents
a user can trigger on the component's markupExample of writing a Component with props, states and events using
ReactJS
frameworkProperties
Properties, or
props
, are external data that a component needs in order to render.State
useState
Hook to give an initial data value, will keep track of that value as it is updatedEvent
onClick
event, then use theuseState
hook to create thesetCount
function to update the statecount
2.3 Styling components
Use an entirely different language and have it transformed into a web-compatible language
Sass/SCSS
: This CSS extension allows developers to use variables, nested rules, mixins, functions, and many other features, some of which are available in native CSS (such as variables), and some of which aren't.Write code using the latest language features and have that transformed into code that works on everyday devices
PostCSS
: Transpile the CSS stylesheets. If there isn’t an equivalent way to do something using older CSS features, PostCSS will install a JavaScript polyfill to emulate the CSS effect.Use UI-libraries for frameworks
TailwindCSS
,Material UI
,Chakra UI
, etc: Provide ready-to-use components for frameworks2.4 Handling dependencies
Dependency injection
App
component has data that ourAuthorCredit
component needs --> we need to pass the props down from the App --> Home --> Article in order to use the props in the AuthorCredit. The problem of passing data through many layers of components is called prop drillingContextAPI
, Angular calls this asdependency injection
, Vue hasprovide() and inject()
component methodsLifeCycle
2.5 Rendering Elements
Document Object Model (DOM)
Virtual DOM