DEV Community

Cover image for Moving away from ReactJs and VueJs on front-end using Clean Architecture

Moving away from ReactJs and VueJs on front-end using Clean Architecture

Jorge Sánchez Fernández on July 12, 2021

This article is an English translation of the original in my blog: Alejándonos de ReactJs y VueJs en el front end usando Clean Architecture. One o...
Collapse
 
bitclaw profile image
Daniel Chavez

The article title seems a little clickbaity for my taste. Even the Spanish one, same thing. From the title, you gather that the article is about NOT using VueJS/React on the front-end .

Collapse
 
gerostenko profile image
Galina Erostenko

That’s what tricked me into reading this article. 🤷🏻‍♀️

Collapse
 
chuddyjoachim profile image
Joachim Chikezie

Same ☝️.

Thread Thread
 
jwizerd profile image
Jeremiah

I'm so glad I was "click-baited" into reading this article. This article, is one of the best frontend architecture articles I've read in a long time.

Collapse
 
peerreynders profile image
peerreynders

On Using Clean Architecture to Decouple Client Side Architecture from React.js or Vue.js

Similarly: A different approach to frontend architecture

Collapse
 
pvfigueiredo profile image
Paulo Figueiredo

That's true. When I read the title, I thought it was about not using VueJS or ReactJS.

Collapse
 
andersonplima profile image
Anderson P. de Lima

I disagree since "moving away from" is different from "moving away from using".

Collapse
 
ruyili profile image
Ruyi Li • Edited

same, also clicked because of the title. just seems like a translation error though, i don't think the author had any bad intentions.

Collapse
 
aabidsofi profile image
aabidsofi19

i searched for it .. love you for such a beautiful article . gonna skim through your whole blog today :)

Collapse
 
noamgu profile image
noamgu

+1

Collapse
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

I'm joining a meeting and could read few parts so I may come back later but now and just to clarify Angular is a Framework, also it is Vue, but not React or Preact which are Libs, there are so many differences (from the engineering point of view) that is not even ok to try to compare them 😅

A Framework makes you work on the way this framework was conceived while a lib let you choose which parts to use and how, how to structure your project and so on (that's also the reason why React is the TOP1 in loved, used and demanded)

Collapse
 
fabiorizzelloomnia profile image
fabio-rizzello-omnia

Well if you think about it React forces you to write applications in a determined way too.
It's just less opinionated on some topics but still gives you a way to do things, the React way. Just saying the thing you have to pass props, never change props, and component will re-render automatically on changed props(or state) without having to manually tell the component what changed, that's already enough to enforce you a way to develop.
Just because React is less opinionated on things like global storage, router, i18n, forms etc.. It doesn't mean it's not a framework

Collapse
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

But it's not, and it's not my opinion. React and Preact are not framewors and it's a fact. It's like saying Node is a framework or a language when Node is only a javascript runtime environment so in order to speak consistently and concisely, we need to categorise and qualify things like they are.

In computer programming, a software framework is an abstraction in which software, providing generic functionality, can be selectively changed by additional user-written code, thus providing application-specific software. It provides a standard way to build and deploy applications and is a universal, reusable software environment that provides particular functionality as part of a larger software platform to facilitate the development of software applications, products and solutions. Software frameworks may include support programs, compilers, code libraries, toolsets, and application programming interfaces (APIs) that bring together all the different components to enable development of a project or system.

Frameworks have key distinguishing features that separate them from normal libraries:

  • inversion of control: In a framework, unlike in libraries or in standard user applications, the overall program's flow of control is not dictated by the caller, but by the framework. This is usually achieved with the Template Method Pattern.
  • default behaviour: This can be provided with the invariant methods of the Template Method Pattern in an abstract class which is provided by the framework.
  • extensibility: A user can extend the framework – usually by selective overriding – or programmers can add specialized user code to provide specific functionality. This is usually achieved by a hook method in a subclass that overrides a template method in the superclass.
  • non-modifiable framework code: The framework code, in general, is not supposed to be modified, while accepting user-implemented extensions. In other words, users can extend the framework, but cannot modify its code.

By the other hand, a software library is a suite of data and programming code that is used to develop software programs and applications. It is designed to assist both the programmer and the programming language compiler in building and executing software. It generally consists of pre-written code, classes, procedures, scripts, configuration data and more. Typically, a developer might manually add a software library to a program to achieve more functionality or to automate a process without writing code for it.

That being said, from the different options we have for the front-end, i'll pick 5 and they are categorised like this:

  • Angular and Vue are frameworks
  • React and Preact are libs
  • Svelte is a compiler.

Hope it helps you understand the differences :)

Thread Thread
 
rockson_30 profile image
Rockson • Edited

Answering from non-work account
That's a really good answer. Yes even tho React has some sort of DI you can't really say it's extensible

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

When you import a lib just to achieve a goal you usually fit into this approach, otherwise you can either choose another one (and fit into it) or write down your approach and publish it as the new lib to do the same others do but on a different manner, then your lib will need to pass 2 filters:

  1. Community (if it solves a real issue, it does it on a simple (no suggar needed) way, it's buggless, covers all possibilities that any project could need, a medium-big project is built with that as example of capabilities and it's well documented, you can get some fans and stars on github).
  2. Us current engineers, tech leads and so will eventually take a look at it if the community growth enough to find devs who knows that lib or to share with the team to solve a current situation for a new or existing project. If you simply changed the way of doing things by stubbornness instead trying to understand how the things work and why they work this way, it'll simply be ditched off and it'll die along the other hundreds of js libs released every month that does not fit for real solutions.

I can understand your reasons to avoid using a lib or framework "as is" and in the end you can agree with me that is a try to avoid tech debt in a project, not less not more.

Then there reasons that counters this reinvented wheel. If you use react millions of devs out there will be available to work within your project in few hours, if you need higher performance and less included libs, you can simply pick preact and every react dev will be skilled to work with that as well.

If you create your own approach and build a project or even a company with that, the end result is that the world keeps rolling and new tech will appear anyway to solve other problems you don't even know about -yet- or to automate things you didn't even mind -yet- so people will like to use this "latest tech" (We know "latest" mean that it appeared 4-5 or 7 years ago and now it's popular and everyone works with that) so even if you figure out how to trick some dev to work in your company or project, they will eventually fly away to another company at the first sight of working on a non standard dinosaur. This will put you in need to increase the salary for your devs and new hires which is also costly and at this point, the life-cycle of your App will be near the end and needs a tech refresh regardless of your initial effort.

The end questions would be then, Is it worth? what do you prefer?

Thread Thread
 
xurxodev profile image
Jorge Sánchez Fernández

Hi, thanks for your comment.

Everything has advantages and disadvantages but in long-term applications I think it makes more sense to uncouple and in the future it will be appreciated in my experience.

Regards

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇

Bet you don't pay the salaries so! 😁

 
jianwu profile image
jianwu

It's not worth to argue if it's a framework or library? There's no clear boundary. This is also not the main point of this article. This is article is about decoupling your core logic from third party code. No matter you call it a framework or library, so that in case you have to migrate to a different library or framework, you don't have to rewrite all your core logic. For the front end world, it's more important as it evolves so fast. Don't expect something you love today will survive for long time.

Collapse
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

Please, I know we live in an opinionated world where people believe what see in tik-tok and so but IT is a science, thus is well categorised. Before being ignorant in front of everyone and especially after the previous explanation make the simple search "react" in Google and you'll see:

React – A JavaScript library for building user interfaces.

Then search "Angular" and you will be able to read the following:

"Angular is a TypeScript-based free and open-source web application framework led by the Angular Team at Google..."

if your opinion is that React is a framework you must try to reach React devs and ask them to change the category of it's Library.
Maybe they can explain what I tried before on a way you can understand it.

So NO, you cannot use React as a framework because it's not a framework, the same way you cannot use Angular as library because it's not a library.
You cannot use a car to travel from europe to america because it's not a plane the same way you cannot use a plane for your commitment to work because it's not a car, even they are both vehicles.

Collapse
 
itswillt profile image
Will T.

It's a really nice article. However, I'd like to have some complaints/suggestions:

  • I see that most of the code snippets in this article are not indented properly, which makes it really hard to read. They also seem to use 4-space indentation, so they are needlessly longer than necessary.
  • The dependency injection pattern is nice, but it will make it impossible for you to implement code splitting in the future because you've already imported all of the code into the dependency injector.
Collapse
 
tiptronic profile image
Andy Fuchs • Edited

I could not more disagree on spacing. Although it's always a personal preference - I prefer 4-chars spacing, as it makes the code much better readable

Collapse
 
jbigorra profile image
Juan Bigorra

To the people getting triggered because of the "framework vs lib" discussion. Plus some considerations in regards of the article ;)

Both (React and Vuejs) are considered a "Delivery Mechanism" from the clean architecture point of view, so following that idea both fall into the same category, no matter if one is a framework and the other a library. Both are an abstraction on top of the DOM to facilitate building user interfaces. That's one of the important parts of the article together with trying to decouple/extracting important logic from it, so your code doesn't depend on any lib/framework that much. So, discussing if it's a framework or not is a bit pointless in my opinion.

I think one point to discuss is, if taking the time to code like this makes sense ? or at least to this high degree of decoupling. Because part of the idea is that you could easily interchange the delivery mechanism if you needed to. But in real life, how often does this happens? Which company/startup would be successful enough to last that many years where you would be in need of using a different lib/framework?

Don't get me wrong, this approach makes you write more testable code which is always a good thing and definitely is an approach that should/could be used when developing back-end systems, and personally I like it and try to stick to it as much as possible (it will always depend on the team though).

Collapse
 
shnydercom profile image
Jonathan Schneider

Which company/startup would be successful enough to last that many years where you would be in need of using a different lib/framework?

basically any company that's survived not fully digitizing until now - which is a large part of enterprise IT, manufacturing, banks and insurances. Startups are only a fraction of the market for User Interfaces. UIs can go into products facing customers or facing internal users. Internal promoters of a digitization project will easily get their budget turned down if the UI can't survive for a couple of years at least, and that means salvaging as much as possible from past projects

Collapse
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

If you read all the comments about you'll probably find the point on the discussion avobe but I'll expand my boundaries to this one :D

I agree with you that being in need to change the lib/fw for the frontend would take years or decades. I.e. Spring that was released in 2002, Ruby on Rails in 2004, Symfony in 2005 and they are still being used widely. But let's think we've an Angular2 framework and that Google stop maintaining it like they did with tones of tech they released in the past ;)

  • or whatever you want)-

In the matter of discussion we can introduce a workaround used for migrating monoliths into services (front end side) that also fits well for migrating modern frontend stacks.
You simply pick a feature, isolate it, build a new JS app with that -stand alone- and embed it into any element of your current view where you want to show that and connect it to the global state (if any).
Now you have an entire Angular app but a feature is provided with a different new hypothetical lib.

This is usually a bit easier to handle if you've a lib than if you've a framework and by the other hand the major part of logic on the frontend is related to conditional rendering of elements and having a 1st layer of security in the shape of form validation, which is easy to understand, document and replicate elsewhere. On top of that there's the fact of having functionalities write down in JS and picking an hypothetical JS lib for the "new frontend", then you'll be able to simply copy-paste your preferred methods/functions and refactor them with the "current future ES version" if you want to (js is retro compatible so it may not be even a need).

This is also easy with a lib where you call methods and just the ones that this lib provide than migrating a ng-if statement because it will need to be rewritten according to the new framework or lib.

At the end you'll have a good modern "new" application with the current stack, methodologies etc.... part by part, feature by feature, view by view... whatever is better depending on your base architecture (usually with the current stack would probably be component by component).

So it's this kind of decoupling really needed? Isn't it a patch to make the job of the devs more difficult to get in return... almost nothing? Wouldn't be better to design a good architecture from the beginning to make this process described above as easier as possible and nothing more?

Collapse
 
joeschr profile image
JoeSchr

Love it. So rare to see somebody discuss this beyond beginner/intermediate level topics like architecture with frontend UI!

Where were you 3 years ago?! ;)

Collapse
 
xurxodev profile image
Jorge Sánchez Fernández

Thanks!

Collapse
 
vietphamh profile image
Viet Pham • Edited

This is an awesome article to me although the title made me confused a little bit at first. Honestly, I really want to learn more from your mentioned links in it, but they're all in Spanish. I think it would be a great help to the readers who want to learn more about your article if you could help to translate them to English. I'm willing to read them as soon as possible I know them translated.

Once again, thank you for the great job!

Collapse
 
dashcraft profile image
Daniel Ashcraft

Okay, i've tried to think of ways to say this without coming off as harsh. I'm going to give pointed criticism and i promise my intent is not to "bash" you. I'm just going to give my honest take.

The Code

The code is bad, doesn't take advantage of implicit returns, hastily abstracts dependencies, makes decent integration testing fairly cumbersome because of the amount of dependency mocking you'd need to do. All in all, it would literally not pass code review, switch statements in a render function vs a hash map? This would get you paired with a senior for a few hours to fix this mess, it's that bad. It's a huge red flag. Too many code smells.

The Concept

The concept is a reasonable one for the backend where the "state" is usually colocated and composability isn't favored over inheritence. But it's just not great for the frontend. It's not composable, it's not easily maintained, it's not extensible, it's tightly coupled to your dependency setup, it's difficult to read, it's difficult to reason about, it's hard to test and therefore it should literally be avoided like the plague. It might actually be one of the worst architectures i've seen for frontend frameworks, including Anguler 1 (insider joke).

If your component/class isn't readable and you cannot discern what it's attempting to do in a short period of time, or extend it with confidence, in the tests/implementation, that it wouldn't break, it's not the solution to the problem.

This is the hastiest of hasty abstractions. Please never write code like this for the frontend. It's fun to see, but it's definitely not realistic or production worthy.

If this comes off as mean spirited, i promise that's not my intent, i'm trying to approach this in good faith.

Collapse
 
shnydercom profile image
Jonathan Schneider • Edited

Eventually, we are going to be moving away from React and Vue, so the question is how much of your codebase you can throw away then. Anyone remember flash-games, Rich Internet Applications and Silverlight?... 👵🧙

For the business logic part it's clear why you seperate it into the domain, what do you think about separating the UI/UX logic into its own domain as well? I've worked on collecting the most common UI phrases, properties and classes with some documentation and assigning a URL to them. The domains of designers, copy and product owners are more in the daily work of a frontend developer. So for the dev, it's going to be hard to advocate for an architecture that coworkers don't benefit from right then and there.

 
tiptronic profile image
Andy Fuchs

I solve this by using a larger display ;) and I doubt 2-space indentatioin lets you see 'more code on each line' in ~99% of all cases. While 4-space indentation let's you much better see where functions/declarations start/end and what belongs together (no matter how long lines are).

Collapse
 
efpage profile image
Eckehard

Maybe we should take into account that the world is constantly changing. If we look back 10 years, the browser ecosystem has significantly changed, so I think we will see some changes on the framework side too. There are constantly new ideas trending.

A good software architecture should make us some kind of independent to changes of the framework. Otherwise you are constantly rewriting all your code over and over. I´m not sure if this is possible if you use React or Vue? I assume, if some Post-Vue-Framework is trending some day, people will start totally from scratch again.

Collapse
 
reikrom profile image
Rei Krom
Thread Thread
 
rockson_30 profile image
Rockson

That's pretty much what I was saying about React. Tbh I don't really care about the discussion but if you think about it, the while props passing and reactive re-rendering inside React is already a kind of Inversion of control if you think about it.
That's why I said it can be considered a framework at some extend, maybe without betteries included? Less opinionated? Still a framework. But yeah if you compare it to the alternatives it might look less of a framework

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

google.com/search?q=react&rlz=1C1C...

google.com/search?q=angular&rlz=1C...

I'm tired of discussing things that are not suitable for opinions. Things are what they are, not more, not less. I already defined the differences many times here. Both libs and frameworks came to solve the same root concern, it's just the engineering behind and the result, being something devs interact with on a given manner what categorise them to be part of a group or another.

Extrapolation:
Again you can consider that a car is a bike and you could argue that both have wheels, both have an engine, both... but they are in the market to solve different needs, and a bike is a bike and a car is a car even having more similarities than notable differences -leaving the visuals apart- unless you enter into the engineering world.
i.e. if you're driving at 80km/h and you want to turn right you need to turn your steering wheel to the right on a car, while on a bike you'll need to turn your handlebars to the left because some physic laws that are not matter of discussion here.

The differences are enough to avoid some crazy to build a bike with steering wheel and say "hey, it's a car". People would think he's silly or crazy, right? The same happens on any science when people try to give an opinion on things that they don't fully understand.

Thread Thread
 
reikrom profile image
Rei Krom

React could be considered a framework to an extent same way a horse could be considered as an organic car. Or a car could be a mechanical horse. Hotdog can be a sandwich. More about it here => youtube.com/watch?v=O9ak89FwYeI

There are differences between a library and a framework hence vue, angular and react are defined appropriately by the authors.
You could do similar things with both of them, but due to the differences associated by the accepted terminology, your experience will vary.

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇

This is a causal argument that puts the things out of it's own boundaries to deal confusion and intends to take acceptance for the people who don't want to contrast the information. It needs people to blind trust them and the thrust on them are linear according to the similarities that can be abstracted between both groups.

Even the similarities that we can observe on them, let's define the items:

  • Horse: a large plant-eating domesticated mammal with solid hoofs and a flowing mane and tail, used for riding, racing, and to carry and pull loads.
  • Car: a four-wheeled road vehicle that is powered by an engine and is able to carry a small number of people.

A car does not eat plants, also is not a mammal, has no wheels, is not a vehicle (it's currently an animal), not domesticated, it's not powered by engine and so on...

Let's define the items from the video:
Soup: a liquid dish, typically savoury and made by boiling meat, fish, or vegetables etc. in stock or water.
Is cereal any of this? Nope, cereals are grain and are put into milk (not water) without boiling or any other process.

It's a speech that usually seems funny to me, I don't consider causal arguments on other context but comedy. It's something that is not usually used in devs world but take care about politicians doing this to confront people :)

Thread Thread
 
sinisarudan profile image
sinisarudan

please, make your own post about FRM vs LIB. Thanks!
And then if you're still obsessed with it, you can just link it here instead of thrilling the main theme, creating the information overload and making us missing the comments that REALLY ARE connected to the topic.
Sorry for the tone, but I contained myself until reading your 101st comment on the non-topic. Thanks!

 
joelbonetr profile image
JoelBonetR 🥇

The key difference between the Library and Framework related to this article is something known as inversion of control (as I wrote above).

Let's explain inversion of control in detail:

When you import a library such react, you have to call the specific methods or functions of your choice and it's up to you when and where to call the Library, so you are in charge of the flow.

On the other hand, a framework itself makes a call to your code and provide you with some space to write down details. In other words, when using a framework, your framework is in charge of flow.

Having a library and having a framework are completely different levels of coupling just for this reason. If you want to change React with Preact for example you simply change one for another and update your method calls (related to the lib) for the ones of the new lib, test, fix and you're done. You cannot do that with a FrameWork because your code depends on the specific framework flow and way-to-do.

Thread Thread
 
rockson_30 profile image
Rockson • Edited

Don't get me wrong I'm just interested on the subject.
Your argument about being able to replace the calls seems a bit off, I mean Preact emulates exactly the same calls of React, maybe does things differently, but if it there was an Angular "emulator" you would be able to do the same. In Angular you are importing @Component, @Injectable, @Module etc, if you override them you're able to "emulate" Angular behavior as with Preact.
Even in Angular you decide what to import, what to use.
Angular just have more tools, it's batteries included, so they made it possible to extend it and to achieve some common tasks through "configurations". But that's it, it just has more tools by default.

Thread Thread
 
peerreynders profile image
peerreynders • Edited

Your notion of the role of IoC is correct. However not all frameworks are application frameworks.

React is not an application framework but React is a framework.

When you import a library such react, you have to call the specific methods or functions of your choice and it's up to you when and where to call the Library, so you are in charge of the flow.

For a React component to get a chance to call React, React has to call the component first. The only time that isn't the case is in this one line of code:

ReactDOM.render(<App />, document.getElementById("root"));
Enter fullscreen mode Exit fullscreen mode

And even that isn't just a library call - it's the entry point so React can "play the role of the main program in coordinating and sequencing rendering activity" and behave as a framework.

React is a (view component) framework

Your React Components (user code) are always called by React - that is IoC in action - used exactly in the manner of a framework.

Looking into it further - Redux maintainer Mark Erikson astutely observed

… or the way I like to put it:

  • React is your application (component-centric)
  • React is not your application (app-centric)

In Kent C. Dodds's Application State Management with React - React is a state management library largely focuses on the React is your application (component-centric) style.

Given that React is used for state management, React is the backbone and the skeleton of the application and all functionality and capability tends to become deeply coupled with the React-ness of the overall client application. At this point React might as well be your application framework (and many developers use it in this fashion) - the missing bits and pieces are simply pulled in from the React ecosystem and these "pieces" tend to be specific to React (e.g. while other frameworks may offer hook-like services , hooks written for React will likely not work with other frameworks).

I argue that the React is your application (component-centric) style does not scale. It may work for smaller applications and has an attractive time-to-initial-success (TTIS) but due to the inherent internal coupling it may be more difficult to maintain over the long run. In a way the tools that are being used to implement the solution dominate the client architecture rather than the problem that is being solved.

Contrast that with Michel Weststrate's UI As An Afterthought which advocates a React is not your application (app-centric) style:

Initially, design your state, stores, processes as if you were building a CLI, not a web app

most components will be dumb

Here the application is built around the state management solution - Mobx in this particular case - and React's responsibilities are deliberately severely curtailed. Taken to the extreme the client application would eschew integration libraries like react-redux or mobx-react-lite and instead define an application specific adaptor for the React side to access "the application" which then turns around to use whatever state management solution was actually chosen. In terms of the Hexagonal Architecture the application logic lives in the core while both React and the state management tool is on the "outside" being connected to the application logic via adaptors whose interfaces are dictated by the application logic.

Note: the above article is advocating one particular flavour of React is not your application (app-centric).

But even in the case of React is not your application (app-centric) React is still calling the shots as it remains in firm control of the main/UI thread - i.e. the application logic only gets control when React calls a component via IoC. The primary benefit of this style is that it reduces the coupling between React and "the application" (and perhaps even the state management tool).

In effect React is not your application (app-centric) is the modern version of the Segregated DOM a concept which goes back to The Humble Dialog Box.

To wrestle control from React (while still using React) it is necessary to move "the application" into a web worker - example: React + Redux + Comlink = Off-main-thread.

The point is that it actually takes significant work and discipline to avoid React acting as your application's framework.


One issue that tends to rear it's head is that some application capabilities benefit from running on the main/UI thread. One solution is to "actorize" the application. That way it's simple to move the functionality back to the main thread should the need arise:

An actor is essentially a message processor (not an object or a component) which maintains it's own autonomous state. It doesn't share anything and only runs when it has a message to process; it processes any one message as quickly as possible while sending messages to other actors or even spawning new ones.

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇

A lib deals with one or more tasks. React is a group of libraries, take a look at your package.json. In most project there are at least

  • react
  • react-dom
  • react-scripts

and there are more, of course.

If you get a library to control your application flow it will do simply this, and this not means it's a framework.
Have you tried to import only a single lib from react and build the rest by your own on the top of that?

The thing is that you simply can.

In order to get some kinda like an actual framework you need a group of libraries (some has nothing to do with react itself such those for state management).

Here it goes a metaphor:

You can go to a scrapper, put some car parts in the same place on a random position and you can say "I've a car", well, eventually, with some work and using certain patterns and order you'll have a car made of isolated pieces but at the starting point you don't have a car, and depending on what you want to do with those parts and the parts you really need to accomplish your goal, you'll never end up with a car.

Thread Thread
 
peerreynders profile image
peerreynders

If you get a library to control your application flow it will do simply this, and this not means it's a framework.

As I've already cited in my gist:

Martin Fowler: InversionOfControl (2005-Jun-26)

Inversion of Control is a key part of what makes a framework different to a library. A library is essentially a set of functions that you can call, these days usually organized into classes. Each call does some work and returns control to the client.

A framework embodies some abstract design, with more behavior built in. In order to use it you need to insert your behavior into various places in the framework either by subclassing or by plugging in your own classes. The framework's code then calls your code at these points.

The litmus test:

  • If your code calls it, it's a library.
  • If it calls your code, it's a framework.

Your code only starts the DOM renderer - at which point your code gives up control and your components are called by React to specialize the VDOM rendering behaviour - so React is a framework.

When the behaviour of the implementation contradicts the documentation then it's time to disregard the documentation.

Thread Thread
 
rockson_30 profile image
Rockson • Edited

I mean, you can consider react-dom the actual interpreter for react, but anyway we are talking about React as a whole. Of course if you start splitting its pieces it becomes less of a framework. So is angular, if you take a single element from it like the rxstore well its not a framework on his own

Just because the react team decided to separate react and react-dom in two different dependencies and allowed people to write their own "interpreter", it doesn't mean it's not a framework.

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

While Angular is a complete solution (a framework), React only takes care of rendering the view and making sure that the view is in sync with the state. That's all react does, nothing less, nothing more.

If you want React to become a framework (it is not possible by itself as discussed above) you'll need other libs to compose an actual framework-like library compound that matches all the requirements of being considered as a framework, shipped together -and maintained- as a single agnostic set shipped as a base solution where to build new projects on.

@peerreynders the first call to the component is done by you inside a react render function, it's not handled by react out of the box nor even has a default required structure.
You can call componentDidMount() or not (same as other methods), you can call render() without having to call other specific method as requirement, you can define and manage your state at your own way...
You can even create your component inside the same app directory tree that does not fit into react and push it right in between the other components at the time you want (of course without using React), because react is a lib and you enforce the usage of a lib wherever you want and not vice-versa.

If you use react features (rendering the view and making sure that the view is in sync with the state) which are defined and controlled by yourself (with the React API) you simply added reactive functionality to your App using React lib.
If your App is completely based into react way to work it was your architectural decision same that happen when you use Redux -which enforces you to apply Reducer design pattern using functional programming paradigm-, then you can say Redux is a framework but again, it is not, it's intended for state management only and it's a lib.

YouTube:

Thread Thread
 
peerreynders profile image
peerreynders • Edited

That's all react does, nothing less, nothing more.

You are simply making a case that React isn't an application framework. Just because React isn't an application framework isn't evidence that it's just a library.

If you want React to become a framework

When I mean application framework I state application framework. Framework is not synonymous with application framework.

the first call to the component is done by you inside a react render function, it's not handled by react out of the box nor even has a default required structure.

ReactDOM.render(<App />, document.getElementById("root"));
Enter fullscreen mode Exit fullscreen mode

is

ReactDOM.render( 
  React.createElement(App, null), 
  document.getElementById("root")
);
Enter fullscreen mode Exit fullscreen mode

You're handing the component tree over to the React renderer via the name/reference to the function or class that represents the root of your component tree:

React here is the component tree that represents my application, could you please run my application for me …

… exactly like one does for a framework. Given that Preact doesn't have a native renderer it's even clearer

  import { h, render } from 'preact';

  // Create your app
  const app = h('h1', null, 'Hello World!');

  render(app, document.body);
Enter fullscreen mode Exit fullscreen mode

With a library:

  • The application code is primarily run from the JavaScript event loop and the application code calls the library only temporarily relinquishing control to the library. When the library completes its task it returns full control control back to the application without leaving a trace of itself on the call stack, microtask queue or task queue (within reason).

With a framework:

  • The application code is run by the framework. Once the framework is started, it runs until the application finally exits while in the meantime orchestrating most of the application activity.

A React application is run by React - not the JS event loop - React (for the most part) sits between the application and the JS event loop.

By the nature in which it operates React is a framework and not a mere library.

Now some people claim that is doesn't matter whether React is a framework or a library - but it does. Lots of sources claim that React is "unopinionated".

It's less opinionated than Angular but that doesn't mean React is unopinionated. As it operates as a framework it creates considerable design pressure towards the "React is your Application" architectural style (which isn't in your long term interest; I argue that React's pit of success herds you towards this style) - and that is opinionated. Going with a "React is not your Application" style (which this article advocates) is considerably more work largely due to React being opinionated.


If you are using react-redux you are still practicing "React is your Application". To move to "React is not your Application" you would put Redux behind an application specific façade.

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇

"You are simply making a case that React isn't an application framework. Just because React isn't an application framework isn't evidence that it's just a library."
I think I explained all key differences between a framework and a lib already, you can't simply stick to a given implementation or a single key feature and say "hey, this does not fit 100% with the given description/explanation".

The react-dom is a package that provides DOM-specific methods that can be used at the top level of your app and as an escape hatch to get outside of the React model if you need to. Most of your components should not need to use this module.

When you call

ReactDOM.render(, document.getElementById("root"));

Here you are saying, hey ReactDOM, please RENDER this component in this container.

YOU are calling the package method passing the required stuff because you added React-DOM for a specific feature, if you don't like nor want React-DOM approach you can write down your own code instead and use it along with React (which does not include React-DOM by default) or simply avoid using it.
Again is your decision whether to use it, where and how (as long as you use it according to the reference if you do, of course).

You can add more or less packages or libs into an application to extend functionality (that's what a lib does) and define -or not- your app structure depending on a lib or not.

Does this seem like inversion of control to you?

Do you really think it enforces you to do the things on a single way? Even JSX is optional and not required to use React!
You can also wrap an imperative UI into a declarative component, and vice versa.

The control over scheduling would be harder if the user directly compose views with a “push” based paradigm common in some variations of Functional Reactive Programming.

To bring reactive, some popular libraries implement the “push” approach functionality where computations are performed when the new data is available. React, however, sticks to the “pull” approach where computations can be delayed until necessary.

This means that your components (either user-written or platform specific) are declarative functions that returns a description about what needs to be done.
Then you pass this description to React and React will call this component whenever is necessary. It's just a matter of the architecture design behind it.
At the end, you are defining what needs to be done, how and where. React simply adds the when -generically speaking- while you keep the control over the process with some methods such componentDidMount

React is not a generic data processing library. It is a library for building user interfaces.

Whenever you like it or not there need to be a deep understanding of both programming paradigms and design patterns to fully understand that in deep.
Extrapolate a single thing in favour to this counter-culture is just populism that hurt -like any populism does- the community, specially those who can keep this in mind while learning and so having a hard time trying to understand the underlying tech -which is quite good and strict into it's decisions- specially design decisions.

Thread Thread
 
peerreynders profile image
peerreynders

I think I explained all key differences between a framework and a lib already.

You informed me of your opinion and you keep saying "framework" when you actually mean "application framework". While all "application frameworks" are "frameworks" not all "frameworks" are "application frameworks".

The discussion is "library" vs "framework" - not "library" vs "application framework".

you can't simply stick to a given implementation or a single key feature

Sure I can and the TLDNR is (I repeat):

  • If your code calls it, it's a library.
  • If it calls your code, it's a framework.

This is a distillation from Designing Reusable Classes 1988 - 25 years before React:

The framework often plays the role of the main program in coordinating and sequencing application activity.

React calls user components giving them a chance to update component instance state and initiate application activities - ✔.

This inversion of control gives frameworks the power to serve as extensible skeletons. The methods supplied by the user tailor the generic algorithms defined in the framework for a particular application.

React: "The components supplied by the user tailor the generic rendering algorithm in the framework for a particular application" - ✔.

A framework's application specific behavior is usually defined by adding methods to subclasses of one or more of its classes.

React: "A framework's application specific behavior is usually defined by composing components" which themselves are created by:

  • Using createReactClass which "subclasses" an internal React type via a specification object.
  • Extending React.Component explicitly.
  • Or representing a component via a function complying to a type specification (and supplying services like hooks) that can be used to access and mutate an internal React component instance while rendering its state.

So - ✔.

In 2005 (8 years before React) Martin Fowler summarized that as:

  • A library is essentially a set of functions that you can call.
  • The framework's code then calls your code

React components "plug into" React when the component tree is passed to React and React uses that tree for the remainder of the application's runtime to drive all application activity. So - ✔.

Now by this point it's contrasting a library as just a bunch of helper functions (that don't take control of application activities for the remainder of the application session) vs a framework which drives the application's activities for the lifetime of the application session.

The reason that distinction is important is because frameworks (engines of application activity) put a much larger design pressure on solution architecture than libraries. That is the core point of Architecture the Lost Years. The same way all Rails applications "looked all the same" (despite application specialization) back then, many React-based front end solutions "look the same" burying the all important "application-logic" as bits-and-pieces inside them rather than emphasizing and delineating the application-logic through architecture.

Here you are saying, hey ReactDOM, please RENDER this component in this container.

… for the remainder of the application session while the container still exists - that is an important detail. For a library it would just render it once and return - a re-render would require a separate invocation.

Does this seem like inversion of control to you?

Your components are invoked by React - that is IoC in action - React is calling your code when it deems fit.

Do you really think it enforces you to do the things on a single way?

Because React is acting as the driver of application activity it imposes design pressures to write the application in a certain way. Going against those design pressures is going to require additional effort - i.e. it's easier to just give in even if the long term consequences are detrimental (maintainability mostly).

You can also wrap an imperative UI into a declarative component, and vice versa.

It's only declarative in relation to its position in the component tree which is fine if it's just a visual, dumb component - but more often than not React components also absorb application logic and the application-logic has entirely different communication pathways than what the component tree can represent - typically application communication is just kitchen-sinked via Context.

It is a library for building user interfaces.

React drives application activity via it's components - a UI library is driven by the running application, i.e. a UI library is called whenever the UI needs to change.

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

wow wow wow, hold your tights. You are blending different concepts into the same speech. Let's break things down as Uncle bob said in the past.

In the "Architecture, the lost years" he's talking about MVC (which is an architectural design pattern) but let's stay apart from that for a moment would you?

You say I'm talking about application framework, that's correct so let's see which kind of frameworks we can find:

  • Technology Framework
  • Business/Enterprise Framework
  • Application Framework
  • Component Framework

Technology Framework

Provides a standard, generic software foundation.
Java is a technology framework, JavaScript is other technology framework etc


Business/Enterprise Framework

A complete environment for developing and implementing a comprehensive information system. Enterprise frameworks provide pre-built applications, development tools for customising and integrating those applications to existing ones as well as developing new applications.
They may also provide a workflow component.
Frameworks such as ERP and CRM are available for business functions such as order entry, inventory and payroll (Comparison of accounting software), while frameworks exist for specific industries such as health services and insurance.


Application Framework

Is a set of common software routines that provides a foundation structure for developing an application (Explained in detail some comments above with all key features).


Component Framework

In essence, component-frameworks break the system down into variant "components" that represent abstract processing that the system supports. These components are generally thought of as "pluggable" in the sense that the system can be configured with a set of components to accomplish a particular task or set of tasks. In many systems, the components can dynamically swapped in and out. The framework, on the other hand, is the invariant "superstructure" that manages the components, providing services to each component that, when combined with the services/behaviours supplied by that component, create the net behaviour defined by that component in that framework.

The framework has the effect of decoupling or isolating the components from each other since it the component interactions are handled by the framework in a manner that is opaque to the components.
Note that this does not preclude any ability of the components to communicate with each other outside of the confines of the framework, they are only decoupled with respect to their interactions through the framework.

One of the key and arguably, defining, characteristics of a component-framework system is its "inversion of control" or "Hollywood Principle": "Don't call us, we'll call you!" Since the framework portion of the system represents the invariant aspects of the system that mediates the dynamics of the variant components, control of the system must be delegated to the framework because the components are only providing services to the framework and are unaware of how those services interact with each other. In other words, it is the framework that is "running the show", directing the calls to the component services, not the other way around. Inversion of control virtually eliminates flow control in the components and thus reduces code complexity in the components.


Ok now let's talk about IOC (inversion of control).

Inversion of control is a design pattern principle in software design, specially (but not exclusive) Object Oriented software, that helps to keep it -among other things- loosely coupled.

One of the methods of achieving it is through Dependency Injection.

This small example of a pseudo code getting data from a database and displaying it:

// design implementation 1

class MyScreenRenderer {

   constructor() {
       this.dbQuery = new MyDBClass();
   }
   
   const showDataOnScreen = () => {
       Screen.show(this.dbQuery.getMyData());
   }
   
}
// design implementation 2
class MyScreenRendererWithDependencyInjection {

   constructor(dbHandlerInjected) {
       this.dbQuery = dbHandlerInjected
   }
   
   const showDataOnScreen = () => {
       Screen.show(this.dbQuery.getMyData());
   }
   
}

In simple terms, the later class uses Dependency Injection pattern to get a instance of some database handler it needs, but, instead of creating it, and therefore getting coupled with a specific implementation, the instance gets injected into it. This pattern makes possible to our system to change databases freely without having to change the client class.

You can learn more in the great Martin Fowler Article.

Now, in the React components, props, etc, you can apply these concepts in order to make components independent and exchangeable.

The Render Props technique for example, allows you to create a component that gets the data and render it using another component that it knows nothing about, the renderer gets injected into it.

You being able to apply this design pattern principle does not mean that React forces you to apply it. It's your decision in software design but you can simply don't apply those concepts.

Just found this post about Use the Inversion of Control pattern with React, take a look at it, it may help you understand the insights.

Thread Thread
 
fabiorizzelloomnia profile image
fabio-rizzello-omnia • Edited

Angular doesn't force you to use dependency injection too. You can declare an instance, import, and use it. That's with any framework.

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇

yup but Angular is a complete solution that covers all keys for being a framework while react does not.
There's a big difference son something being X and using something as X.
Fresh cheese can be used as salad dressing (adding other things such at least salad) while itself is not a dressing, even further you can add some syrup as dressing for fresh cheese.

That's what I'm trying to say, you can add a bunch of libs together putting React as your top lib and say "hey I got a framework" but react itself does not cover the requirements for being one and even react can be a lib to extend functionality inside another framework.

Thread Thread
 
fabiorizzelloomnia profile image
fabio-rizzello-omnia • Edited

Yes but tbh that looks more like the definition of non opinionated rather than library.
You are kinda comparing React to Angular's View Engine. Yes, Angular's View Engine is not a framework, it's used inside a framework. But when we talk about React we are talking about the combination of react + react-dom. If you take react alone it might be just like Angular's View Engine

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

React brings (optionally) so little list of things that I can even type a short list here:

  • React
  • React.Component
  • ReactDOM
  • ReactDOMServer
  • DOM Elements
  • SyntheticEvent
  • Test Utilities
  • Test Renderer

*From React API Doc


Angular includes many more tools -of course it does, it's an entire framework, a complete solution- that you can check at Angular API Doc


You may notice that React needs third party libs even for routing while as I said many times, Angular is an Application framework which uses components as base paradigm , being a framework means it's a complete solution. They of course can break angular down and ship separate libs as optional, but they didn't, they choose to offer a complete framework while React team decided to offer a lib which solves specific needs standardising them for anyone who uses React, maintaining it on it's little scope, instead going further and adding all the things that React currently lacks for being a framework.

Thread Thread
 
fabiorizzelloomnia profile image
fabio-rizzello-omnia • Edited

Yes but still, that's not the definition of a framework
Having many tools != Being a Framework
Having only 1 way to do things != Being a framework

"Being a framework means it's a complete solution"
Well, we might need to define "complete solution" here. Who said that a global store, http routing, animations etc... are mandatory for A framework?

As said before by others, being an application framework is a different thing.
If you want an application framework there are many in React land like nextjs and gatsby.

Still, nextjs that is labeled as an application framework doesn't have tools that angular has like animations, http, localization etc.
Nobody ever specified which tools you need to be an application framework.

Tbh I feel like the word framework is being misused everywhere these days, as if being a framework means:

  1. being opinionated
  2. having batteries included

But that's not the case, not every framework is like that

The only valid point i've seen for being framework is:
it calls you, so it's a framework

And that's the case of react + reactdom

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇

whatever man, send an email to React team with your complains to see if they change its own description. I can explain things for the community but this became a fight with your stubbornness instead.

Thread Thread
 
fabiorizzelloomnia profile image
fabio-rizzello-omnia • Edited

Looks like community doesn't agree with you either.
"send an email to React team with your complains to see if they change its own description"
Just because others say something, it doesn't mean it's true :D Not even creators

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

You stick to a single key feature that is IOC, after demonstrating that you can get IOC or not with react -depending on the implementation- then you say something about angular.
Read this again and do a checklist point per point and you'll end up with the same conclusion.

React is great not being a framework because it is so minimal and deals with so little that a developer will have to learn JavaScript anyway to deal with bigger problems that React JS cannot solve.

If you want to know more, please, ask Google "Why React is not a framework" and you can start a war on any place that you feel like with the same vague arguments.

You can start here for example.

Thread Thread
 
peerreynders profile image
peerreynders • Edited

In the "Architecture, the lost years" he's talking about MVC (which is an architectural design pattern)

If you had actually watched the video rather than just glanced at the thumbnail you would have realized that MVC was only a minor aside around 29:00 and that he considers MVC a design pattern

MVC is not an architecture

and that he really doesn't like Web MVC.

Aside: MVC: misunderstood for 37 years

He's at a Ruby conference and he's talking about how Rails applications in general don't have an architecture that clearly manifests the nature of the application being implemented other than that they're implemented with Rails.

Similarly many React applications have a "same-ish" structure without a clear demarcation where the UI ends and the application(-logic) begins.

In 2011 SPAs weren't commonplace so client-side architecture wasn't a discussion point (though Martin Fowler brought up Segregated DOM in 2014).

In Make the Magic go away Robert C. Martin even calls rxJava (ReactiveX) a framework which most people would classify as a library. However going "all in" with RX has a framework-like effect on solution architecture.

so let's see which kind of frameworks we can find

Wrong frame.
What are the characteristics that most if not all frameworks share? The key one in Johnson and Foote:

The framework often plays the role of the main program in coordinating and sequencing application activity.

React is invoking your components for the lifetime of the application session so as far as your components are concerned React is their "main program". And the way many if not most React components are authored - i.e. components include a fragment of the application logic - React becomes the "main program" for the entire application.

That being said, lets look at your "Component Framework" write up:

These components are generally thought of as "pluggable" in the sense that the system can be configured with a set of components to accomplish a particular task or set of tasks.

Your React components plug into React

  • to render markup in a way that is specific to your application
  • to trigger application activities, which in turn may modify component instance state causing React to schedule them for re-render.

The framework, on the other hand, is the invariant "superstructure" that manages the components, providing services to each component that, when combined with the services/behaviours supplied by that component, create the net behaviour defined by that component in that framework.

React definitely manages React components, delivers events to the component instances via its synthetic event system, delivers props from owner component instances to the nested component, renders the DOM on behalf of the component based the generated ReactNode (a framework specific type) and provides application infrastructure like Context - all of which can be considered services for the components and all for the purpose of rendering the UI and running the application activities.

type ReactNode = ReactChild | ReactFragment | ReactPortal | boolean | null | undefined;
Enter fullscreen mode Exit fullscreen mode

The framework has the effect of decoupling or isolating the components from each other since it the component interactions are handled by the framework in a manner that is opaque to the components.

React components don't interact directly with one another. All interactions go through React facilitated by the ReactNode objects generated by the components.

In other words, it is the framework that is "running the show", directing the calls to the component services, not the other way around.

That's React. Calls the component to get the rendered ReactNode and to schedule the application effects.

Also "Hollywood Principle":

"Don't call us, we'll call you"_

Relevant when you are writing a class/component that must fit into the constraints of an existing framework. You implement the interfaces, you get registered. You get called when the time is right.

This requires a distinctly different way of thinking from that which is taught in introductory programming where the student dictates the flow of control.

That pretty much describes React components.

So React is a component framework.

Hence the title of my gist : React is a (view component) framework.

Now, in the React components, props, etc, you can apply these concepts in order to make components independent and exchangeable.

The objective of dependency-injecting a database is to treat the database as an implementation detail. What persistence storage product is ultimately used should not affect your application's ability to function.

Your UI layout and behaviour on the other hand is specific to the needs your application - and ideally it's the UI technology (e.g. React) that you want to treat as an implementation detail, so it's React that you want to be exchangeable. Given that isn't possible, the standard tactic is to make the UI as dumb as possible (The Humble Dialog Box) and inject the whole UI as a single plugin into the application. That isn't what typically happens with React applications - typically the application is injected into React via the component tree.

The "component exchange-ability" argument is largely associated with the component reuse and replace-ability objective which is an entirely different goal. And you have to specifically design for components to adhere to a specific interface (what props, which context) to be independent and exchangeable so that isn't a by default feature, you have to put in some extra effort in for that to happen. And after all that it's still only reusable within React.

You can learn more in the great Martin Fowler Article.

Read it many times since its publication in 2004. The component tree is injected into React before anything else can happen - so React is in control.

The Render Props technique for example, allows you to create a component that gets the data and render it using another component that it knows nothing about, the renderer gets injected into it

And it has never occurred to you that it's kind of strange that a "UI library" needs support for non-visual components? You are injecting parts of the application into the UI. This is just further evidence that React is a framework.

it may help you understand the insights.

The first thing that I notice is that it's React-centric. Other than that nothing new.

And that may point to the underlying problem - in the mind of some people React is the center of the universe because React is the center of their applications.

To properly decouple the application from React it better look something like:

import { h, render } from 'preact';
import { UI } from './components/ui.jsx';
import { Shop } from './components/shop.js';
import { makeShop } from './app/shop.js';

const shop = (() => {
  const client = {
    getBooks: () => fetch('/books.json').then(response => response.json())
  };

  return makeShop(client);
})();

render(
  <App />,
  document.getElementById('root')
);

function App(_props) {
  return (
    <Shop.Provider value={ shop }>
      <UI />
    </Shop.Provider>
  );
}
Enter fullscreen mode Exit fullscreen mode

that is, your components access nothing but React or the shop application object to get the job done.

"hey I got a framework" but react itself does not cover the requirements for being one and even react can be a lib to extend functionality inside another framework.

And again you're talking about an "application framework".

send an email to React team with your complains to see if they change its own description

After 8 years they are not going to change anything.

Best guess: "JavaScript library" is being treated as a marketing (propaganda) term:

  • So that people don't have false expectations of a "batteries included" solution like Angular.
  • So that people buy into the whole "so simple, React can be learned in a weekend" meme.

You can start here for example.

That article is irrelevant as it commits the same mistake of equating "framework" with "application framework" (perhaps even a case of false equivalence) as the author does not convey an understanding of the fundamental characteristics of a general framework (vs library) that were established long before React was authored.

The distinction is important because IoC used by frameworks to run user code impacts how you structure an application - often not in a good way. If you're comfortable re-writing your client-side apps every two years or so or start to look for another job then you won't have to bear the consequences of not countering the bias that React can introduce into an application (i.e. React is opinionated - in its own way).

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

Yeah ok, watever. TLDR.
All people is wrong but you.
This is my last answer to this thread, sincerely, you make all of us loosing time from a biased pov or misunderstanding of concepts.

I let you this link from a person I appreciate within the industry for his way of explaining things describing just that concepts.

Thread Thread
 
peerreynders profile image
peerreynders

Please listen to your own advice.

Thread Thread
 
fabiorizzelloomnia profile image
fabio-rizzello-omnia

Best guess: "JavaScript library" is being treated as a marketing (propaganda) term:
So that people don't have false expectations of a "batteries included" solution like Angular.
So that people buy into the whole "so simple, React can be learned in a weekend" meme.

Exactly

Collapse
 
olegkusov profile image
Oleg Kusov

The idea is good. Thank you! It’s really first time when I see so decoupled from frameworks and libs domain logic

 
joelbonetr profile image
JoelBonetR 🥇

Show us how, write an article and share with the community for it to be peer reviewed then

Collapse
 
bretgeek profile image
bretgeek

I wanted something easier to work with than the big 3 so I created my own and wrote about it here:

dev.to/bretgeek/vibejs-a-small-jav...

Maybe someone out there will find interest in it:)

Collapse
 
ozzythegiant profile image
Oziel Perez

Correct me if I'm wrong but one particular downside I'm noticing from this is that if you write your components to use a state from a store or from some type of provider, now the component is coupled to that feature. Almost all your components should be written in such a way that they don't depend on anything. Only a top level component such as a page or template should handle fetching/changing state or retrieval of API data, but at the same time, ensure that you don't have too deep of a component tree that you need to pass state several levels down

Collapse
 
xurxodev profile image
Jorge Sánchez Fernández

Hi, thanks for your comment.

I think creating an agnostic of the app state component only has sense if this one is used in several contexts.

For example for a library of components as a table with advanced functionalities that will be used in several apps or a dropdown used in multiple places in your app.

But components (pages or not pages) used in a unique context I think that is not a problem.

Regards

Collapse
 
scorpion231954 profile image
Scorpion

Hello,
Can you help me?
After the [yarn install], the [yarn test] is stopped with:
src/app/test/App.test.tsx
● Test suite failed to run
Cannot find module '@frontend-clean-architecture/core' from 'src/app/App.tsx'
...

3 | import { CartPloc, dependenciesLocator } from "@frontend-clean-architecture/core";
...
at Resolver.resolveModule (../../node_modules/jest-resolve/build/index.js:306:11)
at Object. (src/app/App.tsx:3:1)
The [yarn workspaces info] is OK.
Thank you,
Claude

Collapse
 
prototowb profile image
Tobias Rauer

But we all can agree that Vue and React are no UI frameworks, right? I am really not sure where this is coming from and why some people talk about them in this way.

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

As you can see from my comments above where I explained the difference between a lib and a framework I agree with you.

I think the reason is that many people in this platform are self-taught developers. Being self-taught means you only put attention and time to what you like most. Yo don't have to pass a networking or software engineering exam and if there's no one that puts you in the right direction... you'll learn "how to" do things with this "language/library/framework" because seeing things finished boosts your motivation so you ditch off the rest.

Of course an individual with this mindset hardly will do other thing than a "technician" work on a third-rate company or fighting in the freelance market for an average salary but there's always people that really want to learn more...
So I'm trying hard since long time ago defining things by what they are and make deeply tutorials/articles for all to get more than a surface knowledge and I hope it help someone :D

Collapse
 
sinisarudan profile image
sinisarudan

please, make your own post about FRM vs LIB. Thanks!
And then if you're still obsessed with it, you can just link it here instead of thrilling the main theme, creating the information overload and making us missing the comments that REALLY ARE connected to the topic.
Sorry for the tone, but I contained myself until reading your 101st comment on the non-topic. Thanks!

Collapse
 
jumika profile image
jumika

This is exactly what was looming in my head since i've dived into professional frontend development. Thanks for putting it into words.

Collapse
 
petitkriket profile image
Sam

Not sure it scales well in a codebase maintained by a team/company. It's like asking to team mate to learn an extra layer of abstraction that fits over vue ?
Interesting, thanks for sharing !

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

You can decouple logic from react components without adding layers of abstraction other than the ones you'll get by default -usually- i.e. with HOCs (High Order Components) can be used for more things than just to increment New functionalities for other components. With HOCs you can actually separate responsibilities too.
You can create a HOC that accepts a React component as an argument, implements the data logic, and passes data, loading, and error as props into the wrapped React component.
This way your data and/or logic is decoupled from the UI.

Collapse
 
peerreynders profile image
peerreynders • Edited

It's like asking to team mate to learn an extra layer of abstraction that fits over vue ?

Perhaps the Clean Architecture ceremony is getting in the way of the core message here.

Clean Architecture is a moniker created by Robert C. Martin as an elaboration of Alistair Cockburn's Hexagonal Architecture and as such he is a proponent of keeping frameworks at arm's length. His talk Architecture the Lost Years is relevant here as he critizes frameworks (in this case Rails) for interfering with effective solution architecture (Bring clarity to your monolith with Bounded Contexts tries to address this).

In UI As An Afterthough Michel Weststrate boils it down to one core idea:

Initially, design your state, stores, processes as if you were building a CLI, not a web app.

So while his client side application is clearly a React application he can test the client side application logic without the UI (React):

A different approach to frontend architecture also demonstrates this approach by using an application specific interface instead of letting the UI bind to the stores directly.

Collapse
 
mohamed_galal_a4f1eec42dc profile image
Mohamed Galal

Thank you for this informative article. I have a question, please explain how to handle routing in a different application ? is it responsible of react, vue, or whatever ui lib or framework ? as an example handle login scenario when user login success I should redirect him to main page.

thanks in advance

Collapse
 
luiz0x29a profile image
Real AI

React is not a framework, it is just a Render library, it doesn't even manage state, a framework would do that.

Thread Thread
 
rockson_30 profile image
Rockson • Edited

It manages state. And anyway, managing state is not a requirement for being a framework. It's all about inversion of control out of the box

Collapse
 
ashkanmohammadi profile image
Amohammadi2

Thanks for your wonderful article. You saved me a precious amount of time

Collapse
 
luiz0x29a profile image
Real AI

The good old Onion layer architecture.

Collapse
 
sorindezzy profile image
Raita Dezideriu

Fabio React is in no anyways a Framework take that out from your mind, who teached you that ? All The World knows that React is a Blody Library. Read well The React Documentation

Collapse
 
xamian profile image
Xamian

So they say it is a library? I will say good luck extending a vue or angular application with react. Possible? Probably. Good idea? I do not think so. Call React whatever you like, it will always be used AS a framework

Collapse
 
webjoyable profile image
webjoyable

Clickbait

Collapse
 
chibuokemj profile image
Chibuokem Jerry

I like this and I think it's cool, however the amount of verbose code that has to be introduced in order to achieve this level of decoupling troubles me a bit

Collapse
 
shaalanmarwan profile image
Shaalan Marwan

Thanks for this article it was very helpful .i just and wondering if you will translate your other react articles

Collapse
 
znar profile image
znar

Hi, thanks, greate article.
can there be nested Plocs?