in packages/sdk/src/Confidence.ts [88:122]
constructor(config: Configuration, parent?: Confidence) {
this.config = config;
this.parent = parent;
this.contextChanges = subject(observer => {
let parentSubscription: Closer | void;
if (parent) {
parentSubscription = parent.contextChanges(keys => {
const visibleKeys = keys.filter(key => !this._context.has(key));
if (visibleKeys.length) observer(visibleKeys);
});
}
this.contextChanged = observer;
return () => {
parentSubscription?.();
this.contextChanged = undefined;
};
});
this.flagStateSubject = subject(observer => {
const reportState = () => observer(this.flagState);
if (!this.currentFlags || !Value.equal(this.currentFlags.context, this.getContext())) {
this.resolveFlags().then(reportState);
}
const close = this.contextChanges(() => {
if (this.flagState === 'READY' || this.flagState === 'ERROR') observer('STALE');
this.resolveFlags().then(reportState);
});
return () => {
close();
this.pendingFlags?.abort();
this.pendingFlags = undefined;
};
});
}