Skip to content

Instantly share code, notes, and snippets.

@fredcy
Last active November 13, 2015 23:10
Show Gist options
  • Save fredcy/f6d2a7aba81f143916e8 to your computer and use it in GitHub Desktop.
Save fredcy/f6d2a7aba81f143916e8 to your computer and use it in GitHub Desktop.
Show problem passing 'default' field name though elm port.

This example demonstrates how the default field/property name somehow causes a problem when passing data into an Elm application through a port.

import Html exposing (..)
type alias Info = { default : String, default1 : String }
main : Html
main =
-- Access and display both fields as obtained through the port to show how the
-- "default" field value does not get through.
let m = startingState
val = ( m.default, m.default1 )
in
div []
[ div [] [ startingState |> toString |> text ]
, div [] [ val |> toString |> text ]
]
port startingState : Info
<!DOCTYPE HTML>
<html>
<head>
<title>Default test</title>
<script type="text/javascript" src="elm.js"></script>
</head>
<body>
<h1>Default test</h1>
</body>
<script>
var startingState = { 'default' : 'foobar', 'default1' : 'larry' };
var test = Elm.fullscreen(Elm.Main, { startingState: startingState });
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment