summaryrefslogtreecommitdiff
path: root/web-ui/app/js/mixins/with_feature_toggle.js
blob: 9f4e3759aba2d0f78064b073e5ff555bbfcb79ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
define(['features'],
  function(features) {

    function withFeatureToggle(componentName, behaviorForFeatureOff) {
      return function() {

        this.around('initialize', _.bind(function(basicInitialize, node, attrs) {
          if(features.isEnabled(componentName)) {
            return basicInitialize(node, attrs);
          }
          else if (behaviorForFeatureOff){
            behaviorForFeatureOff.call(this);

            return this;
          }
        }, this));
      };
    }

    return withFeatureToggle;

});