본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Primer::TimeAgoComponent에서 이전하기

원문 보기 위키 갱신

Primer::TimeAgoComponent에서 이전하기 (Moving Away From Primer::TimeAgoComponent)

이 가이드는 이제 deprecated된 Primer::TimeAgoComponent에서 최신 Primer::Beta::RelativeTime 컴포넌트로 업그레이드하는 방법을 보여줍니다.

출처: 문서

본문

이 가이드는 이제 deprecated된 Primer::TimeAgoComponent에서 최신 Primer::Beta::RelativeTime 컴포넌트로 업그레이드하는 방법을 보여줍니다.

마이그레이션 예시 (A Migration Example)

TimeAgoComponent 컴포넌트의 사용은 몇 가지 사소한 변경만으로 마이그레이션할 수 있습니다.

예를 들어, TimeAgoComponent가 이렇게 설정되어 있었다면:

<%= render(Primer::TimeAgoComponent.new(time: Time.at(628232400))) %>

time을 datetime으로 이름을 바꾸고 tense: :past 설정을 추가해 마이그레이션할 수 있습니다.

<%= render(Primer::Beta::RelativeTime.new(datetime: Time.at(628232400), tense: :past)) %>

인자 (Arguments)

RelativeTime에서 제공되는 옵션의 대부분은 이를 TimeAgo의 대체로 사용할 때는 관련이 없습니다. 그러나 몇 가지 변경 사항을 알아두어야 합니다.

From Primer::TimeAgoComponent To Primer::Beta::RelativeTime Notes
time datetime Renamed argument, but the semantics remain the same
micro format: :micro Instead of a boolean flag, set the format argument to the value of :micro
n/a tense: :past Required for displaying how long ago the set time was. This argument tells RelativeTime to behave like TimeAgo did.

RelativeTime의 나머지 인자는 해당 컴포넌트의 문서에서 찾을 수 있습니다.

완전한 설명과 예시는 다음을 참고하세요.

  • Primer::Beta::RelativeTime component
  • Primer::Beta::RelativeTime Lookbook examples

← Back to development docs

더 알아보기 (Learn more)

  • Primer::Beta::RelativeTime 컴포넌트 문서에서 전체 인자 목록을 확인해 보세요.
  • tense: :past를 사용해 기존 TimeAgo처럼 "얼마나 오래 전"을 표시하도록 유지해 보세요.
  • 이전 boolean micro 플래그는 format: :micro로 대체되었음을 참고하세요.