Object vs Record in ImmutableJS - seowonintech/react-native-todo-list GitHub Wiki
์ ์ฐ๋ฆฌ๋ Object ๋์ Record๋ฅผ ์จ์ผํ๋๊ฐ?
์๋ ์ฐธ๊ณ ์๋ฃ๋ฅผ ๋ณด๋ฉด์ Record๋ C์์ ์ฐ๋ Structure์ ๋น์ทํ ์ฉ๋๋ก ์ฌ์ฉํ๋ ๊ตฌ๋ ๋ผ๊ณ ์๊ฐ์ด ๋ค์๋ค.
์ผ๋ฐ Object ๋๋น Record์ ์ฅ์
- They're self-documenting. (Record๋ก ์์ฑํ๋ ๋ฉค๋ฒ๋ค์ ํ๋ฒ ์๋ฏธํ์
์ด ์ฝ๊ฒ naming์
(self-documenting)ํ๋ฉด ๊ณ์ ๊ทธ๋ ๊ฒ ์ฌ์ฉ๋ ์ ๋ฐ์ ์์) - They enforce strict code quality. (์ฒ์์ ์์ฑํ ๋์ ๊ตฌ์กฐ๊ฐ ๋ณ๊ฒฝ๋ ์ ์๋ค.)
- They combine the benefits of ImmutableJS' Map() with normal JS objects. (์ผ๋ฐ Object์
Map()์ ๋ค์ด์๋ ๊ฐ๋ ฅํ ๋ด์ฅ ํจ์๋ค๋ ์ฌ์ฉํ ์ ์๋ค) - You can use
getInwithin maps and records. If a map contains records you can read record's values usinggetIn. (getIn์ด๋ผ๋ ํจ์๋ฅผ ์ฌ์ฉํ ์ ์๋ค. Record์์ ํฌํจ๋ ๋ค๋ฅธ ImmutableJS ๊ฐ์ฒด์ ๊ฐ์ ์ง์ ์์ธ์ค๊ฐ ๊ฐ๋ฅํ๋ค.)
'use strict';
import { Record, Map } from 'immutable';
export const Post = new Record({
id: undefined,
title: '',
content: '',
author: undefined
comments: new Map()
});const data = new Map({
somePost: new Post({ title: 'some post' })
});
console.log(data.getIn(['somePost', 'title'])); // === 'some post';