Creating custom JavaScript code for various clients

My query pertains to effectively managing and writing client-side (javascript) code for various business rules that vary among multiple clients.

For instance, imagine I have a config.js file where there is a flag determining whether the logic should be executed for Client A or Client B.

Config.js

TestBoolFlag = true;

In my Angular controller, I retrieve data from config.js and use conditional statements to determine if the logic should be applied for Client A or Client B.

Angular controller

var total = 500;

if (TestBoolFlag) {
    var discount = total / 1000 * 100;
} else {
    var discount = total / 10 * 10;
}

This serves as a basic example of the issue at hand.

This method involves managing numerous flags and if-else statements. Is it possible to write javascript code in a better way to accommodate multiple clients' needs?

For instance, could we eliminate this flag and split the if-else statements into two separate javascript files, injecting one based on the client's specifications? Any suggestions would be appreciated.

Answer №1

It is advisable to implement a database for storing client-specific configurations instead of embedding them directly into the source code.

Utilizing this approach will facilitate scalability across multiple clients.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the procedure to reduce my final search result by 1?

When the search is triggered, I want to filter the images by name. However, the issue arises when trying to make everything disappear on filter addition. <ul id="list2"> <li class="in2"> An extra number is added ...

Creating personalized tags or components by utilizing insertAdjacentHTML in Vue

With the use of insertAdjacentHTML, I am able to create HTML elements such as div and span, but it seems that I cannot generate custom tags like <myComponent> </myComponent>. I understand that insertAdjacentHTML can create HTML elements, but a ...

Updating a specific property for each object within an array of objects in MongoDB, and inserting the object if it does not already exist

I am looking for a solution to update a property for each object in an array of objects. If some of the objects do not exist, I want to insert the missing objects instead. Currently, I have been using "upsert", which creates a new document when no documen ...

Determining the variance between two datepickers

I've been attempting to calculate the date difference between two datepickers using JavaScript. Despite looking at other resources, I keep running into issues when trying to multiply the date difference by the price. Can anyone guide me in the right d ...

Tips for Loading an Alternate JavaScript File When the Controller Action Result is Null

My controller action is located in *controller/books_controller.rb* def search_book @found_book = Book.find_by_token(params[:token_no]) # After the book is found, I render the search_book.js.erb file using UJS respond_to do |form ...

Leverage the Google Drive API for the storage of app-specific data

I'm currently developing a JavaScript application that runs on the client side and need to store a JSON object containing configuration details in a Google Drive Appdata file. Through the Google Drive API, I can successfully check for the file within ...

Develop a fresh AngularJS directive that utilizes the HTML5 audio element

Recently delved into Angular and managed to create audio buttons using an Angular directive: app.directive('soundButton', [function () { return { restrict: 'E', link: function (scope, element, attrs) { v ...

issue with jQuery not properly selecting options based on text

I have three select elements in my code, each containing 3 or 4 options. An "Apply All" button is placed on the first file row. When a user selects a sheet name on the first file and clicks the Apply All button, it should automatically select the same she ...

Enable automatic scrolling on a website using jQuery with the option to pause

I'm trying to implement a feature in jQuery where the web page auto-scrolls to a specific point, pauses for a moment, and then continues scrolling. It's like simulating a user scrolling down a page while reading an article - stopping and starting ...

Creating dynamic dropdown lists that automatically apply the active class to the chosen option

Here is the JSTL tags code I am using: <ul class="megamenu skyblue"> <!--1st level of categories --> <c:forEach var="item1" items="${shoppingCart.categories}"> <li id="headerCategory" class="grid" style="border-right: 1px solid # ...

Node.js can be used to easily set the values of HTML elements

After successfully setting up a node.js connection to my mysql database and being able to retrieve and input data using connection.query(), I now want to display the database information on my HTML elements. Is there an equivalent of getElementById for t ...

Guide to displaying the dialogue across the entire application when a button is clicked using React and TypeScript

When clicking on the additem or addbooks button in a React and TypeScript application, I want to display a dialog. The dialog should include a hide button that, when clicked, ensures the dialog will not appear again for the session. Below is the code snip ...

Picture failing to show in browser despite successful upload using node

I am encountering some challenges while attempting to upload images using a node-express server. Two issues have come up. Firstly, the uploaded picture file lacks a proper extension and is given an auto-generated name like 2f22c2502b907f7bf0bc2567c43c801c ...

Navigating to Protected Mobile Platform

I am experiencing an issue with accessing a .NET website with SSL on my Blackberry device. When I try to view the site, I receive the message "HTTP ERROR 403 FORBIDDEN - You're not authorized to view this page. Please try loading a different page". Th ...

Exploring the Inner Workings of setInterval During React Re-Rendering

Struggling to understand how setInterval works in React while creating a countdown timer app. Despite using clearInterval in my code, the timer kept running even when paused with onPause(). let startTimer; const onStart = () => { startT ...

Obtaining the "match" object within a Custom Filter Selector on jQuery version 1.8

Here's a helpful resource on Creating a Custom Filter Selector with jQuery for your reference. A Quick Overview: If you're unfamiliar with jQuery's Custom Filter Selectors, they allow you to extend jQuery’s selector expressions by addi ...

combine two JSON objects

Similar Question: Combining and sorting two json objects I have a pair of JSON objects [ {"name": "Graduation"}, {"name": "Post Graduation"} ] and another one that is identical [ {"name": "first sem"}, {"name": "second sem"}, {"name": "third sem"} ...

Tips for concealing a class within JavaScript

I am looking for a way to hide a specific shipping class for products that qualify for free postmail delivery. Here is the scenario: If a product with the following link: is added to the cart and it belongs to this shipping class: shipping_method_0_adva ...

Setting a variable on the $scope within a directive

I need assistance with a directive: <users-table user="{{ session.user }}"></users-table> The session.user variable is an object that contains various key-value pairs. Please take a look at my directive below: angular.module('app' ...

Problem arises when a recursive function call is nested within a request in an asynchronous setting

Currently, I am working on the task of finding a specific document path by providing its name as an argument. In the fetch_doc_path function, I am making two get requests to retrieve a JSON file containing information about all files. Subsequently, I recur ...