JSFiddle - React, Tailwind, and code Playground
by sanford
JavaScript
var option1 = 1, option2 = 2, option3 = 4, option4 = 8;
var applyrules = function(options) {
var ruled = 0;
for ( var opt in options ) {
ruled |= rules[opt]['if'+options[opt]].turnon;
ruled &= ~rules[opt]['if'+options[opt]].turnoff;
}
return(ruled);
}
var rules = {
option1 : {
iftrue : {turnon:option1, turnoff:0},
iffalse : {turnon:0, turnoff: 0}
},
option2 : {
iftrue : {turnon:option2, turnoff:0},
iffalse : {turnon:0, turnoff: 0}
},
option3 : {
iftrue : {turnon:option3|option2, turnoff:0},
iffalse : {turnon:0, turnoff: 0}
},
option4 : {
iftrue : {turnon:option4, turnoff:option1},
iffalse : {turnon:0, turnoff: 0}
}
}
var someoptions = {
option1 : true,
option2 : false,
option3 : true,
option4 : true
}
if (someoptions.option1)
console.log( 'option1 set in raw options' );
else
console.log( 'option1 not set in raw options' );
if (applyrules(someoptions) & option1 )
console.log( 'option1 set in options after rules applied' );
else
console.log( 'option1 not set in options after rules applied' );