Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add case object in Value #37

Merged

Conversation

ashalva
Copy link
Contributor

@ashalva ashalva commented Feb 13, 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.

I have introduced the Object in #36. Now its time to actually using and add support object types in Toggles 馃殌

Implementation

For the memory this is how the object based Toggle will be represented as json 馃憞

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

From now on Object and ObjectSupportedType both conform Codable(instead of Decodable) and Equatable. I had to conform to that since Value enum is Codable & Equatable.

Added new case object(Object) in Value which forced me to consider new case in multiple places:

  1. Toggle+Codable.swift - Decodes json to one of the cases of Value.
  2. Value+Utilities.swift - Provides utilities for Toggle e.g description, icon etc.
    1. In order to display object toggle visually nicely, I have added new property description in Object which converts map into pretty json string (Please see attached video)
  3. InputValidationHelper.swift - Validates the input value for overrides. Considering now .object as well. Created two extensions to fulfill my needs:
    1. String+ValidJSON.swift - validates if input string can be decoded in Object.
    2. String+Object.swift - tries to convert input string to Object.

This is how it looks in Demo app:

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-02-13.at.14.06.17.mov

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.

Beautiful PR @ashalva! Thanks 馃憦

Tests/Suites/Extensions/Value+AccessorsTests.swift Outdated Show resolved Hide resolved
Tests/Suites/Utilities/InputValidationHelperTests.swift Outdated Show resolved Hide resolved
Tests/Utilities/ToggleFactory.swift Outdated Show resolved Hide resolved
@albertodebortoli albertodebortoli merged commit e5030af into TogglesPlatform:main Feb 15, 2024
5 checks passed
@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.

None yet

3 participants