title: DataStore not receiving event from Flow
body: <p>I am playing with datastore-preferences:1.0.0-alpha01 and I cannot seem to get an event back when the datastore value has been updated. I have been trying to observe it in the fragment and the parent activity with the same result. When I create an instance of DataStore and observe a values flow, I receive an event immediately after declaring the observer (seems to be common after registering an observer). This would indicate that flow is functioning and the observer is picking up the events as intended. I then update the value of the preference inside of the same observer which never picks up an event.</p>
  <p>I was using this article as a reference <a href="https://medium.com/scalereal/hello-datastore-bye-sharedpreferences-android-f46c610b81d5" rel="noreferrer">https://medium.com/scalereal/hello-datastore-bye-sharedpreferences-android-f46c610b81d5</a> which goes along with the repo that I used to compare my implementation with. Obviously, this one works. <a href="https://github.com/PatilShreyas/DataStoreExample" rel="noreferrer">https://github.com/PatilShreyas/DataStoreExample</a></p>
  <p>DataStoreUtils</p>
  <pre><code>class DataStoreUtils(context: Context) {
  
      companion object {
          private const val TAG = &quot;DataStoreUtils&quot;
      }
  
      private val dataStore = context.createDataStore(name = Constants.PrefName.APP_PREFS)
  
      suspend fun setString(prefKey: String, value: String) {
          Log.d(TAG, &quot;Setting $prefKey to $value&quot;)
          dataStore.edit { it[preferencesKey&lt;String&gt;(prefKey)] = value }
      }
  
      suspend fun getString(prefKey: String): String? {
          return dataStore.data.map { it[preferencesKey&lt;String&gt;(prefKey)] ?: return@map null }.first()
      }
  
      val usernameFlow: Flow&lt;String?&gt; = dataStore.data
          .catch {
              if (it is IOException) {
                  it.printStackTrace()
                  emit(emptyPreferences())
              }
              else { throw it }
          }
          .map { it[preferencesKey(Constants.SharedPrefKeys.USERNAME)] ?: return@map null }
  
  }
  </code></pre>
  <p>UpdateConnectionDialog</p>
  <pre><code>class UpdateConnectionDialog : DialogFragment() {
  
      companion object {
          private const val TAG = &quot;UpdateConnectionDialog&quot;
      }
  
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
  
          save_btn.setOnClickListener {
              runBlocking { authenticateResponse(ApiCalls.postLogin(body)!!) }
          }
      }
  
      override fun onResume() {
          super.onResume()
  
          dataStore ?: dataStore = DataStoreUtils(Application.appInstance?.applicationContext!!)
  
          dataStore.usernameFlow.asLiveData().observe(this) {
              Log.d(TAG, &quot;Updated username to: $it&quot;)
          }
      }
  
      private fun authenticateResponse(response: ApiResponse&lt;String&gt;) {
  
          Log.d(TAG, &quot;Auth request made.&quot;)
  
          when (response) {
              is ApiSuccessResponse&lt;String&gt; -&gt; {
                  AppLog.d(TAG, &quot;Auth Success&quot;)
  
                  lifecycleScope.launch {
                      dataStore.setString(Constants.PrefKeys.USERNAME, username_input.text.toString())
                      dataStore.setString(Constants.PrefKeys.PASSWORD, password_input.text.toString())
                  }
              }
              is ApiErrorResponse&lt;String&gt; -&gt; {
                  AppLog.d(TAG, &quot;Auth failed&quot;)
              }
          }
      }
  }
  </code></pre>
  <p>When the view inflates this is what I see in the logs</p>
  <pre><code>D/UpdateConnectionDialog: onCreateView()
  D/UpdateConnectionDialog: onViewCreated()
  D/UpdateConnectionDialog: onResume()
  D/UpdateConnectionDialog: Updated username to: X // Seems to be common with other examples I have found. After registering an observer it immediately triggers the event.
  D/UpdateConnectionDialog: Auth request made.
  D/UpdateConnectionDialog: Auth Success
  D/DataStoreUtils: Setting USERNAME to X
  D/DataStoreUtils: Setting PASSWORD to X
  </code></pre>
  <p>Now, with other examples, we should see the observer fire an event for having been updated but I am not. With other examples, adding the same logging points, it's apparent the observer receives the update event.</p>