Skip to content

Conversation

heenakwag
Copy link
Member

  • Support the bracket notation of an object

Before (v2.1.0)

template('{{obj[key]}}', {
    obj: {
        name: "CodeSnippet"
    },
    key: "name" // Object's key should be stored in the context.
});

After (v2.1.1)

template('{{obj["name"]}}', {  // Object's key, "name", can be used without storing in the context.
    obj: {
        name: "CodeSnippet"
    }
});

* ex) '{{title}}' with context {title: 'Hello!'} is converted to 'Hello!'.
* An array or object can be accessed using bracket notation.
* ex) '{{odds[2]}}' with context {odds: [1, 3, 5]} is converted to '5'.
* ex) '{{evens[first]}}' with context {evens: [2, 4], first: 0} is converted to '2'.
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 Author

Choose a reason for hiding this comment

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

each 안에서 @this@index로 프로퍼티를 접근하는 경우도 있어서 이 표현식을 유용하게 쓸 것 같은데, 그대로 유지하는게 낫지 않을까요?

const source = '{{each disabled}}{{fruits[@this]}} + {{/each}}'; 
const context = {
  disabled: [1, 2, 4],
  fruits: ['apple', 'banana', 'grape', 'orange', 'melon']
};

console.log(template(source, context)); // banana + grape  + melon + 

Copy link
Member

@seonim-ryu seonim-ryu left a comment

Choose a reason for hiding this comment

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

[12/6] 리뷰 완료합니다. 고생하셨어요~ 요건 코멘트 드린대로 표현식 사용 방식에 대해서 조금 고민해보고 넘어가야될 것 같습니다.

Copy link
Member

@jung-han jung-han left a comment

Choose a reason for hiding this comment

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

이견 없습니다~
버전이 v2.1.1 대신 v2.2.0 으로 올라가야 하지 않을까요?

@heenakwag heenakwag merged commit 5b91727 into master Dec 11, 2019
@heenakwag heenakwag deleted the feat/bracket-notation-with-quotes branch December 11, 2019 23:07
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.

3 participants