How to use the @hpcc-js/util.Observable function in @hpcc-js/util

To help you get started, we’ve selected a few @hpcc-js/util 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 hpcc-systems / Visualization / tests / test-util / src / observer.spec.ts View on Github external
it("reference counter", function () {
        function echoEvent() {
            // logger.debug(args);
        }
        const et = new Observable("aaa", "bbb", "zzz");
        expect(et.hasObserver()).is.false;
        et.addObserver("aaa", echoEvent);
        expect(et.hasObserver()).is.true;
        expect(et.hasObserver("aaa")).is.true;
        expect(et.hasObserver("bbb")).is.false;
        et.addObserver("bbb", echoEvent);
        const h = et.addObserver("bbb", echoEvent);
        expect(et.hasObserver()).is.true;
        expect(et.hasObserver("aaa")).is.true;
        expect(et.hasObserver("bbb")).is.true;
        et.removeObserver("aaa", echoEvent);
        expect(et.hasObserver()).is.true;
        expect(et.hasObserver("aaa")).is.false;
        expect(et.hasObserver("bbb")).is.true;
        h.release();
        expect(et.hasObserver()).is.false;
github hpcc-systems / Visualization / tests / test-util / src / observer.spec.ts View on Github external
it("message dispatch", function () {
        const et = new Observable("aaa", "bbb", "zzz");
        et.addObserver("aaa", (a: number, b: number, c: number, d?: number) => {
            expect(a).to.equal(1);
            expect(b).to.equal(2);
            expect(c).to.equal(3);
            expect(d).to.be.undefined;
        });
        et.dispatchEvent("aaa", 1, 2, 3);
    });
});