Skip to content

Commit 6ada4bb

Browse files
authored
Merge pull request #148 from optimizely/removeFeatureToggleNote
(chore):remove feature toggle notification
2 parents 25415e7 + 22e4fc6 commit 6ada4bb

File tree

6 files changed

+6
-117
lines changed

6 files changed

+6
-117
lines changed

DemoSwiftApp/AppDelegate.swift

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
7777
print("Datafile changed")
7878
#endif
7979
}
80-
})
81-
82-
_ = optimizely?.notificationCenter.addFeatureFlagRolloutChangeListener(featureListener: { (featurekey, toggle) in
83-
DispatchQueue.main.async {
84-
#if os(iOS)
85-
let alert = UIAlertView(title: "Feature flag \(featurekey) changed", message: "toggled to \(toggle)", delegate: nil, cancelButtonTitle: "cancel")
86-
alert.show()
87-
#else
88-
print("Feature flag \(featurekey) changed toggled to \(toggle)")
89-
#endif
90-
if let controller = self.window?.rootViewController as? VariationViewController {
91-
//controller.showCoupon = toggle == FeatureFlagToggle.on ? true : false;
92-
if let showCoupon = try? self.optimizely?.isFeatureEnabled(featureKey: "show_coupon", userId: self.userId) {
93-
controller.showCoupon = showCoupon
94-
}
95-
80+
if let controller = self.window?.rootViewController as? VariationViewController {
81+
//controller.showCoupon = toggle == FeatureFlagToggle.on ? true : false;
82+
if let showCoupon = try? self.optimizely?.isFeatureEnabled(featureKey: "show_coupon", userId: self.userId) {
83+
controller.showCoupon = showCoupon
9684
}
85+
9786
}
98-
9987
})
100-
88+
10189
_ = optimizely?.notificationCenter.addActivateNotificationListener(activateListener: { (experiment, userId, attributes, variation, event) in
10290
print("got activate notification")
10391
})

DemoSwiftApp/Customization/CustomNotificationCenter.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import Optimizely
1111

1212
class CustomNotificationCenter: OPTNotificationCenter {
1313

14-
func addFeatureFlagRolloutChangeListener(featureListener: @escaping FeatureFlagRolloutChangeListener) -> Int? {
15-
return nil
16-
}
17-
1814
var notificationId: Int
1915

2016
required init() {

OptimizelySDK/Implementation/DefaultNotificationCenter.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,6 @@ public class DefaultNotificationCenter : OPTNotificationCenter {
120120
return incrementNotificationId()
121121
}
122122

123-
public func addFeatureFlagRolloutChangeListener(featureListener: @escaping FeatureFlagRolloutChangeListener) -> Int? {
124-
notificationListeners[notificationId] = (NotificationType.FeatureFlagRolloutToggle.rawValue, { (args:Any...) in
125-
guard let myArgs = args[0] as? [Any?] else {
126-
return
127-
}
128-
if myArgs.count < 2 {
129-
return
130-
}
131-
if let featureKey = myArgs[0] as? String, let toogle = myArgs[1] as? FeatureFlagToggle {
132-
featureListener(featureKey, toogle)
133-
}
134-
})
135-
136-
return incrementNotificationId()
137-
}
138-
139-
140123
public func removeNotificationListener(notificationId: Int) {
141124
self.notificationListeners.removeValue(forKey: notificationId)
142125
}

OptimizelySDK/Optimizely/OptimizelyManager.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ open class OptimizelyManager: NSObject {
153153
// new datafile came in...
154154
self.reInitLock.wait(); defer { self.reInitLock.signal() }
155155
if let config = try? ProjectConfig(datafile: data) {
156-
var featureToggleNotifications:[String:FeatureFlagToggle] = self.getFeatureFlagChanges(newConfig:config)
157156

158157
do {
159158
self.config = config
@@ -170,9 +169,6 @@ open class OptimizelyManager: NSObject {
170169
self.notificationCenter.sendNotifications(type:
171170
NotificationType.DatafileChange.rawValue, args: [data])
172171

173-
for notify in featureToggleNotifications.keys {
174-
self.notificationCenter.sendNotifications(type: NotificationType.FeatureFlagRolloutToggle.rawValue, args: [notify, featureToggleNotifications[notify]])
175-
}
176172
}
177173
}
178174

@@ -187,26 +183,6 @@ open class OptimizelyManager: NSObject {
187183
}
188184
}
189185

190-
func getFeatureFlagChanges(newConfig:ProjectConfig) -> [String:FeatureFlagToggle] {
191-
var featureToggleNotifications:[String:FeatureFlagToggle] =
192-
[String:FeatureFlagToggle]()
193-
194-
if let config = self.config, let featureFlags = config.project?.featureFlags {
195-
for feature in featureFlags {
196-
if let experiment = config.getRollout(id: feature.rolloutId)?.experiments.filter(
197-
{$0.layerId == feature.rolloutId}).first,
198-
let newExperiment = newConfig.getRollout(id: feature.rolloutId)?.experiments.filter(
199-
{$0.layerId == feature.rolloutId}).first,
200-
experiment.status != newExperiment.status {
201-
// call rollout change with status changed.
202-
featureToggleNotifications[feature.key] = newExperiment.status == .running ? FeatureFlagToggle.on : FeatureFlagToggle.off
203-
}
204-
}
205-
}
206-
207-
return featureToggleNotifications
208-
}
209-
210186
func fetchDatafileBackground(completion: ((OptimizelyResult<Data>) -> Void)?=nil) {
211187

212188
// TODO: fix downloadDatafile to throw OptimizelyError

OptimizelySDK/OptimizelyTests/OptimizelyTests-Common/NotificationCenterTests.swift

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ class NotificationCenterTests: XCTestCase {
6565

6666
}
6767

68-
func sendFeatureFlagToggle() {
69-
notificationCenter.sendNotifications(type: NotificationType.FeatureFlagRolloutToggle.rawValue, args: ["featureFlagKey", FeatureFlagToggle.on])
70-
71-
}
72-
7368
func testNotificationCenterAddRemoveActivate() {
7469
// This is an example of a functional test case.
7570
// Use XCTAssert and related functions to verify your tests produce the correct results.
@@ -206,40 +201,6 @@ class NotificationCenterTests: XCTestCase {
206201
XCTAssertTrue(called)
207202
}
208203

209-
func testNotificationCenterAddRemoveFeatureFlagChange() {
210-
// This is an example of a functional test case.
211-
// Use XCTAssert and related functions to verify your tests produce the correct results.
212-
var called = false
213-
214-
let _ = notificationCenter.addFeatureFlagRolloutChangeListener { (featureKey, toggle) in
215-
called = true
216-
}
217-
218-
notificationCenter.clearNotificationListeners(type: .FeatureFlagRolloutToggle)
219-
220-
sendFeatureFlagToggle()
221-
222-
XCTAssertFalse(called)
223-
224-
let id = notificationCenter.addFeatureFlagRolloutChangeListener { (featureKey, toggle) in
225-
called = true
226-
}
227-
228-
notificationCenter.removeNotificationListener(notificationId: id!)
229-
230-
sendFeatureFlagToggle()
231-
232-
XCTAssertFalse(called)
233-
234-
let _ = notificationCenter.addFeatureFlagRolloutChangeListener { (featureKey, toggle) in
235-
called = true
236-
}
237-
238-
sendFeatureFlagToggle()
239-
240-
XCTAssertTrue(called)
241-
}
242-
243204
func testPerformanceExample() {
244205
// This is an example of a performance test case.
245206
self.measure {

OptimizelySDK/Protocols/OPTNotificationCenter.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,9 @@ public enum NotificationType : Int {
2121
case Activate = 1
2222
case Track
2323
case DatafileChange
24-
case FeatureFlagRolloutToggle
2524
case Decision
2625
}
2726

28-
public enum FeatureFlagToggle {
29-
case on
30-
case off
31-
}
32-
3327
// TODO: fix this
3428
// - temporary public data types to avoid {OPTExperiment, OPTVariation}
3529
public typealias OptimizelyExperimentData = [String: Any]
@@ -46,8 +40,6 @@ public typealias DecisionListener = (_ type:String, _ userId:String, _ attribute
4640

4741
public typealias DatafileChangeListener = (_ datafile:Data) -> Void
4842

49-
public typealias FeatureFlagRolloutChangeListener = (_ featureFlagKey:String, _ toggle:FeatureFlagToggle ) -> Void
50-
5143
public protocol OPTNotificationCenter {
5244
init()
5345

@@ -89,13 +81,6 @@ func addDecisionNotificationListener(decisionListener:@escaping DecisionListener
8981
*/
9082
func addDatafileChangeNotificationListener(datafileListener:@escaping DatafileChangeListener) -> Int?
9183

92-
/**
93-
Add a feature flag rollout toggle listener.
94-
- Parameter featureListener: Notification to add.
95-
- Returns: the notification id used to remove the notification. It is greater than 0 on success.
96-
*/
97-
func addFeatureFlagRolloutChangeListener(featureListener:@escaping FeatureFlagRolloutChangeListener) -> Int?
98-
9984
/**
10085
Remove the notification listener based on the notificationId passed back from addNotification.
10186
- Parameter notificationId: the id passed back from add notification.

0 commit comments

Comments
 (0)