yukatan / commangular

Command framework for AngularJS
MIT License
83 stars 8 forks source link

lastResult refers to same object for two separate commands executed after eachother, if input data is the same object #4

Closed patroza closed 9 years ago

patroza commented 10 years ago

E.g; (pseudo code);

routeInfo = {x: 1, y: 2};
dispatch('SomeCommand', routeInfo)
  .then(Function(firstResult) { 
    dispatch('SomeOtherCommand', routeInfo)
     .then(Function(secondResult) {
        // firstResult.lastResult now contains the same object as secondResult.lastResult
     });
  });

Is this by design? Just ran into this issue and had to scratch my head to figure out what was going on. The problem disappeared once I used: angular.copy(routeInfo) on both dispatch calls.

(I realize there is a built-in feature to chain commands)

yukatan commented 9 years ago

Sorry about the delay, github is not sending me mails from issues I dont know why. I have to check it out.

The problem you have is not really a problem, there is a unique command context for every event to dispatch. You are dispatching the same data object for the two events so you are sharing the data object between context. If you want yo chain commands use the built in feature to do it.