Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6aabe91
Added tasts
mszylkowski Dec 21, 2021
dc1fa87
Undo
mszylkowski Dec 21, 2021
d707e5b
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Dec 28, 2021
0e3df75
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Dec 28, 2021
a3f7bd0
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 4, 2022
8c5119c
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 6, 2022
77f8435
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 10, 2022
16e712e
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 19, 2022
8088eb7
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 25, 2022
3858b2a
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 28, 2022
e12d2f6
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Jan 31, 2022
2a29105
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Feb 1, 2022
a5b781f
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Feb 10, 2022
b8006ee
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Mar 8, 2022
b570e86
Merge branch 'main' of github.com:ampproject/amphtml
mszylkowski Mar 10, 2022
974e219
Make observable work with removing items while firing
mszylkowski Mar 17, 2022
e0a87a1
Using set for removing
mszylkowski Mar 17, 2022
5dc4e93
Remove previous code
mszylkowski Mar 17, 2022
c5d9d63
Added iterating depth
mszylkowski Mar 17, 2022
e844875
Added test to check iterations of handler removal
mszylkowski Mar 17, 2022
09809c6
Simplified impl and cleaned unused tests
mszylkowski Mar 17, 2022
be19f25
Added comment
mszylkowski Mar 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Using set for removing
  • Loading branch information
mszylkowski committed Mar 17, 2022
commit e0a87a15cd5e649133f36d72e4989b9215447661
12 changes: 8 additions & 4 deletions src/core/data-structures/observable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {removeItem} from '#core/types/array';
import {remove, removeItem} from '#core/types/array';

/**
* This class helps to manage observers. Observers can be added, removed or
Expand All @@ -13,8 +13,8 @@ export class Observable {
/** @type {?Array<function(TYPE=):void>} */
this.handlers_ = null;

/** @type {!Array<function(TYPE=):void>} */
this.handlersToRemove_ = [];
/** @type {!Set<function(TYPE=):void>} */
this.handlersToRemove_ = new Set();

/** @type {boolean} */
this.iterating_ = false;
Expand Down Expand Up @@ -45,7 +45,7 @@ export class Observable {
return;
}
if (this.iterating_) {
this.handlersToRemove_.push(handler);
this.handlersToRemove_.add(handler);
} else {
removeItem(this.handlers_, handler);
}
Expand Down Expand Up @@ -77,6 +77,10 @@ export class Observable {
for (const handler of this.handlersToRemove_) {
removeItem(this.handlers_, handler);
}
if (this.handlersToRemove_.size) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old Code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, removing it now

remove(this.handlers_, (handler) => this.handlersToRemove_.has(handler));
this.handlersToRemove_.clear();
}
}

/**
Expand Down