const deepClone = obj => JSON.parse(JSON.stringify(obj));

const isEqual = (newVal, oldVal) => JSON.stringify(newVal) === JSON.stringify(oldVal);

Component({
  props: {
    title: '',
    list: [],
    selectedIds: [],
    onChange: () => null,
    onMoreChange: () => null
  },
  data: {
    renderList: []
  },

  deriveDataFromProps({
    list
  }) {
    const {
      renderList
    } = this.data;

    const _list = list.filter((item, i) => i < 2);

    if (!isEqual(_list, renderList)) {
      const update = {
        renderList: deepClone(_list)
      };
      this.setData(update);
    }
  },

  methods: {
    onTapItem({
      currentTarget
    }) {
      const {
        value: id
      } = currentTarget.dataset;
      this.props.onChange(id);
    },

    onChangeList(items) {
      this.props.onMoreChange(items);
    }

  }
});