Ports failure with Elm + webpack in IE 10?

66 views
Skip to first unread message

Rex van der Spuy

unread,
Jul 21, 2016, 9:39:07 AM7/21/16
to Elm Discuss
Hi Everyone,

I was doing some browser testing and discovered my ports weren't working in IE
Apparently IE 10 doesn't understand `Object.assign`, which appears in this block of code (I've highlighted the occurrence):

```
function wrapPorts(elm, portSubscribes) {
     var portNames = Object.keys(elm.ports || {});
     //hook ports
     if (portNames.length) {
       portNames
         .filter(function(name) {
           return 'subscribe' in elm.ports[name];
         })
         .forEach(function(portName) {
           var port = elm.ports[portName];
           var subscribe = port.subscribe;
           var unsubscribe = port.unsubscribe;
           elm.ports[portName] = Object.assign(port, {
             subscribe: function(handler) {
               console.log('[elm-hot] ports.' + portName + '.subscribe called.');
               if (!portSubscribes[portName]) {
                 portSubscribes[portName] = [ handler ];
               } else {
                 //TODO handle subscribing to single handler more than once?
                 portSubscribes[portName].push(handler);
               }
               return subscribe.call(port, handler);
             },
             unsubscribe: function(handler) {
               console.log('[elm-hot] ports.' + portName + '.unsubscribe called.');
               var list = portSubscribes[portName];
               if (list && list.indexOf(handler) !== -1) {
                 list.splice(list.lastIndexOf(handler), 1);
               } else {
                 console.warn('[elm-hot] ports.' + portName + '.unsubscribe: handler not subscribed');
               }
               return unsubscribe.call(port, handler);
             }
           });
         });
     }
     return portSubscribes;
   }
```
I'm not sure where this block of code comes from - is it from webpack or the Elm runtime?
(I'm using Elm Webpack Starter: https://github.com/moarwick/elm-webpack-starter)

If it's from the Elm runtime, Object.assign is not compatible with any IE browsers (just Edge 12 and up).
Does anyone know of a simple way around this?

Thanks!

OvermindDL1

unread,
Jul 21, 2016, 10:18:44 AM7/21/16
to Elm Discuss
Get the Object.assign polyfill from Mozilla.  If the browser does not support Object.assign natively then it adds it to Object.

Rex van der Spuy

unread,
Jul 21, 2016, 10:37:19 AM7/21/16
to Elm Discuss
On Thursday, July 21, 2016 at 10:18:44 AM UTC-4, OvermindDL1 wrote:
Get the Object.assign polyfill from Mozilla.  If the browser does not support Object.assign natively then it adds it to Object.


That worked, thanks!
Reply all
Reply to author
Forward
0 new messages