Angular Foundation
Architecture

Architecture
- Modules
- Components
- Templates
- Metadata
- Data binding
- Directives
- Services
- Dependency injection
Architecture - Modules
- declarations
- exports
- imports
- providers
- bootstrap
File Naming 규칙
Prefix(필수) : N
Types(Suffix, Optional) : A~Z
Subject : Layout, xxxField, etc
최종 파일명 : N + Layout + A
→ NLayoutA.js, NTextField.js
Variable 규칙
Naming : CamelCase로 작성
let : 지역 변수, 중복선언 불가
변수 : var, let, const
- const area = "Area"
- let areaSector = "Area"
const : 지역 변수, 할당된 값 변경 불가
var : 글로벌 또는 지역 변수, 제한없음.
const, let을 권장
Javascript Style Guide
-- References
// bad
var a = 1;
var b = 2;
// good
const a = 1;
const b = 2;
// bad
var count = 1;
if (true) {
count += 1;
}
// good, use the let.
let count = 1;
if (true) {
count += 1;
}
Airbnb Style Guide 참고
React/JSX Style Guide
-- Class 생성
// bad
const Listing = React.createClass({
// ...
render() {
return <div>{this.state.hello}</div>;
}
});
// good
class Listing extends React.Component {
// ...
render() {
return <div>{this.state.hello}</div>;
}
}
-- Component Import
// bad
import reservationCard from './ReservationCard';
// good
import ReservationCard from './ReservationCard';
// bad
const ReservationItem = <ReservationCard />;
// good
const reservationItem = <ReservationCard />;
-- Alignment
// bad
<Foo superLongParam="bar"
anotherSuperLongParam="baz" />
// good
<Foo
superLongParam="bar"
anotherSuperLongParam="baz"
/>
// if props fit in one line then keep it on the same line
<Foo bar="bar" />
// children get indented normally
<Foo
superLongParam="bar"
anotherSuperLongParam="baz"
>
<Quux />
</Foo>
-- Quotes : Always use double quotes (") for JSX attributes, but single quotes for all other JS
// bad
<Foo bar='bar' />
// good
<Foo bar="bar" />
// bad
<Foo style={{ left: "20px" }} />
// good
<Foo style={{ left: '20px' }} />
-- Spacing
// bad
<Foo/>
// very bad
<Foo />
// bad
<Foo
/>
// good
<Foo />
// bad
<Foo bar={ baz } />
// good
<Foo bar={baz} />
-- Props
// bad
<Foo
UserName="hello"
phone_number={12345678}
/>
// good
<Foo
userName="hello"
phoneNumber={12345678}
/>
-- Refs
// bad
<Foo
ref="myRef"
/>
// good
<Foo
ref={ref => { this.myRef = ref; }}
/>
-- Parentheses
// bad
render() {
return <MyComponent className="long body" foo="bar">
<MyChild />
</MyComponent>;
}
// good
render() {
return (
<MyComponent className="long body" foo="bar">
<MyChild />
</MyComponent>
);
}
// good, when single line
render() {
const body = <div>hello</div>;
return <MyComponent>{body}</MyComponent>;
}
-- Bind Event
// bad
class extends React.Component {
onClickDiv() {
// do stuff
}
render() {
return <div onClick={this.onClickDiv.bind(this)} />
}
}
// good
class extends React.Component {
constructor(props) {
super(props);
this.onClickDiv = this.onClickDiv.bind(this);
}
onClickDiv() {
// do stuff
}
render() {
return <div onClick={this.onClickDiv} />
}
}
-- Do not use underscore prefix for internal function
// bad
React.createClass({
_onClickSubmit() {
// do stuff
},
// other stuff
});
// good
class extends React.Component {
onClickSubmit() {
// do stuff
}
// other stuff
}
Airbnb Style Guide 참고
React/JSX Style Guide
React/JSX Ordering
- optional static methods
- constructor
- getChildContext
- componentWillMount
- componentDidMount
- componentWillReceiveProps
- shouldComponentUpdate
- componentWillUpdate
- componentDidUpdate
- componentWillUnmount
- clickHandlers or eventHandlers like onClickSubmit() or onChangeDescription()
- getter methods for render like getSelectReason() or getFooterContent()
- Optional render methods like renderNavigation() or renderProfilePicture()
- render
React/JSX Style Guide
React/JSX Ordering
- How to define propTypes, defaultProps, contextTypes, etc...
import React, { PropTypes } from 'react';
const propTypes = {
id: PropTypes.number.isRequired,
url: PropTypes.string.isRequired,
text: PropTypes.string,
};
const defaultProps = {
text: 'Hello World',
};
class Link extends React.Component {
static methodsAreOk() {
return true;
}
render() {
return <a href={this.props.url} data-id={this.props.id}>{this.props.text}</a>
}
}
Link.propTypes = propTypes;
Link.defaultProps = defaultProps;
export default LinkFunction Style Guide
-- 표기(CamelCase)
// bad
TestCaseOrder(){
// do stuff
}
// good
testCaseOrder(){
// do stuff
}
-- 일반적인 생성 규칙(동사 + 명사)
// bad
orderList(){
// do stuff
}
// good
getOrderStore(){
// do stuff
}
-- 컴포넌트에 종속적인 Function인 경우의 생성 규칙(동사 + 컴포넌트 + 명사)
// bad
getOrderList(){
// do stuff
}
// good
getGridOrderList(){
// do stuff
}Code Style
Function Style Guide
접미사(Prefix)
| 접미사 | Action |
|---|---|
| do | 저장, 수정, 삭제, 다운로드, 그 외의 백앤드 통신 |
| get | 데이터나 return 을 제공하는 경우 |
| set | 데이터나 parameter를 변경하는 경우 그 외 화면의 변경이 필요한 경우 |
| on | click 이나 그 외의 버튼 이벤트(화면제어) |
| bind | 이벤트 bind function |
| init | 초기화 관련 Function(화면) |
Function Style Guide
Code Style
Framework 표준어 Guide
Angular Foundation
By jungyoungtai
Angular Foundation
Augular 기초 자료
- 708