Hi all,

I'm starting to use a certain pattern more and more, where I directly call 
an API function but may also get a broadcast notification with the same 
result format. I'm thus using a pattern like the following:

    function handleSomeData(e, data) {
        var actualData = data || e; // This is the pattern...

        // ... work with actualData ...
    }

    myService.doSomething().then(handleSomeData);
    $scope.$on('someData', handleSomeData);...

The reason for that var is that $q.resolve() will pass in just the data 
element you resolved with, while $scope.$broadcast will pass in (e, data). 
It's only one line of code, but it's awkward and repetitive. I was 
wondering if anybody had come up with some magically clever way around 
this. It's a minor detail but it's been bugging me for a while and I'm 
curious.

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to