Introduce Object and ObjectSupportedType
#36
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Togglearray.Togglekeys are predefined e.gbool,intetc. 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.
ObjectThis is the structure which will be returned to SDK consumer at the end when they ask for object value for concrete
Variable.Objectgives the consumers ability to access their object ether as dictionary (mapproperty) or decoding that map to their expected typeTby callingasType<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:ObjectSupportedTypeIt makes sure that our Object has predefined value support. Each property must be either:
Bool,Int,StringorDouble. It will throw an exception if it encounters other type while decoding.Tests
Tests are covering 100% of the new code.
