Automate defaultToString behaviour
parent
95f0aa2934
commit
1d0a9de7da
|
@ -183,7 +183,6 @@ coder =
|
|||
, description = Text.fields.timelineFilter.senders
|
||||
, coder = Json.set Json.string
|
||||
, default = ( Set.empty, [] )
|
||||
, defaultToString = always "[]"
|
||||
}
|
||||
)
|
||||
(Json.field.required
|
||||
|
@ -199,7 +198,6 @@ coder =
|
|||
, description = Text.fields.timelineFilter.types
|
||||
, coder = Json.set Json.string
|
||||
, default = ( Set.empty, [] )
|
||||
, defaultToString = always "[]"
|
||||
}
|
||||
)
|
||||
(Json.field.required
|
||||
|
|
|
@ -80,7 +80,6 @@ coder x =
|
|||
, description = Text.fields.iddict.cursor
|
||||
, coder = Json.int
|
||||
, default = ( 0, [] )
|
||||
, defaultToString = String.fromInt
|
||||
}
|
||||
)
|
||||
(Json.field.required
|
||||
|
|
|
@ -362,7 +362,7 @@ then the following field type would be used:
|
|||
, coder = string
|
||||
}
|
||||
|
||||
Suppose the JSO isn't obligated to provide a list of hobbies, and the list would
|
||||
Suppose the JSON isn't obligated to provide a list of hobbies, and the list would
|
||||
by default be overriden with an empty list, then we would use the following
|
||||
field type:
|
||||
|
||||
|
@ -373,8 +373,7 @@ field type:
|
|||
[ "The hobbies of the person. Can be omitted."
|
||||
]
|
||||
, coder = list string
|
||||
, default = ( [], [] ) -- The `List Log` can be inserted in case you wish to insert a message when relying on a default
|
||||
, defaultToString = always "[]" -- Default converted to a string
|
||||
, default = ( [ "football" ], [] ) -- The `List Log` can be inserted in case you wish to insert a message when relying on a default
|
||||
}
|
||||
|
||||
-}
|
||||
|
@ -382,7 +381,7 @@ field :
|
|||
{ required : { fieldName : String, toField : object -> a, description : List String, coder : Coder a } -> Field a object
|
||||
, optional :
|
||||
{ value : { fieldName : String, toField : object -> Maybe a, description : List String, coder : Coder a } -> Field (Maybe a) object
|
||||
, withDefault : { fieldName : String, toField : object -> a, description : List String, coder : Coder a, default : ( a, List Log ), defaultToString : a -> String } -> Field a object
|
||||
, withDefault : { fieldName : String, toField : object -> a, description : List String, coder : Coder a, default : ( a, List Log ) } -> Field a object
|
||||
}
|
||||
}
|
||||
field =
|
||||
|
@ -425,7 +424,7 @@ field =
|
|||
, requiredness = OptionalField
|
||||
}
|
||||
, withDefault =
|
||||
\{ fieldName, toField, description, coder, default, defaultToString } ->
|
||||
\{ fieldName, toField, description, coder, default } ->
|
||||
case coder of
|
||||
Coder { encoder, decoder, docs } ->
|
||||
Field
|
||||
|
@ -449,7 +448,8 @@ field =
|
|||
, requiredness =
|
||||
default
|
||||
|> Tuple.first
|
||||
|> defaultToString
|
||||
|> encoder
|
||||
|> E.encode 0
|
||||
|> OptionalFieldWithDefault
|
||||
}
|
||||
}
|
||||
|
|
|
@ -439,6 +439,5 @@ versionsCoder =
|
|||
, description = Text.fields.versions.unstableFeatures
|
||||
, coder = Json.set Json.string
|
||||
, default = ( Set.empty, [] )
|
||||
, defaultToString = Json.encode (Json.set Json.string) >> E.encode 0
|
||||
}
|
||||
)
|
||||
|
|
|
@ -124,7 +124,6 @@ coder c1 =
|
|||
, description = Text.fields.envelope.settings
|
||||
, coder = Settings.coder
|
||||
, default = Tuple.pair Settings.init []
|
||||
, defaultToString = always "<Default settings>"
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -155,7 +155,6 @@ coder =
|
|||
, description = Text.fields.room.accountData
|
||||
, coder = Json.fastDict Json.value
|
||||
, default = ( Dict.empty, [] )
|
||||
, defaultToString = Json.encode (Json.fastDict Json.value) >> E.encode 0
|
||||
}
|
||||
)
|
||||
(Json.field.optional.withDefault
|
||||
|
@ -164,7 +163,6 @@ coder =
|
|||
, description = Text.fields.room.ephemeral
|
||||
, coder = Json.list StrippedEvent.coder
|
||||
, default = ( [], [] )
|
||||
, defaultToString = Json.encode (Json.list StrippedEvent.coder) >> E.encode 0
|
||||
}
|
||||
)
|
||||
(Json.field.optional.withDefault
|
||||
|
@ -173,7 +171,6 @@ coder =
|
|||
, description = Text.fields.room.events
|
||||
, coder = Hashdict.coder .eventId Event.coder
|
||||
, default = ( Hashdict.empty .eventId, [ log.warn "Found a room with no known events! Is it empty?" ] )
|
||||
, defaultToString = Json.encode (Hashdict.coder .eventId Event.coder) >> E.encode 0
|
||||
}
|
||||
)
|
||||
(Json.field.required
|
||||
|
@ -189,7 +186,6 @@ coder =
|
|||
, description = Text.fields.room.state
|
||||
, coder = StateManager.coder
|
||||
, default = ( StateManager.empty, [] )
|
||||
, defaultToString = Json.encode StateManager.coder >> E.encode 0
|
||||
}
|
||||
)
|
||||
(Json.field.optional.withDefault
|
||||
|
@ -198,7 +194,6 @@ coder =
|
|||
, description = Text.fields.room.timeline
|
||||
, coder = Timeline.coder
|
||||
, default = ( Timeline.empty, [] )
|
||||
, defaultToString = Json.encode Timeline.coder >> E.encode 0
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@ coder =
|
|||
, description = Text.fields.settings.currentVersion
|
||||
, coder = Json.string
|
||||
, default = Tuple.pair Default.currentVersion []
|
||||
, defaultToString = identity
|
||||
}
|
||||
)
|
||||
(Json.field.optional.withDefault
|
||||
|
@ -64,7 +63,6 @@ coder =
|
|||
, description = Text.fields.settings.deviceName
|
||||
, coder = Json.string
|
||||
, default = Tuple.pair Default.deviceName []
|
||||
, defaultToString = identity
|
||||
}
|
||||
)
|
||||
(Json.field.optional.withDefault
|
||||
|
@ -73,13 +71,6 @@ coder =
|
|||
, description = Text.fields.settings.removePasswordOnLogin
|
||||
, coder = Json.bool
|
||||
, default = Tuple.pair Default.removePasswordOnLogin []
|
||||
, defaultToString =
|
||||
\b ->
|
||||
if b then
|
||||
"true"
|
||||
|
||||
else
|
||||
"false"
|
||||
}
|
||||
)
|
||||
(Json.field.optional.withDefault
|
||||
|
@ -88,7 +79,6 @@ coder =
|
|||
, description = Text.fields.settings.syncTime
|
||||
, coder = Json.int
|
||||
, default = Tuple.pair Default.syncTime []
|
||||
, defaultToString = String.fromInt
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -226,7 +226,6 @@ coder =
|
|||
, description = Text.fields.timeline.filledBatches
|
||||
, coder = Json.int
|
||||
, default = ( 0, [] )
|
||||
, defaultToString = String.fromInt
|
||||
}
|
||||
)
|
||||
(Json.field.required
|
||||
|
@ -326,7 +325,6 @@ coderIToken =
|
|||
, description = Text.fields.itoken.starts
|
||||
, coder = Json.set coderIBatchPTRValue
|
||||
, default = ( Set.empty, [] )
|
||||
, defaultToString = always "[]"
|
||||
}
|
||||
)
|
||||
(Json.field.optional.withDefault
|
||||
|
@ -335,7 +333,6 @@ coderIToken =
|
|||
, description = Text.fields.itoken.ends
|
||||
, coder = Json.set coderIBatchPTRValue
|
||||
, default = ( Set.empty, [] )
|
||||
, defaultToString = always "[]"
|
||||
}
|
||||
)
|
||||
(Json.field.optional.withDefault
|
||||
|
@ -344,7 +341,6 @@ coderIToken =
|
|||
, description = Text.fields.itoken.inFrontOf
|
||||
, coder = Json.set coderITokenPTRValue
|
||||
, default = ( Set.empty, [] )
|
||||
, defaultToString = always "[]"
|
||||
}
|
||||
)
|
||||
(Json.field.optional.withDefault
|
||||
|
@ -353,7 +349,6 @@ coderIToken =
|
|||
, description = Text.fields.itoken.behind
|
||||
, coder = Json.set coderITokenPTRValue
|
||||
, default = ( Set.empty, [] )
|
||||
, defaultToString = always "[]"
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -100,7 +100,6 @@ gridField =
|
|||
, description = []
|
||||
, coder = Json.list (Json.list Json.int)
|
||||
, default = ( [], [] )
|
||||
, defaultToString = always "[]"
|
||||
}
|
||||
|
||||
|
||||
|
@ -132,7 +131,6 @@ hobbiesField =
|
|||
, description = []
|
||||
, coder = Json.list Json.string
|
||||
, default = ( [], [] )
|
||||
, defaultToString = always "[]"
|
||||
}
|
||||
|
||||
|
||||
|
@ -149,13 +147,6 @@ invitedToPartyField =
|
|||
, description = []
|
||||
, coder = Json.bool
|
||||
, default = ( False, [] )
|
||||
, defaultToString =
|
||||
\b ->
|
||||
if b then
|
||||
"True"
|
||||
|
||||
else
|
||||
"False"
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue