v1.14.0 - Add StatsigListening Protocol for User Value Changes
Adds the StatsigListening. This protocol allows you to listen for changes in the user value store.
There are two methods that can be implemented:
onInitialized
- Will be called when the initialize request is returned in
Statsig.start()
. - An error string may be passed to this function if something went wrong with the network request.
onUserUpdated
- Will be called when the network request for
Statsig.updateUser
is returned. - An error string may be passed to this function if something went wrong with the network request.
You then add your class that implements StatsigListening as a listener with:
Statsig.addListener(myListeningClass)
Note: If you call Statsig.addListener
after Statsig.start()
is already complete, the onInitialized
method will be called immediately.
Also adds Statsig.isInitialized()
which returns a boolean stating whether the Statsig.start()
call has returned.
These API changes will allow developers to know whether their Statsig instance is initialized.
ViewController Example
class ViewController: UIViewController, StatsigListening {
override func viewDidLoad() {
super.viewDidLoad()
if Statsig.isInitialized() {
render()
} else {
Statsig.addListener(self)
renderLoading()
}
}
private func render() {
var showNewUI = Statsig.checkGate("new_ui_enabled", false)
if showNewUI {
// Render the new
} else {
// Render the old
}
}
private func renderLoading() { /* Some Loading UI */ }
private func renderError(error: String) { /* Some Error UI */ }
// StatsigListening Implementation
func onInitialized(_ error: String?) {
if (error) {
renderError(error)
}
render()
}
func onUserUpdated(_ error: String?) { /* Optional rerender when User changed */ }
}