Transcript from the "Talking to JS Solution" Lesson
[00:00:39] Now ordinarily this would be where we implement the body of this if it were a normal function. But this is a port which means that we don't actually need to do anything else. Elm's just generate the implementation for us. So here, inside this function, which is being called elsewhere in the code, all we're gonna do is we're just going to handoff directly to the port.
[00:00:59] So we're gonna say storeSession maybeAuthenticationToken, and that's it. So that should compile, oops, we wanna be pack in part9. Okay, that compiled. And so we will see if it actually works. I guess we should demonstrate the lack of it working. Actually now with half of it implemented it's going to partially work so maybe not.
[00:01:46] It's not in the string form but rather it's in sort of a raw Java Script object that needs to be decoded before we can do something useful with it. But at this point it's just sort of undecoded and something that's just passing through our program. So in order to write a port for this, we're going to use a similar tactic to what we did last time.
[00:02:19] So I can say on session change passing to message and that should compile no problem. No, it did not? Right [LAUGH], I can't just put a type definition and have it work. I actually have to use the port keyword. Otherwise, it just looks like I'm just writing a weird function that I didn't actually define.
[00:02:38] Okay, thanks compiler. So, based on that, I should now, theoretically, be able to sign out, sign up for a new account. And actually, let's put some console logs in here so we can actually see what's going on as we're doing this stuff. So inside here, inside storage session, I'm going to say console.log got a new session.
[00:03:00] A new session and then when we actually set the session, in other words this is going to be sent into Elm through a port, we can say session changed.
>> Richard Feldman: And I don't need to recompile it because that's just raw HTML. Got this email and this username.
>> Richard Feldman: Have an extremely secure password because not even I know it.
>> Richard Feldman: You can zoom it a little bit so we can see that. By the way this is a little warning compiled in DEV mode. Follows advice for a better performance and smaller assets, which is basically tell us here is how you can enable the optimize flag to get better assets.
[00:03:58] And that's all there is to it. Questions?
>> Speaker 2: So the port takes a signature, is that right?
>> Richard Feldman: Yes, the port keyword, yes. It does expect only a signature, yeah.
>> Speaker 2: That is odd for sure.
>> Richard Feldman: That is odd for sure. Yeah, I mean essentially it's code generation, right?
[00:04:52] You have a third party widget or something like that, like a date picker or what have you and you want to just to be able to drop it in the middle of your view. Custom elements are a way that you can do that. So, not something we're gonna cover here but if you're curious about that and that sounds like it fits your use case I highly recommend checking out his talk which we will link to.