Ejemplo n.º 1
0
    align(rect: Rect, props: AlignProps): Bounds {
        const center = Bounds.centerOf(this);
        const rectCenter = Bounds.centerOf(rect);

        const bounds: Object = {};

        forEach(props, (toSide: TargetSide, side: AlignSide) => {
            if (side === "center" && toSide === "center") {
                Object.assign(bounds, {
                    left: add(this.left, sub(center.left, rectCenter.left)),
                    top: add(this.top, sub(center.top, rectCenter.top)),
                    right: add(this.right, sub(center.right, rectCenter.right)),
                    bottom: add(this.bottom, sub(center.bottom, rectCenter.bottom))
                });
            } else if (toSide === "horizontal") {
                bounds.left = add(this.left, sub(center.left, rectCenter.left));
                bounds.right = add(this.left, sub(center.right, rectCenter.right));
            } else if (toSide === "vertical") {
                bounds.top = add(this.top, sub(center.top, rectCenter.top));
                bounds.bottom = add(this.bottom, sub(center.bottom, rectCenter.bottom));
            } else if (side === "center") {
                bounds[toSide] = sub(this[toSide], rectCenter[toSide]);
            } else if (toSide === "center") {
                bounds[side] = add(this[side], center[side]);
            } else if (side !== toSide) {
                bounds[side] = add(this[side], toSide === "left" || toSide === "right" ? this.width : this.height);
            } else {
                bounds[side] = this[side];
            }
        });

        return new Bounds(bounds);
    }
Ejemplo n.º 2
0
 updateDrops(drops) {
     forEach(drops.valueOf(), (drop, id) => {
         if (drop) {
             this.mountDrop(id, drop);
         } else {
             this.unmountDrop(id);
         }
     });
 }
    static defineTypedProperty(props) {
        this.define({ definedProperties: Object.assign({}, this.definedProperties, props) });

        forEach(props, (Type, prop) => {
            defineTypedProperty(this, prop, Type);
        });

        return this;
    }
Ejemplo n.º 4
0
    connect(actions) {
        forEach(actions, (action, name) => {
            const handler = this[name];

            if (typeof handler === "function") {
                action.listen(handler.bind(this));
            }
        });

        return this;
    }
Ejemplo n.º 5
0
 componentWillUnmount() {
     forEach(this.state.drops, this.unmountDrop, this);
 }