-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from achambers/refactor-all-the-things
Refactoring services to be more sane
- Loading branch information
Showing
22 changed files
with
337 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import LocalClient from 'ember-launch-darkly/services/launch-darkly-client-local'; | ||
|
||
export default LocalClient.extend({ | ||
variation(key) { | ||
return this._super(key, false); | ||
}, | ||
|
||
_config() { | ||
return {}; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import Ember from 'ember'; | ||
|
||
export function withVariation(app, key, value = true) { | ||
let launchDarkly = app.__container__.lookup('service:launch-darkly'); | ||
launchDarkly.variation(key, value); | ||
let client = app.__container__.lookup('service:launch-darkly-client'); | ||
client.setVariation(key, value); | ||
} | ||
|
||
Ember.Test.registerHelper('withVariation', withVariation); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import Service from 'ember-service'; | ||
import getOwner from 'ember-owner/get'; | ||
import RSVP from 'rsvp'; | ||
import Evented from 'ember-evented'; | ||
import { assign } from 'ember-platform'; | ||
|
||
export default Service.extend(Evented, { | ||
_allFlags: null, | ||
_user: null, | ||
|
||
init() { | ||
this._super(...arguments); | ||
|
||
let { localFeatureFlags } = this._config(); | ||
localFeatureFlags = localFeatureFlags || {} | ||
|
||
this._allFlags = localFeatureFlags; | ||
}, | ||
|
||
initialize(user) { | ||
return this.identify(user); | ||
}, | ||
|
||
identify(user) { | ||
this._user = user; | ||
return RSVP.resolve(); | ||
}, | ||
|
||
allFlags() { | ||
return assign({}, this._allFlags); | ||
}, | ||
|
||
variation(key, defaultValue = false) { | ||
if (this._allFlags.hasOwnProperty(key)) { | ||
return this._allFlags[key]; | ||
} | ||
|
||
return defaultValue; | ||
}, | ||
|
||
enable(key) { | ||
this.setVariation(key, true); | ||
}, | ||
|
||
disable(key) { | ||
this.setVariation(key, false); | ||
}, | ||
|
||
setVariation(key, value) { | ||
this._allFlags[key] = value; | ||
this.trigger(key); | ||
}, | ||
|
||
user() { | ||
return this._user; | ||
}, | ||
|
||
_config() { | ||
let appConfig = getOwner(this).resolveRegistration('config:environment'); | ||
let config = appConfig.launchDarkly || {}; | ||
|
||
return assign({}, config); | ||
} | ||
}); |
Oops, something went wrong.