iteratehq / iterate-android

Iterate Android SDK
MIT License
3 stars 1 forks source link

Create a StringToAnyMap class to improve type alias #16

Closed endruuu closed 2 years ago

endruuu commented 3 years ago

Previously, we did this to create the UserTraits type:

typealias UserTraits = MutableMap<String, Any>

However, when we wanted to create an object of UserTraits, what we did was:

val userTraits = mutableMapOf(
    "email" to "a@a.com",
    "external_id" to "user-12345"
)

It will confuse readers as we set the data type to be UserTraits, but use mutableMapOf when we want to instantiate it. This PR fixes the issue by creating a new class called StringToAnyMap that extends from LinkedHashMap (the default implementation of mutableMapOf)

endruuu commented 2 years ago

Exactly. But, they actually can use UserTraits instead:

val traits = UserTraits(
    "id" to 12345,
    "message" to "Hello!"
 )

Iterate.identify(traits)