<commit_before>import React, { Component } from 'react';
import {
  Platform,
  Animated,
  TouchableOpacity,
  TouchableNativeFeedback,
  View,
  StyleSheet
} from 'react-native';
import { remove, merge, clone } from 'lodash';
import { connectStyle } from 'native-base-shoutem-theme';

import variables from '../theme/variables/platform';
import { PLATFORM } from '../theme/variables/commonColor';
import computeProps from '../utils/computeProps';
import mapPropsToStyleNames from '../utils/mapPropsToStyleNames';

import { Button } from './Button';

const DIRECTION = {
  DOWN: 'down',
  LEFT: 'left',
  RIGHT: 'right',
  UP: 'up'
};

const POSITION = {
  BOTTOM_LEFT: 'bottomLeft',
  BOTTOM_RIGHT: 'bottomRight',
  TOP_LEFT: 'topLeft',
  TOP_RIGHT: 'topRight'
};

const AnimatedFab = Animated.createAnimatedComponent(Button);

class Fab extends Component {
  constructor(props) {
    super(props);
    this.containerHeight = new Animated.Value(variables.fabWidth);
    this.containerWidth = new Animated.Value(0);
    this.buttonScale = new Animated.Value(0);
    this.state = {
      buttons: undefined,
      active: false
    };
  }

  componentDidMount() {
    const childrenArray = React.Children.toArray(this.props.children);
    const icon = remove(childrenArray, item => {
      if (item.type.displayName === 'Styled(Button)') {
        return true;
      }
      return null;
    });
    // eslint-disable-next-line react/no-did-mount-set-state
    this.setState({
      buttons: icon.length
    });
    this.activeTimer = setTimeout(() => {
      this.setState({
        active: this.props.active
      });
    }, 0);
  }

  componentWillUnmount() {
    if (this.activeTimer) {
      clearTimeout(this.activeTimer);
    }
  }

  getOtherButtonStyle(child, i) {
    const { active, direction } = this.props;
    const type = {
      top: direction ? this.fabOtherBtns(direction, i).top : undefined,
      left: direction ? this.fabOtherBtns(direction, i).left : 8,
      right: direction ? this.fabOtherBtns(direction, i).right : 0,
      bottom: direction
        ? this.fabOtherBtns(direction, i).bottom
        : active === false
        ? Platform.OS === PLATFORM.IOS
          ? 8
          : 8
        : i * 50 + 50
    };

    return merge(
      this.getInitialStyle().buttonStyle,
      StyleSheet.flatten(child.props.style),
      type
    );
  }

  getContainerStyle() {
    return merge(this.getInitialStyle().container, this.props.containerStyle);
  }

  getInitialStyle(iconStyle) {
    const { direction, position } = this.props;
    return {
      fab: {
        height: variables.fabWidth,
        width: variables.fabWidth,
        borderRadius: variables.fabBorderRadius,
        elevation: variables.fabElevation,
        shadowColor: variables.fabShadowColor,
        shadowOffset: {
          width: variables.fabShadowOffsetWidth,
          height: variables.fabShadowOffsetHeight
        },
        shadowOpacity: variables.fabShadowOpacity,
        justifyContent: 'center',
        alignItems: 'center',
        shadowRadius: variables.fabShadowRadius,
        position: 'absolute',
        bottom: variables.fabBottom,
        backgroundColor: variables.fabBackgroundColor
      },
      container: {
        position: 'absolute',
        top: position ? this.fabTopValue(position).top : undefined,
        bottom: position
          ? this.fabTopValue(position).bottom
          : variables.fabContainerBottom,
        right: position
          ? this.fabTopValue(position).right
          : variables.fabContainerBottom,
        left: position ? this.fabTopValue(position).left : undefined,
        width: variables.fabWidth,
        height: this.containerHeight,
        flexDirection: direction
          ? direction === DIRECTION.LEFT || direction === DIRECTION.RIGHT
            ? 'row'
            : 'column'
          : 'column',
        alignItems: 'center'
      },
      iconStyle: {
        color: variables.fabIconColor,
        fontSize: variables.fabIconSize,
        lineHeight: Platform.OS === PLATFORM.IOS ? 27 : undefined,
        ...iconStyle
      },
      buttonStyle: {
        position: 'absolute',
        height: variables.fabButtonHeight,
        width: variables.fabButtonHeight,
        left: variables.fabButtonLeft,
        borderRadius: variables.fabButtonBorderRadius,
        transform: this.state.active
          ? [{ scale: new Animated.Value(1) }]
          : [{ scale: this.buttonScale }],
        marginBottom: variables.fabButtonMarginBottom,
        backgroundColor: variables.fabBackgroundColor
      }
    };
  }

  prepareButtonProps = child => {
    const inp = clone(child.props);
    delete inp.style;

    const defaultProps = {};

    return computeProps(inp, defaultProps);
  };

  fabTopValue = pos => {
    if (pos === POSITION.TOP_LEFT) {
      return {
        top: variables.fabDefaultPosition,
        bottom: undefined,
        left: variables.fabDefaultPosition,
        right: undefined
      };
    } else if (pos === POSITION.BOTTOM_RIGHT) {
      return {
        top: undefined,
        bottom: variables.fabDefaultPosition,
        left: undefined,
        right: variables.fabDefaultPosition
      };
    } else if (pos === POSITION.BOTTOM_LEFT) {
      return {
        top: undefined,
        bottom: variables.fabDefaultPosition,
        left: variables.fabDefaultPosition,
        right: undefined
      };
    } else if (pos === POSITION.TOP_RIGHT) {
      return {
        top: variables.fabDefaultPosition,
        bottom: undefined,
        left: undefined,
        right: variables.fabDefaultPosition
      };
    }
    return null;
  };

  fabOtherBtns(direction, i) {
    const { active } = this.props;
    if (direction === DIRECTION.UP) {
      return {
        top: undefined,
        bottom:
          active === false
            ? Platform.OS === PLATFORM.IOS
              ? 50
              : 5
            : i * 50 + 65,
        left: 8,
        right: 0
      };
    } else if (direction === DIRECTION.LEFT) {
      return {
        top: 8,
        bottom: 0,
        left:
          active === false
            ? Platform.OS === PLATFORM.IOS
              ? 8
              : 8
            : -(i * 50 + variables.fabWidth + 2),
        right: 0
      };
    } else if (direction === DIRECTION.DOWN) {
      return {
        top:
          active === false
            ? Platform.OS === PLATFORM.IOS
              ? 50
              : 8
            : i * 50 + 73,
        bottom: 0,
        left: 8,
        right: 0
      };
    } else if (direction === DIRECTION.RIGHT) {
      return {
        top: 8,
        bottom: 0,
        left:
          active === false
            ? Platform.OS === PLATFORM.IOS
              ? 50
              : 8
            : i * 50 + 73,
        right: 0
      };
    }
    return null;
  }

  prepareFabProps() {
    const defaultProps = {
      style: this.getInitialStyle().fab
    };
    const incomingProps = clone(this.props);
    delete incomingProps.onPress;

    return computeProps(incomingProps, defaultProps);
  }

  upAnimate() {
    if (!this.props.active) {
      Animated.spring(this.containerHeight, {
        toValue: this.state.buttons * 51.3 + variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 1,
        useNativeDriver: true
      }).start();
    } else {
      this.setState({
        active: false
      });
      Animated.spring(this.containerHeight, {
        toValue: variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 0,
        useNativeDriver: true
      }).start();
    }
  }

  leftAnimate() {
    if (!this.props.active) {
      Animated.spring(this.containerWidth, {
        toValue: this.state.buttons * 51.3 + variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 1,
        useNativeDriver: true
      }).start();
    } else {
      this.setState({
        active: false
      });
      Animated.spring(this.containerHeight, {
        toValue: variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 0,
        useNativeDriver: true
      }).start();
    }
  }

  rightAnimate() {
    if (!this.props.active) {
      Animated.spring(this.containerWidth, {
        toValue: this.state.buttons * 51.3 + variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 1,
        useNativeDriver: true
      }).start();
    } else {
      this.setState({
        active: false
      });
      Animated.spring(this.containerHeight, {
        toValue: variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 0,
        useNativeDriver: true
      }).start();
    }
  }

  downAnimate() {
    if (!this.props.active) {
      Animated.spring(this.containerHeight, {
        toValue: variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 1,
        useNativeDriver: true
      }).start();
    } else {
      this.setState({
        active: false
      });
      Animated.spring(this.containerHeight, {
        toValue: variables.fabWidth
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 0,
        useNativeDriver: true
      }).start();
    }
  }
  _animate() {
    const {
      props: { direction, position }
    } = this;

    if (direction) {
      if (direction === DIRECTION.UP) {
        if (position === POSITION.TOP_LEFT || position === POSITION.TOP_RIGHT) {
          console.warn(
            'Passing direction = up with position = topLeft/topRight is not suggested.'
          );
        } else {
          this.upAnimate();
        }
      } else if (direction === DIRECTION.LEFT) {
        if (
          position === POSITION.TOP_LEFT ||
          position === POSITION.BOTTOM_LEFT
        ) {
          console.warn(
            'Passing direction = left with position = topLeft/bottomLeft is not suggested.'
          );
        } else {
          this.leftAnimate();
        }
      } else if (direction === DIRECTION.RIGHT) {
        if (
          position === POSITION.TOP_RIGHT ||
          position === POSITION.BOTTOM_RIGHT
        ) {
          console.warn(
            'Passing direction = right with position = topRight/bottomRight is not suggested.'
          );
        } else {
          this.rightAnimate();
        }
      } else if (direction === DIRECTION.DOWN) {
        if (
          position === POSITION.BOTTOM_LEFT ||
          position === POSITION.BOTTOM_RIGHT
        ) {
          console.warn(
            'Passing direction = down with position = bottomLeft/bottomRight is not suggested.'
          );
        } else {
          this.downAnimate();
        }
      }
    } else {
      this.upAnimate();
    }
  }

  fabOnPress() {
    if (this.props.onPress) {
      this.props.onPress();
      this._animate();
      this.activeTimer = setTimeout(() => {
        this.setState({
          active: this.props.active
        });
      }, 100);
    }
  }

  renderButtons() {
    const childrenArray = React.Children.toArray(this.props.children);
    const newChildren = [];
    childrenArray.slice(1).map((child, i) =>
      newChildren.push(
        <AnimatedFab
          style={this.getOtherButtonStyle(child, i)}
          {...this.prepareButtonProps(child, i)}
          fabButton
          key={i}
        >
          {child.props.children}
        </AnimatedFab>
      )
    );
    return newChildren;
  }

  renderFab() {
    const childrenArray = React.Children.toArray(this.props.children);
    remove(childrenArray, item => {
      if (item.type.displayName === 'Styled(Button)') {
        return true;
      }
      return null;
    });
    return React.cloneElement(childrenArray[0], {
      style: this.getInitialStyle(childrenArray[0].props.style).iconStyle
    });
  }

  render() {
    const { style } = this.props;
    return (
      <Animated.View style={this.getContainerStyle()}>
        {this.renderButtons()}
        {Platform.OS === PLATFORM.IOS ||
        variables.androidRipple === false ||
        Platform.Version <= 21 ? (
          <TouchableOpacity
            onPress={() => this.fabOnPress()}
            {...this.prepareFabProps()}
            activeOpacity={1}
          >
            {this.renderFab()}
          </TouchableOpacity>
        ) : (
          <TouchableNativeFeedback
            onPress={() => this.fabOnPress()}
            // eslint-disable-next-line new-cap
            background={TouchableNativeFeedback.Ripple(
              variables.androidRippleColor,
              false
            )}
            {...this.prepareFabProps()}
          >
            <View style={[this.getInitialStyle().fab, style]}>
              {this.renderFab()}
            </View>
          </TouchableNativeFeedback>
        )}
      </Animated.View>
    );
  }
}
const StyledFab = connectStyle('NativeBase.Fab', {}, mapPropsToStyleNames)(Fab);
export { StyledFab as Fab };
<commit_msg>added useNativeDriver:false to Animated.spring of Fab <commit_after>import React, { Component } from 'react';
import {
  Platform,
  Animated,
  TouchableOpacity,
  TouchableNativeFeedback,
  View,
  StyleSheet
} from 'react-native';
import { remove, merge, clone } from 'lodash';
import { connectStyle } from 'native-base-shoutem-theme';

import variables from '../theme/variables/platform';
import { PLATFORM } from '../theme/variables/commonColor';
import computeProps from '../utils/computeProps';
import mapPropsToStyleNames from '../utils/mapPropsToStyleNames';

import { Button } from './Button';

const DIRECTION = {
  DOWN: 'down',
  LEFT: 'left',
  RIGHT: 'right',
  UP: 'up'
};

const POSITION = {
  BOTTOM_LEFT: 'bottomLeft',
  BOTTOM_RIGHT: 'bottomRight',
  TOP_LEFT: 'topLeft',
  TOP_RIGHT: 'topRight'
};

const AnimatedFab = Animated.createAnimatedComponent(Button);

class Fab extends Component {
  constructor(props) {
    super(props);
    this.containerHeight = new Animated.Value(variables.fabWidth);
    this.containerWidth = new Animated.Value(0);
    this.buttonScale = new Animated.Value(0);
    this.state = {
      buttons: undefined,
      active: false
    };
  }

  componentDidMount() {
    const childrenArray = React.Children.toArray(this.props.children);
    const icon = remove(childrenArray, item => {
      if (item.type.displayName === 'Styled(Button)') {
        return true;
      }
      return null;
    });
    // eslint-disable-next-line react/no-did-mount-set-state
    this.setState({
      buttons: icon.length
    });
    this.activeTimer = setTimeout(() => {
      this.setState({
        active: this.props.active
      });
    }, 0);
  }

  componentWillUnmount() {
    if (this.activeTimer) {
      clearTimeout(this.activeTimer);
    }
  }

  getOtherButtonStyle(child, i) {
    const { active, direction } = this.props;
    const type = {
      top: direction ? this.fabOtherBtns(direction, i).top : undefined,
      left: direction ? this.fabOtherBtns(direction, i).left : 8,
      right: direction ? this.fabOtherBtns(direction, i).right : 0,
      bottom: direction
        ? this.fabOtherBtns(direction, i).bottom
        : active === false
        ? Platform.OS === PLATFORM.IOS
          ? 8
          : 8
        : i * 50 + 50
    };

    return merge(
      this.getInitialStyle().buttonStyle,
      StyleSheet.flatten(child.props.style),
      type
    );
  }

  getContainerStyle() {
    return merge(this.getInitialStyle().container, this.props.containerStyle);
  }

  getInitialStyle(iconStyle) {
    const { direction, position } = this.props;
    return {
      fab: {
        height: variables.fabWidth,
        width: variables.fabWidth,
        borderRadius: variables.fabBorderRadius,
        elevation: variables.fabElevation,
        shadowColor: variables.fabShadowColor,
        shadowOffset: {
          width: variables.fabShadowOffsetWidth,
          height: variables.fabShadowOffsetHeight
        },
        shadowOpacity: variables.fabShadowOpacity,
        justifyContent: 'center',
        alignItems: 'center',
        shadowRadius: variables.fabShadowRadius,
        position: 'absolute',
        bottom: variables.fabBottom,
        backgroundColor: variables.fabBackgroundColor
      },
      container: {
        position: 'absolute',
        top: position ? this.fabTopValue(position).top : undefined,
        bottom: position
          ? this.fabTopValue(position).bottom
          : variables.fabContainerBottom,
        right: position
          ? this.fabTopValue(position).right
          : variables.fabContainerBottom,
        left: position ? this.fabTopValue(position).left : undefined,
        width: variables.fabWidth,
        height: this.containerHeight,
        flexDirection: direction
          ? direction === DIRECTION.LEFT || direction === DIRECTION.RIGHT
            ? 'row'
            : 'column'
          : 'column',
        alignItems: 'center'
      },
      iconStyle: {
        color: variables.fabIconColor,
        fontSize: variables.fabIconSize,
        lineHeight: Platform.OS === PLATFORM.IOS ? 27 : undefined,
        ...iconStyle
      },
      buttonStyle: {
        position: 'absolute',
        height: variables.fabButtonHeight,
        width: variables.fabButtonHeight,
        left: variables.fabButtonLeft,
        borderRadius: variables.fabButtonBorderRadius,
        transform: this.state.active
          ? [{ scale: new Animated.Value(1) }]
          : [{ scale: this.buttonScale }],
        marginBottom: variables.fabButtonMarginBottom,
        backgroundColor: variables.fabBackgroundColor
      }
    };
  }

  prepareButtonProps = child => {
    const inp = clone(child.props);
    delete inp.style;

    const defaultProps = {};

    return computeProps(inp, defaultProps);
  };

  fabTopValue = pos => {
    if (pos === POSITION.TOP_LEFT) {
      return {
        top: variables.fabDefaultPosition,
        bottom: undefined,
        left: variables.fabDefaultPosition,
        right: undefined
      };
    } else if (pos === POSITION.BOTTOM_RIGHT) {
      return {
        top: undefined,
        bottom: variables.fabDefaultPosition,
        left: undefined,
        right: variables.fabDefaultPosition
      };
    } else if (pos === POSITION.BOTTOM_LEFT) {
      return {
        top: undefined,
        bottom: variables.fabDefaultPosition,
        left: variables.fabDefaultPosition,
        right: undefined
      };
    } else if (pos === POSITION.TOP_RIGHT) {
      return {
        top: variables.fabDefaultPosition,
        bottom: undefined,
        left: undefined,
        right: variables.fabDefaultPosition
      };
    }
    return null;
  };

  fabOtherBtns(direction, i) {
    const { active } = this.props;
    if (direction === DIRECTION.UP) {
      return {
        top: undefined,
        bottom:
          active === false
            ? Platform.OS === PLATFORM.IOS
              ? 50
              : 5
            : i * 50 + 65,
        left: 8,
        right: 0
      };
    } else if (direction === DIRECTION.LEFT) {
      return {
        top: 8,
        bottom: 0,
        left:
          active === false
            ? Platform.OS === PLATFORM.IOS
              ? 8
              : 8
            : -(i * 50 + variables.fabWidth + 2),
        right: 0
      };
    } else if (direction === DIRECTION.DOWN) {
      return {
        top:
          active === false
            ? Platform.OS === PLATFORM.IOS
              ? 50
              : 8
            : i * 50 + 73,
        bottom: 0,
        left: 8,
        right: 0
      };
    } else if (direction === DIRECTION.RIGHT) {
      return {
        top: 8,
        bottom: 0,
        left:
          active === false
            ? Platform.OS === PLATFORM.IOS
              ? 50
              : 8
            : i * 50 + 73,
        right: 0
      };
    }
    return null;
  }

  prepareFabProps() {
    const defaultProps = {
      style: this.getInitialStyle().fab
    };
    const incomingProps = clone(this.props);
    delete incomingProps.onPress;

    return computeProps(incomingProps, defaultProps);
  }

  upAnimate() {
    if (!this.props.active) {
      Animated.spring(this.containerHeight, {
        toValue: this.state.buttons * 51.3 + variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 1,
        useNativeDriver: true
      }).start();
    } else {
      this.setState({
        active: false
      });
      Animated.spring(this.containerHeight, {
        toValue: variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 0,
        useNativeDriver: true
      }).start();
    }
  }

  leftAnimate() {
    if (!this.props.active) {
      Animated.spring(this.containerWidth, {
        toValue: this.state.buttons * 51.3 + variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 1,
        useNativeDriver: true
      }).start();
    } else {
      this.setState({
        active: false
      });
      Animated.spring(this.containerHeight, {
        toValue: variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 0,
        useNativeDriver: true
      }).start();
    }
  }

  rightAnimate() {
    if (!this.props.active) {
      Animated.spring(this.containerWidth, {
        toValue: this.state.buttons * 51.3 + variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 1,
        useNativeDriver: true
      }).start();
    } else {
      this.setState({
        active: false
      });
      Animated.spring(this.containerHeight, {
        toValue: variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 0,
        useNativeDriver: true
      }).start();
    }
  }

  downAnimate() {
    if (!this.props.active) {
      Animated.spring(this.containerHeight, {
        toValue: variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 1,
        useNativeDriver: true
      }).start();
    } else {
      this.setState({
        active: false
      });
      Animated.spring(this.containerHeight, {
        toValue: variables.fabWidth,
        useNativeDriver: false
      }).start();
      Animated.spring(this.buttonScale, {
        toValue: 0,
        useNativeDriver: true
      }).start();
    }
  }
  _animate() {
    const {
      props: { direction, position }
    } = this;

    if (direction) {
      if (direction === DIRECTION.UP) {
        if (position === POSITION.TOP_LEFT || position === POSITION.TOP_RIGHT) {
          console.warn(
            'Passing direction = up with position = topLeft/topRight is not suggested.'
          );
        } else {
          this.upAnimate();
        }
      } else if (direction === DIRECTION.LEFT) {
        if (
          position === POSITION.TOP_LEFT ||
          position === POSITION.BOTTOM_LEFT
        ) {
          console.warn(
            'Passing direction = left with position = topLeft/bottomLeft is not suggested.'
          );
        } else {
          this.leftAnimate();
        }
      } else if (direction === DIRECTION.RIGHT) {
        if (
          position === POSITION.TOP_RIGHT ||
          position === POSITION.BOTTOM_RIGHT
        ) {
          console.warn(
            'Passing direction = right with position = topRight/bottomRight is not suggested.'
          );
        } else {
          this.rightAnimate();
        }
      } else if (direction === DIRECTION.DOWN) {
        if (
          position === POSITION.BOTTOM_LEFT ||
          position === POSITION.BOTTOM_RIGHT
        ) {
          console.warn(
            'Passing direction = down with position = bottomLeft/bottomRight is not suggested.'
          );
        } else {
          this.downAnimate();
        }
      }
    } else {
      this.upAnimate();
    }
  }

  fabOnPress() {
    if (this.props.onPress) {
      this.props.onPress();
      this._animate();
      this.activeTimer = setTimeout(() => {
        this.setState({
          active: this.props.active
        });
      }, 100);
    }
  }

  renderButtons() {
    const childrenArray = React.Children.toArray(this.props.children);
    const newChildren = [];
    childrenArray.slice(1).map((child, i) =>
      newChildren.push(
        <AnimatedFab
          style={this.getOtherButtonStyle(child, i)}
          {...this.prepareButtonProps(child, i)}
          fabButton
          key={i}
        >
          {child.props.children}
        </AnimatedFab>
      )
    );
    return newChildren;
  }

  renderFab() {
    const childrenArray = React.Children.toArray(this.props.children);
    remove(childrenArray, item => {
      if (item.type.displayName === 'Styled(Button)') {
        return true;
      }
      return null;
    });
    return React.cloneElement(childrenArray[0], {
      style: this.getInitialStyle(childrenArray[0].props.style).iconStyle
    });
  }

  render() {
    const { style } = this.props;
    return (
      <Animated.View style={this.getContainerStyle()}>
        {this.renderButtons()}
        {Platform.OS === PLATFORM.IOS ||
        variables.androidRipple === false ||
        Platform.Version <= 21 ? (
          <TouchableOpacity
            onPress={() => this.fabOnPress()}
            {...this.prepareFabProps()}
            activeOpacity={1}
          >
            {this.renderFab()}
          </TouchableOpacity>
        ) : (
          <TouchableNativeFeedback
            onPress={() => this.fabOnPress()}
            // eslint-disable-next-line new-cap
            background={TouchableNativeFeedback.Ripple(
              variables.androidRippleColor,
              false
            )}
            {...this.prepareFabProps()}
          >
            <View style={[this.getInitialStyle().fab, style]}>
              {this.renderFab()}
            </View>
          </TouchableNativeFeedback>
        )}
      </Animated.View>
    );
  }
}
const StyledFab = connectStyle('NativeBase.Fab', {}, mapPropsToStyleNames)(Fab);
export { StyledFab as Fab };
<|endoftext|>


<commit_before>(function () {
  "use strict";

  function receiveMessage(event) {
    if (event.data.url) {
      setTimeout(function(){
        try {
          window.top.location = event.data.url;
        }
        catch(err) {
          document.location = event.data.url;
        }
      }, 500);
    };
    return false;
  }

  window.addEventListener("message", receiveMessage, false);

  var BeGateway = function (options) {
    if (!options.url) {
      return false;
    };

    this.url = options.url;
    this.styles = options.style;
    this.type = options.type;
    this.anchor = options.id;
    this.iframeDivId = 'beGatewayForm';

    if (options.size) {
      this.size = options.size;
    } else {
      this.size = { height: 480, width: 320 };
    };
  };

  BeGateway.prototype.isMobile = function () {
    if ( navigator.userAgent.match(/Android/i) ||
      navigator.userAgent.match(/iPhone/i) ||
      navigator.userAgent.match(/Windows Phone/i) ) {
      return true;
    } else {
      return false;
    }
  }

  BeGateway.prototype.prepareIframe = function (url) {
    var iframeDiv = document.createElement("div");
    iframeDiv.setAttribute("id", this.iframeDivId);
    iframeDiv.style.display = "none";

    var iframe = document.createElement("IFRAME");
    iframe.setAttribute("src", url);
    iframe.setAttribute("frameborder", "0");
    iframe.style.display = "block";
    iframe.style.margin = "auto";

    if (this.size) {
      iframe.style.width = this.size.width + "px";
      iframe.style.height = this.size.height + "px";
    };

    iframeDiv.appendChild(iframe);

    if (this.anchor && document.getElementById(this.anchor)) {
      document.getElementById(this.anchor).appendChild(iframeDiv);
    } else {
      document.body.appendChild(iframeDiv);
    };

    var styles = this.styles;
    var size = this.size;

    iframe.onload = function() {
      iframe.contentWindow.postMessage({ css: styles }, "*");
      if ($('#closeWindow').size() == 0) {
        $('.ui-dialog').prepend("
");
        $("a#closeWindow").css("left", size.width);

        $('a#closeWindow').click(function(e) {
          e.preventDefault();
          $('#dialogWindowBeGateway').dialog('close');
        });

      };
    };
    return iframe;
  }

  BeGateway.prototype.buildOverlayForm = function (url) {
    var linkId = '#' + this.anchor;
    var size = this.size;
    var that = this;
    var dialogId = "dialogWindowBeGateway";

    var emptyDiv = document.createElement('div');
    emptyDiv.setAttribute("id", dialogId);
    document.body.appendChild(emptyDiv);

    var reg = new RegExp('([http|https].+\/)checkout')
    var path =  reg.exec(this.url)[1];
    var cssPath = path + 'stylesheets/jquery-ui.min.css'
    $('body').append('<link rel="stylesheet" href="' + cssPath + '">');

    $(linkId).click(function(event) {
      event.preventDefault();

      if (that.isMobile()) {
        window.open(that.url);
        return false;
      }

      var new_width = size.width + 10;
      var new_height = size.height + 10;

      $('#' + dialogId).dialog({
        dialogClass: dialogId,
        modal: true,
        width: new_width,
        height: new_height,
        show: {
          effect: "fadeIn"
        },
        hide: {
          effect: "fadeOut"
        },
        open: function () {
          if ($('#' + dialogId).children('iframe').size() == 0) {
            document.getElementById(dialogId).appendChild(that.prepareIframe(url + "&iframe=overlay"));
          };
          $('#' + dialogId).css("cssText",
            "width: " + new_width + "px !important;" +
            "max-width: " + new_width + "px !important;" +
            "max-height:" + new_height + "px !important;" +
            "height: " + new_height + "px !important;" +
            "overflow-x: hidden; overflow-y: hidden;");
        }
      });
    });
  };

  BeGateway.prototype.buildInlineForm = function(url) {
    url = url + "&iframe=inline";

    this.prepareIframe(url);
    $('#' + this.iframeDivId).show();
  }

  BeGateway.prototype.buildForm = function () {
    if (options.style) {
      this.styles = options.style;
    };

    if (this.type == 'overlay') {
      this.buildOverlayForm(this.url);
      return false;
    };

    if (this.type == 'inline') {
      this.buildInlineForm(this.url);
      return false;
    };
  };

  window.BeGateway = BeGateway;
}());
<commit_msg>Add spinner when iframe is loading.<commit_after>(function () {
  "use strict";

  function receiveMessage(event) {
    if (event.data.url) {
      setTimeout(function(){
        try {
          window.top.location = event.data.url;
        }
        catch(err) {
          document.location = event.data.url;
        }
      }, 500);
    };
    return false;
  }

  window.addEventListener("message", receiveMessage, false);

  var BeGateway = function (options) {
    if (!options.url) {
      return false;
    };

    this.url = options.url;
    this.styles = options.style;
    this.type = options.type;
    this.anchor = options.id;
    this.iframeDivId = 'beGatewayForm';

    if (options.size) {
      this.size = options.size;
    } else {
      this.size = { height: 480, width: 320 };
    };
  };

  BeGateway.prototype.isMobile = function () {
    if ( navigator.userAgent.match(/Android/i) ||
      navigator.userAgent.match(/iPhone/i) ||
      navigator.userAgent.match(/Windows Phone/i) ) {
      return true;
    } else {
      return false;
    }
  }

  BeGateway.prototype.showSpinner = function(){
    $('#' + this.anchor).append(
      "

");
    $('.spinner').css('position', 'absolute').css('left', '45%').css('top', '28%');
  };
  BeGateway.prototype.hideSpinner = function(){
    $('img.beSpinner').remove();
  };

  BeGateway.prototype.prepareIframe = function (url) {
    var iframeDiv = document.createElement("div");
    $(iframeDiv).attr("id", this.iframeDivId);

    this.showSpinner();
    $(iframeDiv).hide();

    var iframe = document.createElement("IFRAME");
    iframe.setAttribute("src", url);
    iframe.setAttribute("frameborder", "0");
    iframe.style.display = "block";
    iframe.style.margin = "auto";

    if (this.size) {
      iframe.style.width = this.size.width + "px";
      iframe.style.height = this.size.height + "px";
    };

    iframeDiv.appendChild(iframe);

    if (this.anchor && document.getElementById(this.anchor)) {
      document.getElementById(this.anchor).appendChild(iframeDiv);
    } else {
      document.body.appendChild(iframeDiv);
    };

    var styles = this.styles;
    var size = this.size;
    var that = this;

    iframe.onload = function() {
      iframe.contentWindow.postMessage({ css: styles }, "*");

      if ($('#closeWindow').size() == 0) {
        $('.ui-dialog').prepend("
");
        $("a#closeWindow").css("left", size.width);

        $('a#closeWindow').click(function(e) {
          e.preventDefault();
          $('#dialogWindowBeGateway').dialog('close');
        });
      };

      that.hideSpinner();
      $(iframeDiv).show();
    };

    return iframe;
  }

  BeGateway.prototype.buildOverlayForm = function (url) {
    var linkId = '#' + this.anchor;
    var size = this.size;
    var that = this;
    var dialogId = "dialogWindowBeGateway";

    var emptyDiv = document.createElement('div');
    emptyDiv.setAttribute("id", dialogId);
    document.body.appendChild(emptyDiv);

    var reg = new RegExp('([http|https].+\/)checkout')
    var path =  reg.exec(this.url)[1];
    var cssPath = path + 'stylesheets/jquery-ui.min.css'
    $('body').append('<link rel="stylesheet" href="' + cssPath + '">');

    $(linkId).click(function(event) {
      event.preventDefault();

      if (that.isMobile()) {
        window.open(that.url);
        return false;
      }

      var new_width = size.width + 10;
      var new_height = size.height + 10;

      $('#' + dialogId).dialog({
        dialogClass: dialogId,
        modal: true,
        width: new_width,
        height: new_height,
        show: {
          effect: "fadeIn"
        },
        hide: {
          effect: "fadeOut"
        },
        open: function () {
          if ($('#' + dialogId).children('iframe').size() == 0) {
            document.getElementById(dialogId).appendChild(that.prepareIframe(url + "&iframe=overlay"));
          };
          $('#' + dialogId).css("cssText",
            "width: " + new_width + "px !important;" +
            "max-width: " + new_width + "px !important;" +
            "max-height:" + new_height + "px !important;" +
            "height: " + new_height + "px !important;" +
            "overflow-x: hidden; overflow-y: hidden;");
        }
      });
    });
  };

  BeGateway.prototype.buildInlineForm = function(url) {
    url = url + "&iframe=inline";
    this.prepareIframe(url);
  }

  BeGateway.prototype.buildForm = function () {
    if (options.style) {
      this.styles = options.style;
    };

    if (this.type == 'overlay') {
      this.buildOverlayForm(this.url);
      return false;
    };

    if (this.type == 'inline') {
      this.buildInlineForm(this.url);
      return false;
    };
  };

  window.BeGateway = BeGateway;
}());
<|endoftext|>


<commit_before>import { bfs } from './bfs';

/*jshint loopfunc:true */
export const bfs_order = (graph, comps) => {
  if (!comps) comps = graph.components();

  let i;
  let comp;
  const order = [];

  for (i = 0; i < comps.length; i++) {
    comp = comps[i];
    bfs(graph, comp[0], (v, c) => {
      if (c >= 0 && v != c) order.push(v);
    });
  }
  return order;
};
<commit_msg>Manual cleanup of bfs_order.js<commit_after>import { bfs } from './bfs';

/*jshint loopfunc:true */
export const bfs_order = (graph, comps) => {
  if (!comps) comps = graph.components();

  const order = [];

  for (let i = 0; i < comps.length; i++) {
    const comp = comps[i];
    bfs(graph, comp[0], (v, c) => {
      if (c >= 0 && v != c) order.push(v);
    });
  }

  return order;
};
<|endoftext|>


<commit_before>const { Knorm } = require('@knorm/knorm');
const { camelCase } = require('lodash');

const isArray = Array.isArray;
const asArray = value => (Array.isArray(value) ? value : [value]);

const addReference = (references, field, reference) => {
  const toModel = reference.model;
  references[toModel.name] = references[toModel.name] || {};
  references[toModel.name][field.name] = field;
};

class KnormRelations {
  constructor({ name = 'relations' } = {}) {
    this.name = name;
  }

  updateField(knorm) {
    const { Field } = knorm;

    class RelationsField extends Field {
      constructor(config = {}) {
        super(config);
        if (config.references) {
          this.references = config.references;
        }
      }
    }

    knorm.updateField(RelationsField);
  }

  updateModel(knorm) {
    const { Model } = knorm;

    class RelationsModel extends Model {
      static createConfig() {
        const config = super.createConfig();
        // NOTE: `rawReferences` is added to prevent breaking changes
        config.rawReferences = {};
        config.references = {};
        config.referenceFunctions = {};
        return config;
      }

      static addField(field) {
        super.addField(field);

        if (field.references) {
          const references = field.references;

          this._config.rawReferences[field.name] = references;

          if (typeof references === 'function') {
            this._config.referenceFunctions[field.name] = references;
          } else {
            (isArray(references) ? references : [references]).forEach(
              reference => {
                addReference(this._config.references, field, reference);
              }
            );
          }
        }
      }

      static removeField(field) {
        super.removeField(field);

        const { name, references } = field;

        if (references) {
          delete this._config.rawReferences[name];

          if (typeof references === 'function') {
            delete this._config.referenceFunctions[name];
          } else {
            const model = references.model.name;
            delete this._config.references[model][name];
            if (!Object.keys(this._config.references[model]).length) {
              delete this._config.references[model];
            }
          }
        }
      }

      // TODO: v3: make async
      // TODO: v3: unit test Model.getReferences
      static getReferences(Model) {
        const allReferences = this._config.rawReferences;
        const resolvedReferences = [];

        for (const [key, value] of Object.entries(allReferences)) {
          const fieldName = key;
          // TODO: any params to pass to the function?
          // TODO: v3: allow function to be async
          const references = typeof value === 'function' ? value() : value;

          for (const reference of asArray(references)) {
            // TODO: validate that reference is Field instance?
            if (
              reference.model === Model ||
              Model.prototype instanceof reference.model
            ) {
              resolvedReferences.push({
                // TODO: Model.getField()
                from: this._config._fields[fieldName],
                to: reference
              });
            }
          }
        }

        return resolvedReferences;
      }
    }

    knorm.updateModel(RelationsModel);
  }

  updateQuery(knorm) {
    const { Query, Model } = knorm;

    class RelationsQuery extends Query {
      constructor(model) {
        super(model);
        // TODO: only initialize parsedRows when needed
        this.parsedRows = new Map();
        this.config.references = model.config.references;
        this.config.referenceFunctions = model.config.referenceFunctions;
      }

      addJoin(type, joins, options) {
        if (!isArray(joins)) {
          joins = [joins];
        }

        // TODO: use appendOption
        this.options.joins = this.options.joins || [];

        joins.forEach(join => {
          if (join.prototype instanceof Model) {
            join = join.query;
          }

          join.options.joinType = type;
          join.setOptions(options);

          this.options.joins.push(join);
        });

        return this;
      }

      leftJoin(queries, options) {
        return this.addJoin('leftJoin', queries, options);
      }

      innerJoin(queries, options) {
        return this.addJoin('innerJoin', queries, options);
      }

      join(queries, options) {
        return this.addJoin('join', queries, options);
      }

      // TODO: require setting `as` when configuring references
      as(as) {
        return this.setOption('as', as);
      }

      // TODO: v2: support multiple fields for `on` via Query.prototpye.appendOption
      // TODO: support raw sql
      on(field) {
        return this.addOption('on', field);
      }

      prepareOn() {
        const join = this;
        const parent = this.parent;
        const joinReferences = join.model.getReferences(parent.model);
        const parentReferences = parent.model.getReferences(join.model);

        if (!parentReferences.length && !joinReferences.length) {
          throw new Query.QueryError(
            `${parent.model.name}: there are no references to \`${
              join.model.name
            }\``
          );
        }

        const isReverseJoin = !!parentReferences.length;
        let references = joinReferences.concat(parentReferences);

        if (this.options.on) {
          const filteredReferences = [];

          for (let field of this.options.on) {
            if (typeof field === 'string') {
              // TODO: join.model.getField(field)
              field = join.model._config._fields[field];
            }
            for (const reference of references) {
              if (reference.from === field || reference.to === field) {
                filteredReferences.push(reference);
              }
            }
          }

          references = filteredReferences;
        }

        const columns = {};

        for (const { from, to } of references) {
          let fromColumn;
          let toColumn;

          if (isReverseJoin) {
            fromColumn = parent.formatColumn(from.column);
            toColumn = join.formatColumn(to.column);
          } else {
            fromColumn = join.formatColumn(from.column);
            toColumn = parent.formatColumn(to.column);
          }

          columns[fromColumn] = toColumn;
        }

        return columns;
      }

      async prepareJoin(sql) {
        const method = this.options.joinType || 'leftJoin';
        sql[method](this.getTable(), this.prepareOn());

        this.ensureFields();
        return this.prepareSql(sql);
      }

      ensureUniqueField(to) {
        if (this.options.fields === false) {
          // if no fields are requested then no need checking for unique fields
          return;
        }

        const aliases = Object.keys(this.options.fields);

        if (to.options.fields === false) {
          // if no fields are requested on the joined query use any field as
          // unique
          this.options.unique = aliases[0];
          return;
        }

        const fields = Object.values(this.options.fields);
        let unique;

        [this.config.primary].concat(this.config.unique).some(field => {
          const index = fields.indexOf(field);
          if (index > -1) {
            unique = aliases[index];
            return true;
          }
          return false;
        });

        if (!unique) {
          throw new Query.QueryError(
            `${this.model.name}: cannot join \`${
              to.model.name
            }\` with no primary or unique fields selected`
          );
        }

        this.options.unique = unique;
      }

      async prepareJoins(sql) {
        return Promise.all(
          this.options.joins.map(async join => {
            this.ensureUniqueField(join);

            join.parent = this;
            // depended on by @knorm/postgres
            join.config.joined = true;
            join.config.index = ++this.config.index;
            // TODO: support custom aliases
            join.config.alias = `${join.config.alias}_${join.config.index}`;
            // propagate the forFetch option to nested joins
            join.config.forFetch = true;

            // TODO: remove
            if (!join.options.as) {
              join.options.as = camelCase(join.model.name);
            }

            return join.prepareJoin(sql);
          })
        );
      }

      ensureFields() {
        super.ensureFields();
      }

      async prepareSql(sql) {
        sql = await super.prepareSql(sql);

        if (this.options.joins) {
          await this.prepareJoins(sql);
        }

        return sql;
      }

      throwFetchRequireError() {
        super.throwFetchRequireError();

        if (this.options.joins) {
          this.options.joins.forEach(join => join.throwFetchRequireError());
        }
      }

      // TODO: strict mode: throw if the value for the unique field is null or undefined
      getParsedRow(row) {
        let parsedRow = super.getParsedRow(row);

        if (!this.options.joins) {
          return parsedRow;
        }

        if (this.options.fields === false) {
          return parsedRow;
        }

        const unique =
          row[this.formatFieldAlias(this.options.unique, { quote: false })];

        if (unique) {
          const uniqueRow = this.parsedRows.get(unique);
          if (uniqueRow) {
            parsedRow = uniqueRow;
          } else {
            this.parsedRows.set(unique, parsedRow);
          }
        }

        return parsedRow;
      }

      parseRow(row) {
        const parsedRow = super.parseRow(row);

        if (this.options.joins) {
          this.options.joins.forEach(join => {
            const as = join.options.as;
            const first = join.options.first;

            const data = join.parseRow(row);
            // the performance of this check could be improved by checking row
            // values while parsing the row but at a cost to code complexity
            const isEmpty = Object.values(data).every(
              // TODO: the array check will also deem empty postgres arrays or
              // JSON arrays as empty/null values. do we want that?
              value => value === null || (isArray(value) && !value.length)
            );

            // TODO: strict mode: warn if joined data replaces already existing
            // fields on the row
            if (isEmpty) {
              parsedRow[as] = first ? null : [];
            } else if (first) {
              if (!parsedRow[as] || !parsedRow[as].knorm) {
                parsedRow[as] = data;
              }
            } else {
              if (!isArray(parsedRow[as])) {
                parsedRow[as] = [];
              }
              parsedRow[as].push(data);
            }
          });
        }

        return parsedRow;
      }

      parseRows(rows) {
        const parsedRows = super.parseRows(rows);

        if (this.options.joins) {
          return Array.from(this.parsedRows.values());
        }

        return parsedRows;
      }
    }

    knorm.updateQuery(RelationsQuery);
  }

  init(knorm) {
    if (!knorm) {
      throw new this.constructor.KnormRelationsError(
        'no Knorm instance provided'
      );
    }

    if (!(knorm instanceof Knorm)) {
      throw new this.constructor.KnormRelationsError(
        'invalid Knorm instance provided'
      );
    }

    this.updateModel(knorm);
    this.updateField(knorm);
    this.updateQuery(knorm);
  }
}

KnormRelations.KnormRelationsError = class KnormRelationsError extends Knorm.KnormError {};

module.exports = KnormRelations;
<commit_msg>chore: update TODOs<commit_after>const { Knorm } = require('@knorm/knorm');
const { camelCase } = require('lodash');

const isArray = Array.isArray;
const asArray = value => (Array.isArray(value) ? value : [value]);

const addReference = (references, field, reference) => {
  const toModel = reference.model;
  references[toModel.name] = references[toModel.name] || {};
  references[toModel.name][field.name] = field;
};

class KnormRelations {
  constructor({ name = 'relations' } = {}) {
    this.name = name;
  }

  updateField(knorm) {
    const { Field } = knorm;

    class RelationsField extends Field {
      constructor(config = {}) {
        super(config);
        if (config.references) {
          this.references = config.references;
        }
      }
    }

    knorm.updateField(RelationsField);
  }

  updateModel(knorm) {
    const { Model } = knorm;

    class RelationsModel extends Model {
      static createConfig() {
        const config = super.createConfig();
        // NOTE: `rawReferences` is added to prevent breaking changes
        config.rawReferences = {};
        config.references = {};
        config.referenceFunctions = {};
        return config;
      }

      static addField(field) {
        super.addField(field);

        if (field.references) {
          const references = field.references;

          this._config.rawReferences[field.name] = references;

          if (typeof references === 'function') {
            this._config.referenceFunctions[field.name] = references;
          } else {
            (isArray(references) ? references : [references]).forEach(
              reference => {
                addReference(this._config.references, field, reference);
              }
            );
          }
        }
      }

      static removeField(field) {
        super.removeField(field);

        const { name, references } = field;

        if (references) {
          delete this._config.rawReferences[name];

          if (typeof references === 'function') {
            delete this._config.referenceFunctions[name];
          } else {
            const model = references.model.name;
            delete this._config.references[model][name];
            if (!Object.keys(this._config.references[model]).length) {
              delete this._config.references[model];
            }
          }
        }
      }

      // TODO: v3: make async
      // TODO: v3: unit test Model.getReferences
      static getReferences(Model) {
        const allReferences = this._config.rawReferences;
        const resolvedReferences = [];

        for (const [key, value] of Object.entries(allReferences)) {
          const fieldName = key;
          // TODO: any params to pass to the function?
          // TODO: v3: allow function to be async
          const references = typeof value === 'function' ? value() : value;

          for (const reference of asArray(references)) {
            // TODO: validate that reference is Field instance?
            if (
              reference.model === Model ||
              Model.prototype instanceof reference.model
            ) {
              resolvedReferences.push({
                // TODO: v3: Model.getField()
                from: this._config._fields[fieldName],
                to: reference
              });
            }
          }
        }

        return resolvedReferences;
      }
    }

    knorm.updateModel(RelationsModel);
  }

  updateQuery(knorm) {
    const { Query, Model } = knorm;

    class RelationsQuery extends Query {
      constructor(model) {
        super(model);
        // TODO: only initialize parsedRows when needed
        this.parsedRows = new Map();
        this.config.references = model.config.references;
        this.config.referenceFunctions = model.config.referenceFunctions;
      }

      addJoin(type, joins, options) {
        if (!isArray(joins)) {
          joins = [joins];
        }

        // TODO: use appendOption
        this.options.joins = this.options.joins || [];

        joins.forEach(join => {
          if (join.prototype instanceof Model) {
            join = join.query;
          }

          join.options.joinType = type;
          join.setOptions(options);

          this.options.joins.push(join);
        });

        return this;
      }

      leftJoin(queries, options) {
        return this.addJoin('leftJoin', queries, options);
      }

      innerJoin(queries, options) {
        return this.addJoin('innerJoin', queries, options);
      }

      join(queries, options) {
        return this.addJoin('join', queries, options);
      }

      // TODO: require setting `as` when configuring references
      as(as) {
        return this.setOption('as', as);
      }

      // TODO: v2: support multiple fields for `on` via Query.prototpye.appendOption
      // TODO: support raw sql
      on(field) {
        return this.addOption('on', field);
      }

      prepareOn() {
        const join = this;
        const parent = this.parent;
        const joinReferences = join.model.getReferences(parent.model);
        const parentReferences = parent.model.getReferences(join.model);

        if (!parentReferences.length && !joinReferences.length) {
          throw new Query.QueryError(
            `${parent.model.name}: there are no references to \`${
              join.model.name
            }\``
          );
        }

        const isReverseJoin = !!parentReferences.length;
        let references = joinReferences.concat(parentReferences);

        if (this.options.on) {
          const filteredReferences = [];

          for (let field of this.options.on) {
            if (typeof field === 'string') {
              // TODO: v3: join.model.getField(field)
              field = join.model._config._fields[field];
            }
            for (const reference of references) {
              if (reference.from === field || reference.to === field) {
                filteredReferences.push(reference);
              }
            }
          }

          references = filteredReferences;
        }

        const columns = {};

        for (const { from, to } of references) {
          let fromColumn;
          let toColumn;

          if (isReverseJoin) {
            fromColumn = parent.formatColumn(from.column);
            toColumn = join.formatColumn(to.column);
          } else {
            fromColumn = join.formatColumn(from.column);
            toColumn = parent.formatColumn(to.column);
          }

          columns[fromColumn] = toColumn;
        }

        return columns;
      }

      async prepareJoin(sql) {
        const method = this.options.joinType || 'leftJoin';
        sql[method](this.getTable(), this.prepareOn());

        this.ensureFields();
        return this.prepareSql(sql);
      }

      ensureUniqueField(to) {
        if (this.options.fields === false) {
          // if no fields are requested then no need checking for unique fields
          return;
        }

        const aliases = Object.keys(this.options.fields);

        if (to.options.fields === false) {
          // if no fields are requested on the joined query use any field as
          // unique
          this.options.unique = aliases[0];
          return;
        }

        const fields = Object.values(this.options.fields);
        let unique;

        [this.config.primary].concat(this.config.unique).some(field => {
          const index = fields.indexOf(field);
          if (index > -1) {
            unique = aliases[index];
            return true;
          }
          return false;
        });

        if (!unique) {
          throw new Query.QueryError(
            `${this.model.name}: cannot join \`${
              to.model.name
            }\` with no primary or unique fields selected`
          );
        }

        this.options.unique = unique;
      }

      async prepareJoins(sql) {
        return Promise.all(
          this.options.joins.map(async join => {
            this.ensureUniqueField(join);

            join.parent = this;
            // depended on by @knorm/postgres
            join.config.joined = true;
            join.config.index = ++this.config.index;
            // TODO: support custom aliases
            join.config.alias = `${join.config.alias}_${join.config.index}`;
            // propagate the forFetch option to nested joins
            join.config.forFetch = true;

            // TODO: remove
            if (!join.options.as) {
              join.options.as = camelCase(join.model.name);
            }

            return join.prepareJoin(sql);
          })
        );
      }

      ensureFields() {
        super.ensureFields();
      }

      async prepareSql(sql) {
        sql = await super.prepareSql(sql);

        if (this.options.joins) {
          await this.prepareJoins(sql);
        }

        return sql;
      }

      throwFetchRequireError() {
        super.throwFetchRequireError();

        if (this.options.joins) {
          this.options.joins.forEach(join => join.throwFetchRequireError());
        }
      }

      // TODO: strict mode: throw if the value for the unique field is null or undefined
      getParsedRow(row) {
        let parsedRow = super.getParsedRow(row);

        if (!this.options.joins) {
          return parsedRow;
        }

        if (this.options.fields === false) {
          return parsedRow;
        }

        const unique =
          row[this.formatFieldAlias(this.options.unique, { quote: false })];

        if (unique) {
          const uniqueRow = this.parsedRows.get(unique);
          if (uniqueRow) {
            parsedRow = uniqueRow;
          } else {
            this.parsedRows.set(unique, parsedRow);
          }
        }

        return parsedRow;
      }

      parseRow(row) {
        const parsedRow = super.parseRow(row);

        if (this.options.joins) {
          this.options.joins.forEach(join => {
            const as = join.options.as;
            const first = join.options.first;

            const data = join.parseRow(row);
            // the performance of this check could be improved by checking row
            // values while parsing the row but at a cost to code complexity
            const isEmpty = Object.values(data).every(
              // TODO: the array check will also deem empty postgres arrays or
              // JSON arrays as empty/null values. do we want that?
              value => value === null || (isArray(value) && !value.length)
            );

            // TODO: strict mode: warn if joined data replaces already existing
            // fields on the row
            if (isEmpty) {
              parsedRow[as] = first ? null : [];
            } else if (first) {
              if (!parsedRow[as] || !parsedRow[as].knorm) {
                parsedRow[as] = data;
              }
            } else {
              if (!isArray(parsedRow[as])) {
                parsedRow[as] = [];
              }
              parsedRow[as].push(data);
            }
          });
        }

        return parsedRow;
      }

      parseRows(rows) {
        const parsedRows = super.parseRows(rows);

        if (this.options.joins) {
          return Array.from(this.parsedRows.values());
        }

        return parsedRows;
      }
    }

    knorm.updateQuery(RelationsQuery);
  }

  init(knorm) {
    if (!knorm) {
      throw new this.constructor.KnormRelationsError(
        'no Knorm instance provided'
      );
    }

    if (!(knorm instanceof Knorm)) {
      throw new this.constructor.KnormRelationsError(
        'invalid Knorm instance provided'
      );
    }

    this.updateModel(knorm);
    this.updateField(knorm);
    this.updateQuery(knorm);
  }
}

KnormRelations.KnormRelationsError = class KnormRelationsError extends Knorm.KnormError {};

module.exports = KnormRelations;
<|endoftext|>


<commit_before>/*
 * 2010-2016 Sellermania / Froggy Commerce / 23Prod SARL
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to team@froggy-commerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade your module to newer
 * versions in the future.
 *
 *  @author         Froggy Commerce <team@froggy-commerce.com>
 *  @copyright      2010-2016 Sellermania / Froggy Commerce / 23Prod SARL
 *  @version        1.0
 *  @license        http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

$(document).ready(function() {

    // Hide PDF invoice link on orders list when the order status contains "Sellermania"
    $('#order div table tbody tr').each(function() {
        hidePDFButtons($(this));
    });

    $('#form-order div div table tbody tr').each(function() {
        hidePDFButtons($(this));
    });

    function hidePDFButtons(line)
    {
        var column = 0;
        var id_order = 0;
        var flag_sellermania = 0;

        line.find('td').each(function() {
            if (column == 1) {
                id_order = $(this).text();
            }
            else if (column == 8 && line.text().trim().toLowerCase().indexOf("marketplace") >= 0) {
                flag_sellermania = 1;
            }
            else if (column == 10 && flag_sellermania == 1) {
                $(this).find('a').each(function() {
                    if ($(this).attr('href').indexOf("generateInvoicePDF") >= 0) {
                        $(this).attr('href', sellermania_invoice_url + '&id_order=' + id_order);
                    } else {
                        $(this).remove();
                    }
                });
            }
            column++;
        });
    }

	if (nb_sellermania_orders_in_error > 0) {
        $('#order').before('
' + nb_sellermania_orders_in_error + ' ' + txt_sellermania_orders_in_error + '
');
    }

    /**
     * Handle Orders Bulk Action
     */

    html_bulk_actions = '

';

    html_bulk_actions += '
';
    html_bulk_actions += ' ' + txt_sellermania_confirm_orders;
    html_bulk_actions += '
';

    html_bulk_actions += '
';
    html_bulk_actions += ' ' + txt_sellermania_send_orders;
    html_bulk_actions += '
';

    $('.bulk-actions .dropdown-menu').append(html_bulk_actions);

    $('#sellermania-bulk-confirm-orders').click(function() {
        handleOrdersBulkAction($(this), 'bulk-confirm-orders');
        return false;
    });

    $('#sellermania-bulk-send-orders').click(function() {
        handleOrdersBulkAction($(this), 'bulk-send-orders');
        return false;
    });

    function handleOrdersBulkAction(self, sellermania_action)
    {
        // Retrieve selected orders
        var selected_orders = getSelectedOrders(self.closest('form').get(0), 'orderBox[]', true);
        if (selected_orders.length < 1) {
            alert(txt_sellermania_select_at_least_one_order);
            return false;
        }

        // Retrieve carrier
        var carrier = '';
        if (sellermania_action == 'bulk-send-orders') {
            var carrier = window.prompt(txt_sellermania_carrier_selection, sellermania_default_carrier);
        }

        // Post values
        var post_values = { sellermania_bulk_action: sellermania_action, sellermania_selected_orders: JSON.stringify(selected_orders), sellermania_carrier: carrier};
        $.post(sellermania_admin_orders_url, post_values).done(function(data) {
            var result = JSON.parse(data);
            if (result.result == 'OK') {
                var confirmation_message = txt_sellermania_orders_updated;
                for (var i in result.result_details.OrderItemConfirmationStatus) {
                    var conf_status = result.result_details.OrderItemConfirmationStatus[i];
                    confirmation_message += "\n#" + conf_status.id_order_prestashop + ' (sku: ' + conf_status.sku + ') : ';
                    if (conf_status.Status == 'ERROR') {
                        confirmation_message += conf_status.Message;
                    } else {
                        confirmation_message += conf_status.Status;
                    }
                }
                alert(confirmation_message);
            } else {
                alert(txt_sellermania_error_occured);
            }
        });
    }

    function getSelectedOrders(pForm, boxName, parent)
    {
        var boxes = [];
        for (i = 0; i < pForm.elements.length; i++) {
            if (pForm.elements[i].name == boxName && pForm.elements[i].checked == true) {
                boxes.push(pForm.elements[i].value);
            }
        }
        return boxes;
    }

});
<commit_msg>Quick fix<commit_after>/*
 * 2010-2016 Sellermania / Froggy Commerce / 23Prod SARL
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to team@froggy-commerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade your module to newer
 * versions in the future.
 *
 *  @author         Froggy Commerce <team@froggy-commerce.com>
 *  @copyright      2010-2016 Sellermania / Froggy Commerce / 23Prod SARL
 *  @version        1.0
 *  @license        http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

$(document).ready(function() {

    // Hide PDF invoice link on orders list when the order status contains "Sellermania"
    $('#order div table tbody tr').each(function() {
        hidePDFButtons($(this));
    });

    $('#form-order div div table tbody tr').each(function() {
        hidePDFButtons($(this));
    });

    function hidePDFButtons(line)
    {
        var column = 0;
        var id_order = 0;
        var flag_sellermania = 0;

        line.find('td').each(function() {
            if (column == 1) {
                id_order = $(this).text();
            }
            else if (column == 8 && line.text().trim().toLowerCase().indexOf("marketplace") >= 0) {
                flag_sellermania = 1;
            }
            else if (column == 10 && flag_sellermania == 1) {
                $(this).find('a').each(function() {
                    if ($(this).attr('href').indexOf("generateInvoicePDF") >= 0) {
                        $(this).attr('href', sellermania_invoice_url + '&id_order=' + id_order);
                    } else {
                        $(this).remove();
                    }
                });
            }
            column++;
        });
    }

	if (nb_sellermania_orders_in_error > 0) {
        $('#order').before('
' + nb_sellermania_orders_in_error + ' ' + txt_sellermania_orders_in_error + '
');
    }

    /**
     * Handle Orders Bulk Action
     */

    html_bulk_actions = '

';

    html_bulk_actions += '
';
    html_bulk_actions += ' ' + txt_sellermania_confirm_orders;
    html_bulk_actions += '
';

    html_bulk_actions += '
';
    html_bulk_actions += ' ' + txt_sellermania_send_orders;
    html_bulk_actions += '
';

    $('.bulk-actions .dropdown-menu').append(html_bulk_actions);

    $('#sellermania-bulk-confirm-orders').click(function() {
        handleOrdersBulkAction($(this), 'bulk-confirm-orders');
        return false;
    });

    $('#sellermania-bulk-send-orders').click(function() {
        handleOrdersBulkAction($(this), 'bulk-send-orders');
        return false;
    });

    function handleOrdersBulkAction(self, sellermania_action)
    {
        // Retrieve selected orders
        var selected_orders = getSelectedOrders(self.closest('form').get(0), 'orderBox[]', true);
        if (selected_orders.length < 1) {
            alert(txt_sellermania_select_at_least_one_order);
            return false;
        }

        // Retrieve carrier
        var carrier = '';
        if (sellermania_action == 'bulk-send-orders') {
            var carrier = window.prompt(txt_sellermania_carrier_selection, sellermania_default_carrier);
        }

        // Post values
        var post_values = { sellermania_bulk_action: sellermania_action, sellermania_selected_orders: JSON.stringify(selected_orders), sellermania_carrier: carrier};
        $.post(sellermania_admin_orders_url, post_values).done(function(data) {
            var result = JSON.parse(data);
            if (result.result == 'OK') {

                var confirmation_message = txt_sellermania_orders_updated;

                if (sellermania_action == 'bulk-confirm-orders') {
                    for (var i in result.result_details.OrderItemConfirmationStatus) {
                        var conf_status = result.result_details.OrderItemConfirmationStatus[i];
                        confirmation_message += "\n\n#" + conf_status.id_order_prestashop + ' (sku: ' + conf_status.sku + ') : ';
                        if (conf_status.Status == 'ERROR') {
                            confirmation_message += conf_status.Message;
                        } else {
                            confirmation_message += conf_status.Status;
                        }
                    }
                }

                alert(confirmation_message);
            } else {
                alert(txt_sellermania_error_occured);
            }
        });
    }

    function getSelectedOrders(pForm, boxName, parent)
    {
        var boxes = [];
        for (i = 0; i < pForm.elements.length; i++) {
            if (pForm.elements[i].name == boxName && pForm.elements[i].checked == true) {
                boxes.push(pForm.elements[i].value);
            }
        }
        return boxes;
    }

});
<|endoftext|>


<commit_before>/****************************************************************************
 * Copyright (C) <2010>  <lostpassword>                                     *
 * [http://lostpassword.hellospace.net | gdb.lost@gmail.com]                *
 *                                                                          *
 *                                                                          *
 * misTET is free software: you can redistribute it and/or modify           *
 * it under the terms of the GNU General Public License as published by     *
 * the Free Software Foundation, either version 3 of the License, or        *
 * (at your option) any later version.                                      *
 *                                                                          *
 * misTET is distributed in the hope that it will be useful,                *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 * GNU General Public License for more details.                             *
 *                                                                          *
 * You should have received a copy of the GNU General Public License        *
 * along with misTET.  If not, see <http://www.gnu.org/licenses/>.          *
 ****************************************************************************/

/** Blog **/

misTET.modules.blog = {

	version: "0.0.1",
	name: "blog",
	root: "/modules/blog/",
	file: { },
	total: "",

	initialize: function () {

		misTET.modules.blog.location = document.location.hash;
		misTET.modules.blog.initXML();
		var args = misTET.other.parseGET();

		if (isset(misTET.intval)) {
			clearInterval(misTET.intval);
		}

		if (/#blog/.match(misTET.modules.blog.location)) {
			if (isset(args['id'])) {
				misTET.modules.blog.display(args['id']);
			} else {
				misTET.modules.blog.display();
			}
		}

		misTET.other.insertCSS(misTET.modules.blog.root + "resources/blog.css");
		misTET.modules.blog.intval = window.setInterval(misTET.modules.blog.refresh, 100);
	},

	refresh: function () {

		if (misTET.modules.blog.location != document.location.hash) {

			misTET.modules.blog.location = document.location.hash;
			var loc = misTET.modules.blog.location;
			var args = misTET.other.parseGET();

			if (/#blog/i.match(loc)) {
				if (/admin/.match(loc)) {
					misTET.modules.blog.admin();
				}
				if (!isset(args['id'])) {
					misTET.modules.blog.display();
				} else if (isset(args['id']) ) {
					misTET.modules.blog.display(args['id']);
				} else {
					misTET.refresh();
				}
			}
		}
	},

	initXML: function () {
		var path = misTET.modules.blog.root + "resources/blog.xml";
		var test = false;
		var error = false;

		new Ajax.Request(path, {
			method: "get",
			asynchronous: false,
       	   	evalJS: false,

            onSuccess: function (http) {
				if (test = misTET.other.XMLtest(http.responseXML)) {
					misTET.modules.blog.file = http.responseXML;
					misTET.modules.blog.total = parseInt(misTET.modules.blog.file.documentElement.getAttribute('n'));
				} else {
					misTET.error(test);
				}
            },

            onFailure: function (http) {
            	misTET.error("Error while loading blog.xml (#{error})".interpolate({ error: http.status }));
            }
		});
        if (error) {
			$('sd_left').innerHTML += error;
		}
	},

	getPost: function (id) {

		var XML = misTET.modules.blog.file.documentElement;
		var posts = XML.getElementsByTagName('post');
		var output = { };

		if (posts.length == 0) {
			output = null;
		} else {
			for (var i = 0; i < posts.length; i++) {
				if (posts[i].getAttribute('id') == id) {
					var list = posts[i].childNodes;
					output.author = posts[i].getAttribute('author');
					output.title = posts[i].getAttribute('title');
					output.date = posts[i].getAttribute('date');
					for (var j = 0; j < list.length; j++) {
						if (list[j].nodeName == "#cdata-section") {
							output.text = list[j].nodeValue;
						}
					}
				}
			}
		}
		return output;
	},

	display: function (id) {
		if (id) {
			var post = misTET.modules.blog.getPost(id);
			var output = "

"+ post.title + "
" + post.text + "
"+
					 	"Posted by " + post.author + " on " + post.date + "
";
			$('sd_left').innerHTML = output;
		} else {
			for (var j = misTET.modules.blog.total; j > 0; j--) {
				$('sd_left').innerHTML = "";
				var currentPost = misTET.modules.blog.getPost(j);
				var output = "

"+ currentPost.title + "
" + currentPost.text + "
"+
					 		 "Posted by " + currentPost.author + " on " + currentPost.date + "
";
				$('sd_left').innerHTML += output;
			}
		}
	},

	admin: function () {
		/** This has to be implemented */
	}

}
<commit_msg>Fixed a bug wich allowed you to view a post that does not exist<commit_after>/****************************************************************************
 * Copyright (C) <2010>  <lostpassword>                                     *
 * [http://lostpassword.hellospace.net | gdb.lost@gmail.com]                *
 *                                                                          *
 *                                                                          *
 * misTET is free software: you can redistribute it and/or modify           *
 * it under the terms of the GNU General Public License as published by     *
 * the Free Software Foundation, either version 3 of the License, or        *
 * (at your option) any later version.                                      *
 *                                                                          *
 * misTET is distributed in the hope that it will be useful,                *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 * GNU General Public License for more details.                             *
 *                                                                          *
 * You should have received a copy of the GNU General Public License        *
 * along with misTET.  If not, see <http://www.gnu.org/licenses/>.          *
 ****************************************************************************/

/** Blog **/

misTET.modules.blog = {

	version: "0.1",
	name: "blog",
	root: "/modules/blog/",
	file: { },
	total: "",

	initialize: function () {

		misTET.modules.blog.location = document.location.hash;
		misTET.modules.blog.initXML();
		var args = misTET.other.parseGET();

		if (isset(misTET.intval)) {
			clearInterval(misTET.intval);
		}

		if (/#blog/.match(misTET.modules.blog.location)) {
			if (/admin/.match(misTET.modules.blog.location)) {
				window.location.href = misTET.modules.blog.root + "admin";
			} else  if (isset(args['id'])) {
				misTET.modules.blog.display(args['id']);
			} else {
				misTET.modules.blog.display();
			}
		}

		misTET.other.insertCSS(misTET.modules.blog.root + "resources/blog.css");
		misTET.modules.blog.intval = window.setInterval(misTET.modules.blog.refresh, 100);
	},

	refresh: function () {

		if (/#blog/i.match(document.location.hash)) {
			if (misTET.modules.blog.location != document.location.hash) {
				misTET.modules.blog.location = document.location.hash;
				var loc = misTET.modules.blog.location;
				var args = misTET.other.parseGET();

				if (/admin/.match(loc)) {
					window.location.href = misTET.modules.blog.root + "admin";
				}
				if (!isset(args['id'])) {
					misTET.modules.blog.display();
				} else if (isset(args['id']) ) {
					misTET.modules.blog.display(args['id']);
				} else {
					misTET.refresh();
				}
			}
		}
	},

	initXML: function () {
		var path = misTET.modules.blog.root + "resources/blog.xml";
		var test = false;
		var error = false;

		new Ajax.Request(path, {
			method: "get",
			asynchronous: false,
       	   	evalJS: false,

            onSuccess: function (http) {
				if (test = misTET.other.XMLtest(http.responseXML)) {
					misTET.modules.blog.file = http.responseXML;
					misTET.modules.blog.total = parseInt(misTET.modules.blog.file.documentElement.getAttribute('n'));
				} else {
					misTET.error(test);
				}
            },

            onFailure: function (http) {
            	misTET.error("Error while loading blog.xml (#{error})".interpolate({ error: http.status }));
            }
		});
        if (error) {
			$('sd_left').innerHTML += error;
		}
	},

	getPost: function (id) {

		var XML = misTET.modules.blog.file.documentElement;
		var posts = XML.getElementsByTagName('post');
		var output = { };

		if (posts.length == 0) {
			output = null;
		} else {
			for (var i = 0; i < posts.length; i++) {
				if (posts[i].getAttribute('id') == id) {
					var list = posts[i].childNodes;
					output.author = posts[i].getAttribute('author');
					output.title = posts[i].getAttribute('title');
					output.date = posts[i].getAttribute('date');
					for (var j = 0; j < list.length; j++) {
						if (list[j].nodeName == "#cdata-section") {
							output.text = list[j].nodeValue;
						}
					}
				}
			}
		}
		return output;
	},

	checkPost: function (map) {
		var result = true;
		['title', 'text', 'author', 'date'].each(function(obj) {
			if (typeof(map[obj]) == "undefined") {
				result = false;
			}
		});
		return result;
	},

	display: function (id) {
		if (id) {
			var post = misTET.modules.blog.getPost(id);
			if (misTET.modules.blog.checkPost(post)) {
				var output = "

"+ post.title + "
" + post.text + "
"+
					 		"Posted by " + post.author + " on " + post.date + "
";
				$('sd_left').innerHTML = output;
			} else {
				$('sd_left').innerHTML = "
The selected post doesn\'t exist
";
			}
		} else {
			$('sd_left').innerHTML = "";
			for (var j = misTET.modules.blog.total; j > 0; j--) {
				var currentPost = misTET.modules.blog.getPost(""+j+"");
				if (misTET.modules.blog.checkPost(currentPost)) {
					var output = "

"+ currentPost.title + "
" + currentPost.text + "
"+
					 		 	"Posted by " + currentPost.author + " on " + currentPost.date + "
";
					$('sd_left').innerHTML += output;
				}
			}
		}
	},

}
<|endoftext|>


<commit_before>/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

/*
* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.
*/

// MODULES //

var setReadOnly = require( '@stdlib/utils/define-read-only-property' );

// MAIN //

/**
* Top-level namespace.
*
* @namespace ns
*/
var ns = {};

/**
* @name ArrayBuffer
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/buffer}
*/
setReadOnly( ns, 'ArrayBuffer', require( '@stdlib/array/buffer' ) );

/**
* @name convertArray
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/convert}
*/
setReadOnly( ns, 'convertArray', require( '@stdlib/array/convert' ) );

/**
* @name convertArraySame
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/convert-same}
*/
setReadOnly( ns, 'convertArraySame', require( '@stdlib/array/convert-same' ) );

/**
* @name arrayCtors
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/ctors}
*/
setReadOnly( ns, 'arrayCtors', require( '@stdlib/array/ctors' ) );

/**
* @name arrayDataType
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/dtype}
*/
setReadOnly( ns, 'arrayDataType', require( '@stdlib/array/dtype' ) );

/**
* @name arrayDataTypes
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/dtypes}
*/
setReadOnly( ns, 'arrayDataTypes', require( '@stdlib/array/dtypes' ) );

/**
* @name Float32Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/float32}
*/
setReadOnly( ns, 'Float32Array', require( '@stdlib/array/float32' ) );

/**
* @name Float64Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/float64}
*/
setReadOnly( ns, 'Float64Array', require( '@stdlib/array/float64' ) );

/**
* @name Int8Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/int8}
*/
setReadOnly( ns, 'Int8Array', require( '@stdlib/array/int8' ) );

/**
* @name Int16Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/int16}
*/
setReadOnly( ns, 'Int16Array', require( '@stdlib/array/int16' ) );

/**
* @name Int32Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/int32}
*/
setReadOnly( ns, 'Int32Array', require( '@stdlib/array/int32' ) );

/**
* @name arrayMinDataType
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/min-dtype}
*/
setReadOnly( ns, 'arrayMinDataType', require( '@stdlib/array/min-dtype' ) );

/**
* @name arrayNextDataType
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/next-dtype}
*/
setReadOnly( ns, 'arrayNextDataType', require( '@stdlib/array/next-dtype' ) );

/**
* @name typedarraypool
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/pool}
*/
setReadOnly( ns, 'typedarraypool', require( '@stdlib/array/pool' ) );

/**
* @name arrayPromotionRules
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/promotion-rules}
*/
setReadOnly( ns, 'arrayPromotionRules', require( '@stdlib/array/promotion-rules' ) );

/**
* @name reviveTypedArray
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/reviver}
*/
setReadOnly( ns, 'reviveTypedArray', require( '@stdlib/array/reviver' ) );

/**
* @name arraySafeCasts
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/safe-casts}
*/
setReadOnly( ns, 'arraySafeCasts', require( '@stdlib/array/safe-casts' ) );

/**
* @name arraySameKindCasts
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/same-kind-casts}
*/
setReadOnly( ns, 'arraySameKindCasts', require( '@stdlib/array/same-kind-casts' ) );

/**
* @name arrayShape
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/shape}
*/
setReadOnly( ns, 'arrayShape', require( '@stdlib/array/shape' ) );

/**
* @name SharedArrayBuffer
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/shared-buffer}
*/
setReadOnly( ns, 'SharedArrayBuffer', require( '@stdlib/array/shared-buffer' ) );

/**
* @name typedarray2json
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/to-json}
*/
setReadOnly( ns, 'typedarray2json', require( '@stdlib/array/to-json' ) );

/**
* @name typedarray
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/typed}
*/
setReadOnly( ns, 'typedarray', require( '@stdlib/array/typed' ) );

/**
* @name typedarrayComplexDataTypes
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/typed-complex-dtypes}
*/
setReadOnly( ns, 'typedarrayComplexDataTypes', require( '@stdlib/array/typed-complex-dtypes' ) );

/**
* @name typedarrayCtors
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/typed-ctors}
*/
setReadOnly( ns, 'typedarrayCtors', require( '@stdlib/array/typed-ctors' ) );

/**
* @name typedarrayDataTypes
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/typed-dtypes}
*/
setReadOnly( ns, 'typedarrayDataTypes', require( '@stdlib/array/typed-dtypes' ) );

/**
* @name Uint8Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/uint8}
*/
setReadOnly( ns, 'Uint8Array', require( '@stdlib/array/uint8' ) );

/**
* @name Uint8ClampedArray
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/uint8c}
*/
setReadOnly( ns, 'Uint8ClampedArray', require( '@stdlib/array/uint8c' ) );

/**
* @name Uint16Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/uint16}
*/
setReadOnly( ns, 'Uint16Array', require( '@stdlib/array/uint16' ) );

/**
* @name Uint32Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/uint32}
*/
setReadOnly( ns, 'Uint32Array', require( '@stdlib/array/uint32' ) );

/**
* @name constants
* @memberof ns
* @readonly
* @type {Namespace}
* @see {@link module:@stdlib/constants/array}
*/
setReadOnly( ns, 'constants', require( '@stdlib/constants/array' ) );

// EXPORTS //

module.exports = ns;
<commit_msg>Update namespace<commit_after>/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

/*
* When adding modules to the namespace, ensure that they are added in alphabetical order according to module name.
*/

// MODULES //

var setReadOnly = require( '@stdlib/utils/define-read-only-property' );

// MAIN //

/**
* Top-level namespace.
*
* @namespace ns
*/
var ns = {};

/**
* @name ArrayBuffer
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/buffer}
*/
setReadOnly( ns, 'ArrayBuffer', require( '@stdlib/array/buffer' ) );

/**
* @name convertArray
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/convert}
*/
setReadOnly( ns, 'convertArray', require( '@stdlib/array/convert' ) );

/**
* @name convertArraySame
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/convert-same}
*/
setReadOnly( ns, 'convertArraySame', require( '@stdlib/array/convert-same' ) );

/**
* @name arrayCtors
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/ctors}
*/
setReadOnly( ns, 'arrayCtors', require( '@stdlib/array/ctors' ) );

/**
* @name arrayDataType
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/dtype}
*/
setReadOnly( ns, 'arrayDataType', require( '@stdlib/array/dtype' ) );

/**
* @name arrayDataTypes
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/dtypes}
*/
setReadOnly( ns, 'arrayDataTypes', require( '@stdlib/array/dtypes' ) );

/**
* @name Float32Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/float32}
*/
setReadOnly( ns, 'Float32Array', require( '@stdlib/array/float32' ) );

/**
* @name Float64Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/float64}
*/
setReadOnly( ns, 'Float64Array', require( '@stdlib/array/float64' ) );

/**
* @name Int8Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/int8}
*/
setReadOnly( ns, 'Int8Array', require( '@stdlib/array/int8' ) );

/**
* @name Int16Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/int16}
*/
setReadOnly( ns, 'Int16Array', require( '@stdlib/array/int16' ) );

/**
* @name Int32Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/int32}
*/
setReadOnly( ns, 'Int32Array', require( '@stdlib/array/int32' ) );

/**
* @name arrayMinDataType
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/min-dtype}
*/
setReadOnly( ns, 'arrayMinDataType', require( '@stdlib/array/min-dtype' ) );

/**
* @name arrayNextDataType
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/next-dtype}
*/
setReadOnly( ns, 'arrayNextDataType', require( '@stdlib/array/next-dtype' ) );

/**
* @name typedarraypool
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/pool}
*/
setReadOnly( ns, 'typedarraypool', require( '@stdlib/array/pool' ) );

/**
* @name arrayPromotionRules
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/promotion-rules}
*/
setReadOnly( ns, 'arrayPromotionRules', require( '@stdlib/array/promotion-rules' ) );

/**
* @name reviveTypedArray
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/reviver}
*/
setReadOnly( ns, 'reviveTypedArray', require( '@stdlib/array/reviver' ) );

/**
* @name arraySafeCasts
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/safe-casts}
*/
setReadOnly( ns, 'arraySafeCasts', require( '@stdlib/array/safe-casts' ) );

/**
* @name arraySameKindCasts
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/same-kind-casts}
*/
setReadOnly( ns, 'arraySameKindCasts', require( '@stdlib/array/same-kind-casts' ) );

/**
* @name arrayShape
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/shape}
*/
setReadOnly( ns, 'arrayShape', require( '@stdlib/array/shape' ) );

/**
* @name SharedArrayBuffer
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/shared-buffer}
*/
setReadOnly( ns, 'SharedArrayBuffer', require( '@stdlib/array/shared-buffer' ) );

/**
* @name typedarray2json
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/to-json}
*/
setReadOnly( ns, 'typedarray2json', require( '@stdlib/array/to-json' ) );

/**
* @name typedarray
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/typed}
*/
setReadOnly( ns, 'typedarray', require( '@stdlib/array/typed' ) );

/**
* @name typedarrayComplexCtors
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/typed-complex-ctors}
*/
setReadOnly( ns, 'typedarrayComplexCtors', require( '@stdlib/array/typed-complex-ctors' ) );

/**
* @name typedarrayComplexDataTypes
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/typed-complex-dtypes}
*/
setReadOnly( ns, 'typedarrayComplexDataTypes', require( '@stdlib/array/typed-complex-dtypes' ) );

/**
* @name typedarrayCtors
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/typed-ctors}
*/
setReadOnly( ns, 'typedarrayCtors', require( '@stdlib/array/typed-ctors' ) );

/**
* @name typedarrayDataTypes
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/typed-dtypes}
*/
setReadOnly( ns, 'typedarrayDataTypes', require( '@stdlib/array/typed-dtypes' ) );

/**
* @name Uint8Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/uint8}
*/
setReadOnly( ns, 'Uint8Array', require( '@stdlib/array/uint8' ) );

/**
* @name Uint8ClampedArray
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/uint8c}
*/
setReadOnly( ns, 'Uint8ClampedArray', require( '@stdlib/array/uint8c' ) );

/**
* @name Uint16Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/uint16}
*/
setReadOnly( ns, 'Uint16Array', require( '@stdlib/array/uint16' ) );

/**
* @name Uint32Array
* @memberof ns
* @readonly
* @constructor
* @see {@link module:@stdlib/array/uint32}
*/
setReadOnly( ns, 'Uint32Array', require( '@stdlib/array/uint32' ) );

/**
* @name constants
* @memberof ns
* @readonly
* @type {Namespace}
* @see {@link module:@stdlib/constants/array}
*/
setReadOnly( ns, 'constants', require( '@stdlib/constants/array' ) );

// EXPORTS //

module.exports = ns;
<|endoftext|>