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

branch for codereview #36

Closed
wants to merge 3 commits into from
Closed

Conversation

jinwoo-kim-nhn
Copy link
Contributor

@jinwoo-kim-nhn jinwoo-kim-nhn commented May 31, 2018

work

  • Image-editor에 디자인된 기본 UI 적용
    • ui.js 추가 - ui 관련 dom관리 및 이벤트 관리.
    • ui/{메뉴명}.js - 메뉴별로 dom관리 및 이벤트 관리
    • action.js 추가 - 이벤트 핸들러부분을 전부 관리.
    • theme.js 추가 - 테마관리
    • polyfill.js 추가 - svg use, classList, element closest
    • ui/template - 템플릿 html

demo

@@ -284,6 +292,10 @@ class Graphics {
this._canvas.setActiveObject(target);
}

setCropSelectionStyle(style) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 퍼블릭 메서드인가요? 주석이 빠졌네요.

import Invoker from './invoker';
import Ui from './ui';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요건 네이밍을 정리하면 좋을것 같아요~

@@ -26,9 +29,19 @@ const {isUndefined, forEach, CustomEvents} = snippet;
class ImageEditor {
constructor(wrapper, option) {
option = snippet.extend({
includeUi: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI 대문자로 쓰는게 맞을듯요

drawRange: new Range(selector('#draw-range'), {
min: 5,
max: 30,
value: 12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상수 모듈 하나 만들어서 거기서 관리하는건 어떨까요?

/**
* Add event for draw
* @param {Object} actions - actions for crop
* @param {Function} setDrawMode - set draw mode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

두 번째 파라미터는 잘못 들어간 건가요?

const option = {};
switch (type) {
case 'removeWhite':
option.threshold = parseInt(this._el.removewhiteThresholdRange.getValue(), 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseInt() 이건 유틸 메서드로 빼서 처리하는게 좋겠어요

* @private
*/
_makeSelectOptionList(selectlist) {
const blendOptions = ['add', 'diff', 'subtract', 'multiply', 'screen', 'lighten', 'darken'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드 호출할 때마다 이 변수들 매번 생성할 필요는 없어보여요.

* @returns {string}
* @private
*/
_toCamelCase(targetString) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 로직도 필터 클래스가 가질 필요가 없네요. 유틸로 빼주세요~


if (file) {
imgUrl = URL.createObjectURL(file);
registCustomIcon(imgUrl, file);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파일 객체 유무 판별하는 로직도 유틸로 빼주세요~

'icon-location': 'M24 62C8 45.503 0 32.837 0 24 0 10.745 10.745 0 24 0s24 10.745 24 24c0 8.837-8 21.503-24 38zm0-28c5.523 0 10-4.477 10-10s-4.477-10-10-10-10 4.477-10 10 4.477 10 10 10z',
'icon-heart': 'M49.994999,91.349998 l-6.96,-6.333 C18.324001,62.606995 2.01,47.829002 2.01,29.690998 C2.01,14.912998 13.619999,3.299999 28.401001,3.299999 c8.349,0 16.362,5.859 21.594,12 c5.229,-6.141 13.242001,-12 21.591,-12 c14.778,0 26.390999,11.61 26.390999,26.390999 c0,18.138 -16.314001,32.916 -41.025002,55.374001 l-6.96,6.285 z ',
'icon-bubble': 'M44 48L34 58V48H12C5.373 48 0 42.627 0 36V12C0 5.373 5.373 0 12 0h40c6.627 0 12 5.373 12 12v24c0 6.627-5.373 12-12 12h-8z'
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것도 아이콘 패쓰 모듈로 해서 상수로 빼는게 좋겠어요.

iconSubMenu.className = 'icon';
iconSubMenu.innerHTML = iconHtml({iconStyle});

subMenuElement.appendChild(iconSubMenu);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 메서드는.. 클래스마다 다 가지고 있는 것 같은데..
인터페이스 하나 두고 재사용할 수는 없는건가요?

const [shapeType] = button.className.match(/(circle|triangle|rect)/);

event.currentTarget.classList.remove(this.type);
event.currentTarget.classList.add(shapeType);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 코드도 다른 클래스랑 많이 중복되네요~

subMenuElement.appendChild(shapeSubMenu);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[5/31] 오늘은 여기까지 리뷰할게요~ 내일 이어서 진행하겠습니다.

@@ -0,0 +1,95 @@
/**
* @fileoverview The standard theme
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파일명 basic은 어떤가요ㅎ

linkElement.setAttribute('rel', 'stylesheet');
linkElement.setAttribute('type', 'text/css');
linkElement.setAttribute('href', `data:text/css;charset=UTF-8,${styleData}`);
head.appendChild(linkElement);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 메서드도 테마 클래스 소유가 아니라 유틸로 빼야겠어요~

};

document.addEventListener('mousemove', changeAngle);
document.addEventListener('mouseup', stopChangingAngle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

핸들러 함수들 외부 메서드로 분리하는게 가독성에 더 좋을것 같아요

test/ui.spec.js Outdated
@@ -0,0 +1,351 @@
/**
* @author NHN Ent. FE Development Team <[email protected]>
* @fileoverview Test cases of "src/js/component/cropper.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것은.. 설명이 잘못된 것 같습니다ㅎㅎ

menu: {
icon: {
normal: {
path: '../dist/svg',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

패쓰 이렇게 잡혀도 상관 없는건가요??

@seonim-ryu
Copy link
Member

[6/1] 테스트가 깨지는군요 ㅜㅜ 차주에 리팩토링 하시고 리뷰 한 번 더 가시죠~

Copy link
Member

@shiren shiren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨어요.. 테스트는 꼭해야할 부분들이 몇가지 더 있는것 같아요.

target[1] = outer[1] + size;
target[2] = outer[1] + (size * 2);
target[3] = outer[2];
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outer하고 size 를 받어서 inner를 리턴해주는 함수로 바꿔서 모듈 안에 private하게 두고 사용하는게 좋을것같아요.

* Ui instance
* @type {Ui}
*/
this.ui = option.includeUi ? new Ui(wrapper, option.includeUi, this.getActions()) : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

includeUi가 true인경우 ui를 사용하는 조건은 3항연산자가 어울리지 않는것 같아요. null이 따로 의미가 없다면 말이죠
A or B로 선택하는게 아니니까

if (options.includeUi) {
this.ui = new Ui(wrapper, option.includeUi, this.getActions())
}

이게  의미적으로 맞는것 같습니다. this.ui가 undefined  없는것이니까요

this._el.lineSelectButton.classList.add(lineType);

this.type = lineType;
this.setDrawMode();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

click 하면 무었을 한다라는 함수명으로 하나 뽑아주면 click되면 무엇을 하는구나 하고 한눈에 읽힐 수 있을것 같아요. 다시말해 click은 일반화된 행위이고 그 행위로 실제 어떤 작업을 하게되는지를 나타내는 함수명

여기서는 아래 와 같으면 되려나.
this._el.lineSelectButton.addEventListener('click', this.changeDrawModeType.bind(this));

아래 리스너들도 마찮가지

const selector = str => subMenuElement.querySelector(str);
this._makeSubMenuElement(subMenuElement, iconStyle);

this._el = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여긴 this._els 가 나을것 같아요 this._el 로 보통 한개의 dom 노드를 참조하는 케이스가 많다보니 햇갈려요.
그리고 일괄처리가 필요해서 모와둔게 아니고 단순히 모와두기만 한것이라면 굳이 객체로 모와서 사용하지 말고
개별적으로 사용해도 괜찮다고 생각합니다.

this._lineSelectButtonEl

이런식으로..

*/
_makeSelectOptionList(selectlist) {
const blendOptions = ['add', 'diff', 'subtract', 'multiply', 'screen', 'lighten', 'darken'];
snippet.forEach(blendOptions, option => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인자가 두개 이상부터는 괄호로 감싸는것이 컨벤션으로 아는데 린터가 안잡았나?

*/
setColor(color) {
this._color = color;
this._changeColorElement(color);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 게터 세터 딱이네.

_setPickerControlPosition() {
const controlStyle = this.pickerControl.style;
const top = parseInt(window.getComputedStyle(this.pickerControl, null).height, 10) + 12;
const left = (parseInt(window.getComputedStyle(this.pickerControl, null).width, 10) / 2) - 20;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

매직넘버 제거해주세요

this.value = options.value || 0;
this.rangeElement = rangeElement;
this._drawRangeElement();
this.rangeWidth = parseInt(window.getComputedStyle(rangeElement, null).width, 10) - 12;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

매직넘버

* @param {Number} value range value
* @param {Boolean} fire whether fire custom event or not
*/
setValue(value, fire = true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 게터 세터

src/js/util.js Outdated
* @returns {string} rgb expression
*/
getRgb(color, alpha) {
const r = parseInt(color.slice(1, 3), 16);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

컬러값이 '#fff'

이렇게 축약형일때도 고려되야 하는거 아니에요?

@@ -308,6 +308,11 @@ class Shape extends Component {
* @private
*/
_onFabricMouseDown(fEvent) {
if (!fEvent.target) {
this._isSelected = false;
this._shapeObj = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 false 말고 null이 들어가는게 맞을 것 같아요.

'icon-polygon': 'M3,31 L19,3 h32 l16,28 l-16,28 H19 z ',
'icon-location': 'M24 62C8 45.503 0 32.837 0 24 0 10.745 10.745 0 24 0s24 10.745 24 24c0 8.837-8 21.503-24 38zm0-28c5.523 0 10-4.477 10-10s-4.477-10-10-10-10 4.477-10 10 4.477 10 10 10z',
'icon-heart': 'M49.994999,91.349998 l-6.96,-6.333 C18.324001,62.606995 2.01,47.829002 2.01,29.690998 C2.01,14.912998 13.619999,3.299999 28.401001,3.299999 c8.349,0 16.362,5.859 21.594,12 c5.229,-6.141 13.242001,-12 21.591,-12 c14.778,0 26.390999,11.61 26.390999,26.390999 c0,18.138 -16.314001,32.916 -41.025002,55.374001 l-6.96,6.285 z ',
'icon-bubble': 'M44 48L34 58V48H12C5.373 48 0 42.627 0 36V12C0 5.373 5.373 0 12 0h40c6.627 0 12 5.373 12 12v24c0 6.627-5.373 12-12 12h-8z'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프로퍼티들 대문자로 사용해야 하지 않을까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

svg같은데 꼭 자바스크립트에 있어야 하나요? css에 있는 것이 어울리는데.

@@ -26,9 +29,21 @@ const {isUndefined, forEach, CustomEvents} = snippet;
class ImageEditor {
constructor(wrapper, option) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이번에 정리하는김에.. option -> options로 변경하면 좋겠습니다~

@@ -848,6 +875,15 @@ class ImageEditor {
return this.execute(commands.CHANGE_TEXT_STYLE, id, styleObj);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프라이빗 주석 추가요

/**
* Change drawing color
* @param {string} color - select drawing color
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@private 추가요~

/**
* Change drawing Range
* @param {number} value - select drawing range
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 @private 추가요.

*/
_changeDrawColor(color) {
color = color || 'transparent';
this.color = color;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한줄로 해도 될 것 같아요.

rangeWrap.appendChild(rangelabel);
rangeWrap.appendChild(range);
pickerControl.appendChild(rangeWrap);
pickerControl.style.height = '130px';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것도 css로 빠지기 힘든 건가요?

return new Range(range, {
min: 0,
max: 1,
value: 0.7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런것들도 상수 모아놓는 파일이 있었던것 같은데, 같이 관리하면 좋겠어요.

this._makeSelectOptionList(selectlist);

pickerControl.appendChild(selectlistWrap);
pickerControl.style.height = '130px';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위에랑 같은거네요. 불가피 하다면, 한번에 바꿀 수 있도록 여기서 상수로라도 처리해야 겠습니다.

export default class Flip extends Submenu {
constructor(subMenuElement, {iconStyle}) {
super(subMenuElement, {
name: 'flip',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI마다 이름 처리를 해주어야 하는군요.

babel class properties 사용중이라면 프로퍼티로 넣고,
UI 상위 constructor에서 이름 처리해주는 것도 깔끔하겠네요.

const rotateType = this.getButtonType(button, ['counterclockwise', 'clockwise']);
const rotateAngle = {
'clockwise': 30,
'counterclockwise': -30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분도 상수처리 필요하겟습니다.

});
this.type = 'rect';
this.options = {
stroke: '#ffbb3b',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상수처리는 이 이후로 생략하겠습니다.

* Get text color
* @returns {string} - text color
*/
get textColor() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우리 엑세서 안쓰기로 했던 것 같아요.

@kyuwoo-choi
Copy link
Member

[6/4] 완료입니다. 많네요;;; 수고하셨어요~

/**
* Change icon color
* @param {string} color - color for change
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적으로 클래스마다 @private이 누락된것 같네요

* @param {object} event - File change event object
*/
_loadMaskFile(event) {
const supportingFileAPI = !!(window.File && window.FileList && window.FileReader);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 유틸 메서드로 안빼고 그대로 사용하는건가요? ;ㅅ;

const rotateType = this.getButtonType(button, ['counterclockwise', 'clockwise']);
const rotateAngle = {
'clockwise': 30,
'counterclockwise': -30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

하이픈으로 연결된 경우 아니면 프로퍼티들 따옴표 없이 사용해도 되요~

* Get butten type
* @param {HTMLElement} button - event target element
* @param {array} buttonNames - Array of button names
* @returns {string} - button type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음? 리턴값 배열 아닌가요?

* @returns {string} - button type
*/
getButtonType(button, buttonNames) {
const [buttonType] = button.className.match(RegExp(`(${buttonNames.join('|')})`));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

할당하지 말고 바로 리턴해도 되겠어요~

colorpickerElement.addEventListener('click', event => {
this._show = !this._show;
const display = this._show ? 'block' : 'none';
this.pickerControl.style.display = display;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수 할당 안하고 바로 써도 되겠어요~

@seonim-ryu
Copy link
Member

[6/4] 리뷰 완료하였습니다. TC가 깨졌네요 ㅜㅜ 고생하셨어요~

@jinwoo-kim-nhn jinwoo-kim-nhn deleted the feat/design-codereview branch July 9, 2018 08:21
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

Successfully merging this pull request may close these issues.

None yet

4 participants