Skip to content

Instantly share code, notes, and snippets.

@aaronj1335
Last active December 26, 2015 18:59
Show Gist options
  • Select an option

  • Save aaronj1335/7198616 to your computer and use it in GitHub Desktop.

Select an option

Save aaronj1335/7198616 to your computer and use it in GitHub Desktop.
my proposal for implementing feature flags client-side based on hard-coding a role (we could do a group too, i just used role because it was easy to show the idea).
define([
'feature-flags'
], function(feature) {
// .. instantiate the view and all of that
feature.promise().then(function() {
path.map(url).to(function() {
if (feature.flags.dashboard)
view.show();
});
});
});
define([
// this is currently the 'config/feature-flags.json' file,
// and it would be something like `{production: true, staging: false}`
'json!environment.json'
], function(environment) {
var productRole = '4e6fa6187a475eefd68fb5f8';
var object = {
// this is what the widgets will use to access the flags
flags: null,
// deferring this makes it possible to involve an api call in the future
promise: $.Deferred().then(function(flags) {
// also export the flags to the viewmodel so view's templates can bind to them
object.flags = viewmodel.features = flags;
}).resolve({
dashboard: !environment.production || waterfall.authenticate.role === productRole;
}).promise();
};
return object;
});
define([
'./../three-widget',
'feature-flags'
], function(ThreeWidget, feature) {
var mapping = {
defaults: {
flags: {
dashboard: false
}
}
};
$.widget('msgme_navbar', ThreeWidget, {
_create: function() {
// assume that the caller loaded the flags before instantiating this
mapping.defaults.flags = feature.flags;
ThreeWidget.prototype._create.apply(this, arguments);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment