Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (this.state !== 4 /* Scope */) {
if (this.state === 2 /* Updating */) {
throw new Error("Modifying inputs during updating computed");
}
if (this.state === 3 /* Updated */) {
this.state = 1 /* NeedRecheck */;
var usedBy = this.usedBy;
if (usedBy !== undefined) {
this.usedBy = undefined;
usedBy.forEach(function (comp) {
comp.invalidateBy(this.atomId);
}, this);
}
if (this.ctxs !== undefined) {
updateNextFrameList.push(this);
b.invalidate(bobxRootCtx);
}
}
}
this.freeUsings();
}
};
ComputedImpl.prototype.freeUsings = function () {
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;
export function observableProp(obj: T, key: K): b.IProp {
if (obj == null) throw new Error("observableProp parameter is " + obj);
let bobx = ((obj as any) as IAtom).$bobx;
if (bobx === undefined) throw new Error("observableProp parameter is not observable: " + obj);
if (bobx === ObservableMapMarker) throw new Error("observableProp parameter is observableMap");
if (b.isArray(bobx)) {
// Does this pays off to cache and/or inline?
return (value?: any) => {
if (value !== undefined) {
obj[key] = value;
}
return obj[key];
};
}
if (Object.getPrototypeOf(bobx) === undefined) {
return (bobx[key] as ObservableValue).prop();
}
bobx = asObservableClass(obj);
let val = bobx[key];
if (val === undefined) {
obj[key]; // Has side effect to create ObservableValue
val = bobx[key]!;
return obj[key];
};
}
if (Object.getPrototypeOf(bobx) === undefined) {
return (bobx[key] as ObservableValue).prop();
}
bobx = asObservableClass(obj);
let val = bobx[key];
if (val === undefined) {
obj[key]; // Has side effect to create ObservableValue
val = bobx[key]!;
}
return val.prop();
}
var frameStart = b.now();
var outsideOfComputedPartialResults = false;
var alreadyInterrupted = false;
var firstInterruptibleCtx: IBobxCallerCtx | undefined;
var timeBudget = 10;
export function setTimeBudget(value: number) {
timeBudget = value;
}
export function getTimeBudget(): number {
return timeBudget;
}
var haveTimeBudget: () => boolean = () => b.now() - frameStart < timeBudget; // Spend only first 10ms from each frame in computed methods.
export function resetGotPartialResults() {
var haveTimeBudget: () => boolean = () => b.now() - frameStart < timeBudget; // Spend only first 10ms from each frame in computed methods.
var haveTimeBudget = function () { return b.now() - frameStart < 10; }; // Spend only first 10ms from each frame in computed methods.
function resetGotPartialResults() {