How to use bobril - 10 common examples

To help you get started, we’ve selected a few bobril examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bobril / bobx / index.js View on Github external
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 () {
github bobril / bobx / index.ts View on Github external
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;
github bobril / bobx / index.js View on Github external
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;
github bobril / bobx / index.js View on Github external
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) {
github bobril / bobx / index.js View on Github external
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 {
github bobril / bobx / index.js View on Github external
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;
github bobril / bobx / index.ts View on Github external
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]!;
github bobril / bobx / index.ts View on Github external
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() {
github bobril / bobx / index.ts View on Github external
var haveTimeBudget: () => boolean = () => b.now() - frameStart < timeBudget; // Spend only first 10ms from each frame in computed methods.
github bobril / bobx / index.js View on Github external
var haveTimeBudget = function () { return b.now() - frameStart < 10; }; // Spend only first 10ms from each frame in computed methods.
function resetGotPartialResults() {