proxy-link
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

proxy-link

proxyLink(source, modifiers?)
Creates a proxy for the source object, modifiers merge with the new proxy object with properly binded functions, getters and setters.

import { proxyLink } from "../src";
const base = { value: "bar" };
 
it("Values Linked", () => {
    const link = proxyLink(base, { count: 1 });
 
    link.value = "baz";
    expect(base.value === "baz").toBe(true);
 
    base.value = "foo";
    expect(link.value === "foo").toBe(true);
    expect(link.count === 1 && (base as any).count === undefined).toBe(true);
});
 
it("Functions, Getters & Setters", () => {
    const link = proxyLink(base, {
        get getter() { return this.value + "!"; },
        set setter(v: string) { this.value = v; },
        exec() { return this.getter + "?"; },
        getValue() { return this.value; },
    });
 
    link.setter = "woof";
    expect(base.value === "woof").toBe(true);
    expect(link.getter === base.value + "!").toBe(true);
    expect(link.exec() === "woof!?").toBe(true);
    expect(link.getValue() === "woof").toEqual(true);
});

/proxy-link/

    Package Sidebar

    Install

    npm i proxy-link

    Weekly Downloads

    0

    Version

    0.0.4

    License

    UNLICENSE

    Unpacked Size

    6.88 kB

    Total Files

    7

    Last publish

    Collaborators

    • natty