Nine Pomeranian Monsters

    @stamp/arg-over-prop

    1.0.4 • Public • Published

    @stamp/arg-over-prop

    Assign properties passed to the stamp factory

    Usage

    import ArgOverProp from '@stamp/arg-over-prop';
    
    const StampA = compose({
        properties: {
            foo: 1
        }
    })
    .compose(ArgOverProp).argOverProp('foo');
    
    const instance1 = StampA(); // { foo: 1 }
    const instance2 = StampA({ foo: 999 }); // { foo: 999 }

    A shorter but identical version of the same StampA:

    const StampA = ArgOverProp.argOverProp({foo: 1});

    Or if you don't want to import the stamp you can import only the method:

    import {argOverProp} from '@stamp/arg-over-prop';
    const StampA = argOverProp({foo: 1});

    Basically, the arg-over-prop stamp sets properties in an initializer. The code below is what the StampA becomes.

    const StampA = compose({
        properties: {
            foo: 1
        },
        initializers: [function (opts) {
            this.foo = opts.foo;
        }]
    })

    Example

    import ArgOverProp from '@stamp/arg-over-prop';
    
    const HasColor = ArgOverProp.argOverProp('color', 'background');
    const HasPoint = ArgOverProp.argOverProp({ x: 0, y: 0 });
    
    const ColorPoint = compose(HasColor, HasPoint);
    
    const point = ColorPoint({ color: 'blue', x: 15 });
    
    console.log(point.color); // "blue"
    console.log(point.background); // undefined
    console.log(point.x); // 15
    console.log(point.y); // 0

    Keywords

    none

    Install

    npm i @stamp/arg-over-prop

    DownloadsWeekly Downloads

    51

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    7.06 kB

    Total Files

    4

    Last publish

    Collaborators

    • stamp