Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
markUsage() {
const ctx = b.getCurrentCtx() as IBobxCallerCtx;
if (ctx === undefined)
// outside of render => nothing to mark
return;
if (isIBobxComputed(ctx)) {
if (ctx.markUsing(this.atomId, this)) {
let ctxs = this.ctxs;
if (ctxs === undefined) {
ctxs = new Map();
this.ctxs = ctxs;
}
ctxs.set(ctx.atomId, ctx);
}
} else {
let bobx = ctx.$bobxCtx;
if (bobx === undefined) {
bobx = new Map() as IBobXInCtx;
ComputedImpl.prototype.run = function () {
if (this.state === 2 /* Updating */) {
throw new Error("Recursively calling computed value");
}
this.markUsage();
if (this.state !== 3 /* Updated */) {
this.update();
if (b.getCurrentCtx() === undefined) {
this.buryIfDead();
}
}
if (this.exception !== undefined)
throw this.exception;
return this.value;
};
return ComputedImpl;
ComputedImpl.prototype.markUsage = function () {
var ctx = b.getCurrentCtx();
if (ctx === undefined)
// outside of render => nothing to mark
return;
if (isIBobxComputed(ctx)) {
if (ctx.markUsing(this.atomId, this)) {
var ctxs = this.usedBy;
if (ctxs === undefined) {
ctxs = new Map();
this.usedBy = ctxs;
}
ctxs.set(ctx.atomId, ctx);
}
}
else {
var bobx = ctx.$bobxCtx;
if (bobx === undefined) {
var previousBeforeRender = b.setBeforeRender(function (node, phase) {
var ctx = b.getCurrentCtx();
if (phase === 3 /* Destroy */ || phase === 1 /* Update */ || phase === 2 /* LocalUpdate */) {
outsideOfComputedPartialResults = false;
var bobx = ctx.$bobxCtx;
if (bobx !== undefined) {
bobx.forEach(function (value) {
if (isIBobxComputed(value)) {
value.unmarkCtx(this.ctxId);
}
else {
value.ctxs.delete(this.ctxId);
}
}, bobx);
if (phase === 3 /* Destroy */) {
ctx.$bobxCtx = undefined;
}
else {
ComputedImpl.prototype.update = function () {
if (alreadyInterrupted && this.partialResults) {
setPartialResults();
return;
}
var backupCurrentCtx = b.getCurrentCtx();
b.setCurrentCtx(this);
this.partialResults = false;
var isFirst = this.state === 0 /* First */;
this.state = 2 /* Updating */;
try {
var newResult = this.fn.call(this.that);
if (isFirst || this.exception !== undefined || !this.comparator(this.value, newResult)) {
this.exception = undefined;
this.value = newResult;
}
else {
isFirst = true;
}
}
catch (err) {
this.exception = err;
function setPartialResults() {
var ctx = b.getCurrentCtx();
if (ctx !== undefined) {
if (isIBobxComputed(ctx)) {
ctx.partialResults = true;
}
else {
b.invalidate(ctx);
}
}
outsideOfComputedPartialResults = true;
}
function gotPartialResults() {
function gotPartialResults() {
var ctx = b.getCurrentCtx();
if (ctx !== undefined && isIBobxComputed(ctx)) {
return ctx.partialResults;
}
return outsideOfComputedPartialResults;
}
exports.gotPartialResults = gotPartialResults;
promiseFulfilled(value: any) {
let backupCurrentCtx = b.getCurrentCtx();
b.setCurrentCtx(this as any);
this.state = ComputedState.Updating;
try {
this.iteratorNext(this.iterator!.next(value));
} catch (err) {
this.value = new CaughtException(err);
this.state = ComputedState.Updated;
this.invalidate();
}
b.setCurrentCtx(backupCurrentCtx);
}
update(): void {
if (alreadyInterrupted && this.partialResults) {
setPartialResults();
return;
}
let backupCurrentCtx = b.getCurrentCtx();
b.setCurrentCtx(this as any);
this.partialResults = false;
this.freeUsings();
let wasChange = false;
if (this.state === ComputedState.First) {
this.state = ComputedState.Updated;
this.value = this.call();
wasChange = true;
} else {
this.state = ComputedState.Updated;
let newResult = this.call();
if (!this.comparator(this.value, newResult)) {
this.value = newResult;
wasChange = true;
}
}
function resetGotPartialResults() {
var ctx = b.getCurrentCtx();
if (ctx !== undefined && isIBobxComputed(ctx)) {
throw new Error("resetGotPartialResults cannot be called from computed method");
}
outsideOfComputedPartialResults = false;
}
exports.resetGotPartialResults = resetGotPartialResults;