Hi, 

I have run to weird issue regarding sending data to port. 

*Background*

I am working on Angular app, that I want piece by piece replace with Elm. 
During the transition, ports are really important, so I can communicate 
data back and fourth. 

Now I have some Angular directive [basically a component], who's controller 
after fetching some data, will send it to Elm. Code is something along the 
lines of : 

controller: function($scope, dataservice){
  // $scope.id is unique for each directive, eg. controller
  dataservice.get()
    .then (sendToElm($scope.$id)); 
}

function sendToElm (id){
 (data) => elmApp.ports.foo.send([id, data]);
}


Now this works fine if I have one controller, i.e. one directive on the 
page. But problem comes when I have multiple directives, ie, this 
controller function *fires couple of times in short interval. *

*Problem*

So the problem lies in the fact that ports don't accept second *send 
*invocation 
in short burst. 

When I tried to isolate test case, everything worked fine, no matter how 
fast I feed data into Elm.

So I had go back to my Angular app and check what is wrong. 

When I added random timeout, greater that 1s things started to work fine: 

controller: function($scope, dataservice){
  // $scope.id is unique for each directive, eg. controller
  dataservice.get()
    .then (sendToElm($scope.$id)); 
}

function sendToElm (id){
 (data) => {
  time = parseInt(Math.random() * 1000);
  setTimeout(() => { 
    elmApp.ports.foo.send([id, data]); 
  }, time);
 }
}

But the issue seems to persist if I decrease that 1000 multiplier to 
anything less than 900. 

Now I wonder, can anybody bring any insight into why this is behaving like 
it is. 

Many thanks folks

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to