Skip to content

Conversation

@MisterJerry123
Copy link

PR 타이틀

stateflow 활용 간단한 메모 앱 만들기 (stateflow-> stateflow+Repository pattern)

PR 생성 날짜

2024/10/11

PR 내용

기존 LiveData로 구현한 방식에서 stateflow를 이용하여 설계
잘못 설계한 비즈니스 로직 개선

  • Repository 패턴을 활용하여 저장하는 비즈니스 로직 설계

로직 구성

  • 초기 앱 실행 시 ViewModel클래스에서 repository에서 받아온 값을 emit(방출) (※이때 repository에서 받아온 값은 SharedPreference에 저장된 값)
  • MainActivity에서는 ViewModel클래스의 currentValue를 collect하여 emit한 값이 있는지 감시
  • 저장버튼을 누를 경우 ViewModel클래스로 입력 값을 넘기고 ViewModel클래스에서는 repository로 또 값을 넘겨 실질적으로 repository가 SharedPreference에 값을 저장
  • emit한 값을 collect한 경우 EditText의 값을 변경

질문

SharedPreference에 저장하는 로직은 MainActivity에 들어가야하나요 아니면 ViewModel에 들어가야 하나요? (Repository 패턴으로 해결)

@SeonghwiShin SeonghwiShin self-requested a review October 31, 2024 04:19
@SeonghwiShin
Copy link
Contributor

저거 하나빼곤 잘하셨씁니당

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.

2 participants