Skip to content

Commit

Permalink
Merge branch 'main' into ci/refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian authored Oct 6, 2024
2 parents 4f0b542 + ad3bc3b commit 9c565bb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/create-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export function createContext(defaultValue, contextId) {
/** @type {FunctionComponent} */
Provider(props) {
if (!this.getChildContext) {
/** @type {Component[] | null} */
let subs = [];
/** @type {Set<Component> | null} */
let subs = new Set();
let ctx = {};
ctx[contextId] = this;

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

this.shouldComponentUpdate = function (_props) {
if (this.props.value !== _props.value) {
subs.some(c => {
subs.forEach(c => {
c._force = true;
enqueueRender(c);
});
}
};

this.sub = c => {
subs.push(c);
subs.add(c);
let old = c.componentWillUnmount;
c.componentWillUnmount = () => {
if (subs) {
subs.splice(subs.indexOf(c), 1);
subs.delete(c);
}
if (old) old.call(c);
};
Expand Down

0 comments on commit 9c565bb

Please sign in to comment.