I'd like to add some "feature toggling mechanism" to my Vue application. While I have implemented a rather basic setup, I'd like to consider the techniques described in this article by Pete Hodgson. Especially the aspect "Inversion of Decision" looks meaningful but I'm struggling to get an idea of how to adapt this to my Vue application.
This is what I have so far.
config.js
const yn = require("yn");
const config = {
// Add new feature toggles here
features: {
myFeature: parse(
window.myaEnv.myFeature || process.env.VUE_APP_MY_FEATURE,
false
),
},
};
function parse(value, fallback) {
if (typeof value === "undefined") {
return fallback;
}
switch (typeof fallback) {
case "boolean":
return yn(value);
case "number":
return value ? JSON.parse(value) : fallback;
default:
return value;
}
}
function feature(name) {
return config.features[name];
}
export { config };
export default {
install(Vue) {
Vue.appConfig = config;
Vue.feature = feature;
Vue.prototype.$appConfig = config;
Vue.prototype.$feature = feature;
},
};
Then in e.g. a component I toggle the visibility like this:
b-button(v-if="this.$feature('myFeature')") I'm visible only if feature is enabled
While this is a very basic example I can imagine that feature toggles might become more complex to handle like this.
How to apply the described feature toggle techniques?