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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reply with an Encodable type #12

Merged
merged 7 commits into from
Aug 10, 2023
Merged

Reply with an Encodable type #12

merged 7 commits into from
Aug 10, 2023

Conversation

svara
Copy link
Collaborator

@svara svara commented Aug 9, 2023

This PR adds the option to reply to a message with an object conforming to Encodable protocol. The library handles the encoding using the JSONEncoder.

Example:

private func onItemSelected(at index: Int) {
    reply(to: Event.display.rawValue,
             with: SelectionMessageData(selectedIndex: index))
}

struct SelectionMessageData: Encodable {
        let selectedIndex:Int
}

The library allows to set custom JSON encoder/decoder. The custom encoder/decoder can be useful when you need to apply specific encoding/decoding strategies.
To set a custom encoder/decoder you set it like:

Strada.config.jsonEncoder = myCustomEncoder
Strada.config.jsonDecoder = myCustomDecoder

@svara svara requested a review from jayohms August 9, 2023 15:51
Copy link
Collaborator

@jayohms jayohms left a comment

Choose a reason for hiding this comment

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

Such a nice improvement 👏

Source/Message.swift Outdated Show resolved Hide resolved
Source/StradaJSONCoding.swift Outdated Show resolved Hide resolved
Source/Message.swift Outdated Show resolved Hide resolved
Copy link
Collaborator

@jayohms jayohms left a comment

Choose a reason for hiding this comment

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

Really wonderful, this will go a long way to simplify using message data within components 👏

Source/Strada.swift Show resolved Hide resolved
Source/Message.swift Show resolved Hide resolved
@svara svara merged commit 03a77d5 into main Aug 10, 2023
1 check passed
@svara svara deleted the reply-codable branch August 10, 2023 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants