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.