diff --git a/BrickKit/bricks/src/main/java/com/wayfair/brickkit/brick/DataModel.kt b/BrickKit/bricks/src/main/java/com/wayfair/brickkit/brick/DataModel.kt index 74d56948..51b9f3f9 100644 --- a/BrickKit/bricks/src/main/java/com/wayfair/brickkit/brick/DataModel.kt +++ b/BrickKit/bricks/src/main/java/com/wayfair/brickkit/brick/DataModel.kt @@ -11,7 +11,13 @@ import java.io.Serializable */ abstract class DataModel : Serializable { @Transient - private val updateListeners = mutableSetOf() + private var updateListeners: MutableSet? = null + get() { + if (field == null) { + field = mutableSetOf() + } + return field + } /** * Add a [DataModelUpdateListener] to the list of listeners. @@ -19,7 +25,7 @@ abstract class DataModel : Serializable { * @param updateListener the listener to add */ open fun addUpdateListener(updateListener: DataModelUpdateListener) { - updateListeners.add(updateListener) + updateListeners!!.add(updateListener) } /** @@ -28,7 +34,7 @@ abstract class DataModel : Serializable { * @param updateListener the listener to remove */ open fun removeUpdateListener(updateListener: DataModelUpdateListener) { - updateListeners.remove(updateListener) + updateListeners!!.remove(updateListener) } /** @@ -37,7 +43,7 @@ abstract class DataModel : Serializable { open fun notifyChange() { val handler = Handler(Looper.getMainLooper()) - updateListeners.forEach { updateListener -> + updateListeners!!.forEach { updateListener -> handler.post { updateListener.notifyChange() } } }