Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.1更新说明 #3

Open
ckinmind opened this issue Jan 28, 2017 · 1 comment
Open

v1.1更新说明 #3

ckinmind opened this issue Jan 28, 2017 · 1 comment

Comments

@ckinmind
Copy link
Owner

ckinmind commented Jan 28, 2017

v1.1更新说明

  • 组件拆分,不再写在一个文件夹中
  • 引入了classnames包处理样式class
  • 将通用方法拆分到util中
  • 修改了闭包传递方法的写法
@ckinmind
Copy link
Owner Author

关于:修改了闭包传递方法的写法

之前

/**
     * 利用rearrange函数居中对应index的图片
     * @param index 需要被居中的图片的索引值
     * return {function}
     */
    center(index){
        return () => this.rearrange(index);
    }

    /**
     * 翻转图片
     * @param index 传入当前被执行inverse操作的图片对应的图片信息数组的index值
     * @returns {Function} 这是一个闭包函数, 其内return一个真正待被执行的函数
     */
    inverse(index){
        return () => {
            let imgsArrangeArr = this.state.imgsArrangeArr;
            imgsArrangeArr[index].isInverse = !imgsArrangeArr[index].isInverse;
            this.setState({
                imgsArrangeArr: imgsArrangeArr
            });
        }
    }
// ....
  let commonProps = {
                key: index,
                arrange: this.state.imgsArrangeArr[index],
                inverse: this.inverse(index),
                center: this.center(index)
            };
            imgFigure.push( <ImgFigure data={value} ref={'imgFigure' + index} {...commonProps}/> );
            cotrollerUnits.push( <ControllerUnit  {...commonProps} />);

修改之后

 /**
     * 利用rearrange函数居中对应index的图片
     * @param index 需要被居中的图片的索引值
     * return {function}
     */
    center(index){
        this.rearrange(index);
    }

    /**
     * 翻转图片
     * @param index 传入当前被执行inverse操作的图片对应的图片信息数组的index值
     * @returns {Function} 这是一个闭包函数, 其内return一个真正待被执行的函数
     */
    inverse(index) {
        let imgsArrangeArr = this.state.imgsArrangeArr;
        imgsArrangeArr[index].isInverse = !imgsArrangeArr[index].isInverse;
        this.setState({
            imgsArrangeArr: imgsArrangeArr
        });
    }
//....
 let commonProps = {
                key: index,
                arrange: this.state.imgsArrangeArr[index],
                inverse: this.inverse.bind(this,index),
                center: this.center.bind(this,index)
            };
            imgFigure.push( <ImgFigure data={value} ref={'imgFigure' + index} {...commonProps}/> );
            cotrollerUnits.push( <ControllerUnit  {...commonProps} />);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant