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

Sending Json.Value over a Port doesn't Work #22

Closed
maxsnew opened this Issue Nov 29, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@maxsnew
Contributor

maxsnew commented Nov 29, 2014

File

module Main where

import Json.Encode as Json
import Signal
import Text (..)
import Time (..)

port out : Signal Json.Value
port out = Signal.sampleOn (every second) (Signal.constant (Json.object []) )

main = plainText "test" 

Compile this to a file main.js and then open this html file:

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="main.js"></script>
</head>
<body>
<h1>Test</h1>
<div id="bug"></div>

<script type="text/javascript">
 var handler = function(o) { console.log(o) };
var div = document.getElementById('bug');
var test = Elm.embed(Elm.Main, div, { });
test.ports.out.subscribe(handler); 
</script>
</body>
</html> 

and get the error:

Initialization Error on port 'out':

    $Native$Json is not defined
@maxsnew

This comment has been minimized.

Show comment
Hide comment
@maxsnew

maxsnew Nov 29, 2014

Contributor

Furthermore, adding the necessary $Native$Json = Elm.Native.Json.make(_elm) then results in another error:

Initialization Error on port 'out':

    $Native$Json.toJS is not a function
Contributor

maxsnew commented Nov 29, 2014

Furthermore, adding the necessary $Native$Json = Elm.Native.Json.make(_elm) then results in another error:

Initialization Error on port 'out':

    $Native$Json.toJS is not a function
@maxsnew

This comment has been minimized.

Show comment
Hide comment
@maxsnew

maxsnew Nov 29, 2014

Contributor

I think the bug is this line: https://github.com/elm-lang/elm-compiler/blob/92be75c649fe8b5010893c9be30b2ae5177b207a/src/Generate/JavaScript/Ports.hs#L166 it should just return the value as-is since it's already a JS value

Contributor

maxsnew commented Nov 29, 2014

I think the bug is this line: https://github.com/elm-lang/elm-compiler/blob/92be75c649fe8b5010893c9be30b2ae5177b207a/src/Generate/JavaScript/Ports.hs#L166 it should just return the value as-is since it's already a JS value

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Nov 29, 2014

Member

Thanks for the report and finding the root issue. elm/compiler@530fe17 should fix it. I think there are similar issues lurking in the ports code, so I'm going to add it to my pre-0.14 todo list to go through and check for any more stuff like this.

Member

evancz commented Nov 29, 2014

Thanks for the report and finding the root issue. elm/compiler@530fe17 should fix it. I think there are similar issues lurking in the ports code, so I'm going to add it to my pre-0.14 todo list to go through and check for any more stuff like this.

@evancz evancz closed this Nov 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment