Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix(event): fix memory leak for once, add more test cases #841

Merged
merged 2 commits into from
Jul 17, 2017

Conversation

JiaLiPassion
Copy link
Collaborator

@JiaLiPassion JiaLiPassion commented Jul 15, 2017

  1. fix memory leak issue when addEventListener with {once: true}, in this PR, we handle once
    ourselves.
button.addEventListener('click', function() {}, {once:true});
  1. if user don't call eventTarget.removeEventListener but call zone.cancelTask directly (for example, we may use like this in unit test spec to clean up eventListeners), we should clean the eventTasks from target.
let eventTasks = [];
let zoneSpec = {
  name: 'test',
  onScheduleTask: function(task..) {
    if (task.type === eventTask) {
      eventTasks.push(task);
    } 
  }
}
zone.fork(zoneSpec).run(() => {
   testCode();
});

// on finish clean up
function complete() {
  eventTasks.forEach(task => {
    task.zone.cancelTask(task);
  });
}
  1. add more test cases about capture=true.

  2. change ZonePrivate api, don't set api.patchEventTargetMethods multiple times.

@mhevery mhevery merged commit 2143d9c into angular:master Jul 17, 2017
@JiaLiPassion JiaLiPassion deleted the once branch July 20, 2017 22:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants