0

I am new to web development. I am a C++ developer. I worked on a project where we were using different graphics libraries. Based on the systems environment variable we decide which library to use. I want this kind of design where we can change Javascript framework based on some settings. As technology is changing very fast Can we design such a way that we can change frameworks used in our web application will easily changeable? Is there any tool which can handle this or a design/architecture we can follow to achieve this.

3
  • Changing a framework? Probably not. I can't think of any two that are compatible. Heck, even different versions of the same framework might be incompatible. So, the only way to do it is have a complete codebase implementation for each framework and then swap which codebase you load. So it's doable but I don't think anybody would or should do it. If you're talking about a library - then perhaps. It depends on what the library does but jQuery can be swapped, for example, and Underscore.js and Lodash are largely interchangeable if you use them with some constraints. Commented Feb 28, 2019 at 12:38
  • Is there any design hack or tool that can work ? Commented Feb 28, 2019 at 12:40
  • Well, in the case of both jQuery and Underscore, they export a global which you use to interact with the library. For jQuery it's $ so you'd do something like $("#someElementId").hide() to hide an element with ID someElementId. You can swap $ to point to a different library with similar API. With Underscore, it exports _ (an underscore) where you do _.map(someArray, x => transformToY(x)) to transform all elements of an array. The Lodash library also exports _ as a global and already provides a compatible API and functionality, so it's usually a drop-in replacement. Commented Feb 28, 2019 at 12:45

1 Answer 1

1

This generally isn't the way JavaScript applications are written. The whole point of the framework is to have a skeleton that you build your code around. This is the fundamental difference between a library and a framework. Libraries (if they are designed well) are interchangeable, and the applications that use them can abstract away that dependency.

Theoretically you could write a new framework that abstracted several other underlying frameworks, but many of them have very different philosophies about how applications should be written. Some are more DOM centric, some are more event-driven, and some are very model-driven. Making something that would encapsulate both something like JQuery and Angular and React would be almost impossible (and certainly larger than any of those frameworks individually).

Finally, part of the value of using a framework is that you can ignore all the bits that they handle for you. When you try and fight those frameworks, and build something independent, they will generally fight you, and make your life miserable. You will spend more time writing wrappers and hacking your way through layers than you ever would just writing your application.

Do yourself a favor, pick a framework, build your app, and throw it away when you decide to switch. It will be far cheaper than trying to abstract over these various systems (plus you can't predict the future, so you will ultimately choose the wrong abstraction anyway).

Sign up to request clarification or add additional context in comments.

1 Comment

Detailed answer this is what is am looking for. Thanks !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.