Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

const tslib_1 = require("tslib");

const react_1 = tslib_1.__importDefault(require("react"));

const mobx_react_1 = require("xmobx/mobx-react");

const exotic_1 = require("exotic");

const exotic_2 = require("exotic");

const ShoppingList_1 = require("../../../abstractions/ShoppingList");

const renderProps_1 = require("./renderProps");

const state_1 = require("./state");

const strategy_1 = require("./strategy");

const words_1 = require("../../../../words");

let Item = class Item extends react_1.default.Component {
  constructor() {
    super(...arguments);
    this.observableState = new state_1.ListState();
    this.strategy = new strategy_1.ValidationStrategy();
  } // strategy = new ValidationStrategy({
  //   props: this.props,
  //   state: this.observableState,
  // })


  updateListName(nextProps) {
    const {
      item = exotic_1.EMPTY_OBJ
    } = nextProps;
    const {
      listName
    } = item;
    const name = exotic_1.isSafe(listName) ? listName : '';
    this.observableState.setListName(name);
  }

  updateStatus(nextProps) {
    const {
      item = exotic_1.EMPTY_OBJ
    } = nextProps;
    const {
      accessType
    } = item;
    const isPrivate = exotic_1.isSafe(accessType) && accessType.toLowerCase() === words_1.wording.private ? true : false;
    this.observableState.setIsPrivate(isPrivate);
  }

  updateStrategyConfig(nextProps) {
    this.strategy.setStrategyConfig({
      props: nextProps,
      state: this.observableState
    });
  }

  componentWillUpdate(nextProps) {
    this.updateListName(nextProps);
    this.updateStatus(nextProps);
    this.updateStrategyConfig(nextProps);
  }

  componentDidUpdate() {
    const {
      shoppingListCollapseState
    } = this.props;

    if (this.observableState.isExpanded === true) {
      this.observableState.setIsExpanded(false);
    }

    shoppingListCollapseState.collapseState = undefined;

    if (this.observableState.isConfirming === true) {
      this.observableState.handleConfirmCancel();
    }

    shoppingListCollapseState.removeConfirmationState = undefined;
  }

  componentWillMount() {
    this.updateListName(this.props);
    this.updateStatus(this.props);
    this.updateStrategyConfig(this.props);
  }

  render() {
    return react_1.default.createElement(ShoppingList_1.Item, Object.assign({
      state: this.observableState,
      strategy: this.strategy
    }, this.props));
  }

};
Item.defaultProps = {
  className: '',
  renderExpandableView: renderProps_1.defaultRenderExpandableView,
  renderActionBar: renderProps_1.defaultRenderActionBar,
  renderButton: renderProps_1.defaultRenderButton,
  renderRemoveConfirmation: renderProps_1.defaultRenderRemoveConfirmation,
  //
  onRemoveList: exotic_2.NO_OP,
  onEdit: exotic_2.NO_OP
};
Item = tslib_1.__decorate([mobx_react_1.observer], Item);
exports.Item = Item;
exports.default = Item; //# sourceMappingURL=Item.js.map