Skip to content

Commit ad3bc3b

Browse files
authored
Context consumer unmounting perf (#4526)
1 parent 87f7efa commit ad3bc3b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/create-context.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export function createContext(defaultValue, contextId) {
1818
/** @type {FunctionComponent} */
1919
Provider(props) {
2020
if (!this.getChildContext) {
21-
/** @type {Component[] | null} */
22-
let subs = [];
21+
/** @type {Set<Component> | null} */
22+
let subs = new Set();
2323
let ctx = {};
2424
ctx[contextId] = this;
2525

@@ -31,19 +31,19 @@ export function createContext(defaultValue, contextId) {
3131

3232
this.shouldComponentUpdate = function (_props) {
3333
if (this.props.value !== _props.value) {
34-
subs.some(c => {
34+
subs.forEach(c => {
3535
c._force = true;
3636
enqueueRender(c);
3737
});
3838
}
3939
};
4040

4141
this.sub = c => {
42-
subs.push(c);
42+
subs.add(c);
4343
let old = c.componentWillUnmount;
4444
c.componentWillUnmount = () => {
4545
if (subs) {
46-
subs.splice(subs.indexOf(c), 1);
46+
subs.delete(c);
4747
}
4848
if (old) old.call(c);
4949
};

0 commit comments

Comments
 (0)