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

[#17] Strip field name prefixes #20

Merged

Conversation

chshersh
Copy link
Contributor

Resolves #17

I've checked in the ghci. Seems to work:

λ: data User = User { userHeh :: String, userMeheh :: Int } deriving (Show, Generic)
λ: instance Elm User
λ: toElmDefinition (Proxy @User)
DefAlias (ElmAlias {elmAliasName = "User", elmAliasFields = ElmRecordField {elmRecordFieldType = TypeName {unTypeName = "[Char]"}, elmRecordFieldName = "heh"} :| [ElmRecordField {elmRecordFieldType = TypeName {unTypeName = "Int"}, elmRecordFieldName = "meheh"}]})

@chshersh chshersh self-assigned this Feb 15, 2019
Copy link
Contributor

@vrom911 vrom911 left a comment

Choose a reason for hiding this comment

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

👍

:set -XTypeApplications
import Data.Proxy
import GHC.Generics
import qualified Data.Text as T
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@chshersh chshersh merged commit 962c0cc into master Feb 15, 2019
@chshersh chshersh deleted the chshersh/17-Implement-field-names-stripping-strategy branch February 15, 2019 03:45
@silky
Copy link

silky commented Mar 15, 2023

could we make this a configuration option? it turns out to be inconvenient sometimes

@jhrcek
Copy link
Contributor

jhrcek commented Mar 15, 2023

Could you please open an issue and give us a basic idea on how you'd like this to be configurable?
Something like what aeson is doing?

customOptions = defaultOptions
                { fieldLabelModifier = map toUpper
                }

instance ToJSON Coord where
    toJSON     = genericToJSON customOptions
    toEncoding = genericToEncoding customOptions

We can consider implementing it, but no guarantees about timeline.

@silky
Copy link

silky commented Mar 15, 2023

yes; bafflingly that's what i'm trying, but it seems overriding the options via the toJSON instance doesn't even get triggered when writing the json?!

( is that because the Elm instance overrides it? )

-- edit:

my bad, i see now that that is obvious.

yes, i'm just looking to have that function stripTypeNamePrefix be part of the Settings ( https://hackage.haskell.org/package/elm-street-0.2.0.0/docs/Elm-Generate.html ) somehow.

@turboMaCk
Copy link
Member

interactions between Elm instance and aeson's FromJSON and ToJSON instances are a bit weird and can brake things. See for instance #115

It all depends on how you're deriving the ToJSON and FromJSON.

@jhrcek
Copy link
Contributor

jhrcek commented Mar 15, 2023

It won't be that easy.
You have to realize that allowing arbitrary field name modification in FromJSON / ToJSON would have to be properly reflected in the elm Encoders / Decoders generated by the library.

@silky
Copy link

silky commented Mar 15, 2023

i got confused, the point is stripTypeNamePrefix is always used here - https://github.com/Holmusk/elm-street/blob/master/src/Elm/Generic.hs#L272 - that's where it'd be great to configure it.

@silky
Copy link

silky commented Mar 15, 2023

call me crazy @jhrcek but if that function is customisable, i think everything else would just follow through, no? what would go wrong?

@jhrcek
Copy link
Contributor

jhrcek commented Mar 15, 2023

Not saying it's impossible, just that it would not just be matter of extracting field label modifier within To/FromJSON instances but probably larger change.

@silky
Copy link

silky commented Mar 15, 2023

do you want me to make a new issue for this?

@turboMaCk
Copy link
Member

yes please open new issue for this. Also feel free to submit PR. We will still need to test it and review it and if it seems solid I don't see a reason why it would not get accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement field names stripping strategy
5 participants