Skip to content

Commit

Permalink
fixes elm#952
Browse files Browse the repository at this point in the history
Checking callback type on port subscribe

Currently calling `elm.ports[portName].subscribe(undefined)` will cause an exception only when subscribers get called, this commit adds a type check before pushing the callback on subscription list
  • Loading branch information
emilianobovetti authored and rupertlssmith committed Mar 4, 2022
1 parent 84f3889 commit 758b3ae
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Elm/Kernel/Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ function _Platform_setupOutgoingPort(name)

function subscribe(callback)
{
if (typeof callback !== 'function')
{
throw new Error('Trying to subscribe an invalid callback on port `' + name + '`');
}

subs.push(callback);
}

Expand Down

0 comments on commit 758b3ae

Please sign in to comment.