Skip to content

Commit a38da93

Browse files
Bug 2045793 - Add feature update callback registration to FeatureHolder (#7406)
These methods allow methods for adding and removing update callbacks with Nimbus without passing string constants around in client code, making it less likely to cause misregistration due to typos.
1 parent fe81b19 commit a38da93

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • components/nimbus/android/src/main/java/org/mozilla/experiments/nimbus/internal

components/nimbus/android/src/main/java/org/mozilla/experiments/nimbus/internal/FeatureHolder.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,23 @@ class FeatureHolder<T : FMLFeatureInterface>(
134134
}
135135
}
136136

137+
/**
138+
* Add a callback to be called when the feature updates.
139+
*
140+
* This **must** be called after Nimbus is initialized, otherwise the
141+
* callback will not be registered.
142+
*/
143+
fun addUpdateCallback(callback: () -> Unit) {
144+
getSdk()?.getFeatureUpdateDispatcher()?.addCallback(featureId, callback)
145+
}
146+
147+
/**
148+
* Remove a feature update callback.
149+
*/
150+
fun removeUpdateCallback(callback: () -> Unit) {
151+
getSdk()?.getFeatureUpdateDispatcher()?.removeCallback(featureId, callback)
152+
}
153+
137154
/**
138155
* Is this feature the focus of an automated test.
139156
*

0 commit comments

Comments
 (0)