Skip to content

Conversation

@ashalva
Copy link
Contributor

@ashalva ashalva commented Feb 1, 2024

Motivation

Currently Toggles support only primitive types, but seemingly there is some need to add support for objects. I will be working for some time to add support for objects in Toggles. So, expect some more prs in upcomings days/weeks.

Implementation

This is how the object based Toggle will be represented as json 👇

Object json
{
    "variable": "object_toggle",
    "object": {
        "boolProperty" : true,
        "stringProperty" : "value",
        "intProperty" : 420
    },
    "metadata": {
        "group": "Raw toggles",
        "description": "Object toggle"
    }
}

The basic flow for Toggles is to intake the predefined json structure and it will decode into the Toggle array. Toggle keys are predefined e.g bool, int etc. When we are talking about objects though, we need some mechanism which will allow us to use dynamic keys.

That's why I am introducing two new objects in the SDK.

Object

This is the structure which will be returned to SDK consumer at the end when they ask for object value for concrete Variable. Object gives the consumers ability to access their object ether as dictionary (map property) or decoding that map to their expected type T by calling asType<T>()

It has custom decoding strategy. We will be decoding above mentioned json to dictionary where value is actually enum ObjectSupportedType. On top of that, it throws errors in several scenarios:

  1. If objects key is empty.
  2. If the object is empty.
  3. If the object is nested.

ObjectSupportedType

It makes sure that our Object has predefined value support. Each property must be either: Bool, Int, String or Double. It will throw an exception if it encounters other type while decoding.

Tests

Tests are covering 100% of the new code.

Copy link
Member

@albertodebortoli albertodebortoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ashalva 🙌 Looking good!

Copy link
Contributor

@AlexLotsu AlexLotsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could some additional tests be added?

You could consider tests for this new type in Value+UtilitiesTests, Value+AccessorsTests, Dictionary+TogglesTests

@ashalva
Copy link
Contributor Author

ashalva commented Feb 8, 2024

You could consider tests for this new type in Value+UtilitiesTests, Value+AccessorsTests, Dictionary+TogglesTests

Thanks @AlexL271828, every part of the new code is tested but in one file. 100% of the new code is covered with unit tests.

@albertodebortoli albertodebortoli merged commit f4b6030 into TogglesPlatform:main Feb 8, 2024
@ashalva ashalva mentioned this pull request Feb 13, 2024
@albertodebortoli albertodebortoli added this to the 0.11.0 milestone Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants