SlideShare a Scribd company logo
1 of 22
Download to read offline
Lea Cohen Tannoudji / Dec. 19
MVVM in
Real Life
MVVM IN REAL LIFE
About me
Lea Cohen Tannoudji
B.Sc in Computational Biology at Hebrew
University
Android developer @ Lightricks
MVVM IN REAL LIFE
• 2013: Founded, 2019: Unicorn
Content creation products based on image &
video processing technology



• 200+ million downloads and counting
• 310 Employees
HQ in Israel, branches in the UK and Germany
Introducing Lightricks
MVVM IN REAL LIFE
MVVM IN REAL LIFE
Enlight Pixaloop
MVVM IN REAL LIFE
MVVM
An architectural pattern that facilitates a
separation of GUI (View) from business
logic (Model).
ViewModel is a value converter,
responsible for exposing data objects
from the model for presenting.
MVVM IN REAL LIFE
MVVM - Why?
• Clear separation of responsibilities
• Maintainable
• Testable
• Allows reusing of Model
• Allows lean Views
MVVM IN REAL LIFE
Assumptions
• One ViewModel per Fragment/Activity
• ViewModel to View communications done
using LiveData
MVVM IN REAL LIFE
LiveData
An observable data holder class.
Lifecycle- aware, only updates app component
observers that are in active lifecycle state.
It’s great, but….
MVVM IN REAL LIFE
MVVM IN REAL LIFE
Lesson #1: Save state
Explicitly
VMs are stored in memory, and are designed
to survive configuration changes.
MVVM IN REAL LIFE
Lesson #1: Save state
Explicitly
They may NOT survive in cases of low memory
(killed by OS).
MVVM IN REAL LIFE
Save state Explicitly -
Example
Save state
Explicitly -
Solved
• ViewModel state
• Use onSaveInstanceState() (disk
persistent) for simple, lightweight
state.
• Save to storage (external  internal )
or SQL database.
MVVM IN REAL LIFE
Persistability
Lesson #2: Multiple Vs.
Single LiveData Objects
Multiple LiveData objects, for each responsibility (i.e
toolbarLiveData, isProUserLiveData, previewLiveData).
Vs.
Single LiveData, containing all the data needed to
draw the fragment.
MVVM IN REAL LIFE
Single
LiveData -
Why ?
• Single source of truth
• Allows synchronous screen changes (i.e animations)
because Ui related logic is run on the main thread.
Note: calculating diff between old and new data need to be
efficient for this to work well.
As a rule: any stream should pass immutable objects since
changing an existing object is a source of bugs.
MVVM IN REAL LIFE
MVVM IN REAL LIFE
Lesson #3: Single
LiveData Events
LiveData can be used to tell the Fragment to
display data in some form (Toast, AlertDialog
etc.)
However, this data needs to be displayed
only once.
MVVM IN REAL LIFE
Single
LiveData
Events -
Solved
• Create SingleEventLiveData which
posts/sets every event only once 
Or
• Wrap the event, allowing access only
if it hasn’t been handled
MVVM IN REAL LIFE
MVVM IN REAL LIFE
Conclusion
• Save VM state explicitly
• Consider using single LiveData for Ui updates
• Handling one time events using LiveData
Enlight Pixaloop Enlight Videoleap
MVVM IN REAL LIFE
Come build cool apps with us!
Enlight Photofox
Thank
You!
lea@lightricks.com

More Related Content

Similar to MVVM In real life - Lea Cohen Tannoudji, Lightricks

Avoiding the domino effect in our [micro]services (SOLID at macro-design level)
Avoiding the domino effect in our [micro]services (SOLID at macro-design level)Avoiding the domino effect in our [micro]services (SOLID at macro-design level)
Avoiding the domino effect in our [micro]services (SOLID at macro-design level)
CodelyTV
 
ANDROID presentation prabal
ANDROID presentation prabalANDROID presentation prabal
ANDROID presentation prabal
Prabal Tyagi
 

Similar to MVVM In real life - Lea Cohen Tannoudji, Lightricks (20)

Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
SunMicroSystems
SunMicroSystemsSunMicroSystems
SunMicroSystems
 
Ios development 2
Ios development 2Ios development 2
Ios development 2
 
App specific app architecture
App specific app architectureApp specific app architecture
App specific app architecture
 
Sunstate
SunstateSunstate
Sunstate
 
DDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan PaulovichDDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan Paulovich
 
Sunstate
SunstateSunstate
Sunstate
 
Android architecture components - how they fit in good old architectural patt...
Android architecture components - how they fit in good old architectural patt...Android architecture components - how they fit in good old architectural patt...
Android architecture components - how they fit in good old architectural patt...
 
MVVM for Modern Applications
MVVM for Modern ApplicationsMVVM for Modern Applications
MVVM for Modern Applications
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
Building databound JavaScript apps with Knockoutjs
Building databound JavaScript apps with KnockoutjsBuilding databound JavaScript apps with Knockoutjs
Building databound JavaScript apps with Knockoutjs
 
JAVA PROGRAMMING (1).pptx
JAVA PROGRAMMING (1).pptxJAVA PROGRAMMING (1).pptx
JAVA PROGRAMMING (1).pptx
 
Avoiding the domino effect in our [micro]services (SOLID at macro-design level)
Avoiding the domino effect in our [micro]services (SOLID at macro-design level)Avoiding the domino effect in our [micro]services (SOLID at macro-design level)
Avoiding the domino effect in our [micro]services (SOLID at macro-design level)
 
Lean Engineering. Applying Lean Principles to Building Experiences
Lean Engineering. Applying Lean Principles to Building ExperiencesLean Engineering. Applying Lean Principles to Building Experiences
Lean Engineering. Applying Lean Principles to Building Experiences
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
ANDROID presentation prabal
ANDROID presentation prabalANDROID presentation prabal
ANDROID presentation prabal
 
Adaptive fault tolerance_in_real_time_cloud_computing
Adaptive fault tolerance_in_real_time_cloud_computingAdaptive fault tolerance_in_real_time_cloud_computing
Adaptive fault tolerance_in_real_time_cloud_computing
 
Windows phone and azure
Windows phone and azureWindows phone and azure
Windows phone and azure
 
iOS Development (Part 2)
iOS Development (Part 2)iOS Development (Part 2)
iOS Development (Part 2)
 
IRJET- Implementation of Cloud Energy Saving System using Virtual Machine...
IRJET-  	  Implementation of Cloud Energy Saving System using Virtual Machine...IRJET-  	  Implementation of Cloud Energy Saving System using Virtual Machine...
IRJET- Implementation of Cloud Energy Saving System using Virtual Machine...
 

More from DroidConTLV

More from DroidConTLV (20)

Mobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, NikeMobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, Nike
 
Doing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra TechnologiesDoing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra Technologies
 
No more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola SolutionsNo more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola Solutions
 
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.comMobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
 
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, ClimacellLiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
 
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
 
Building Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice NinjaBuilding Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice Ninja
 
New Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy ZukanovNew Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy Zukanov
 
Designing a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, GettDesigning a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, Gett
 
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, PepperThe Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
 
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDevKotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
 
Flutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, TikalFlutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, Tikal
 
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bisReactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
 
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevelFun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
 
DroidconTLV 2019
DroidconTLV 2019DroidconTLV 2019
DroidconTLV 2019
 
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, MondayOk google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
 
Introduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, WixIntroduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, Wix
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
 
Educating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz TamirEducating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz Tamir
 
Constraint-ly motion - making your app dance - John Hoford, Google
Constraint-ly motion - making your app dance - John Hoford, GoogleConstraint-ly motion - making your app dance - John Hoford, Google
Constraint-ly motion - making your app dance - John Hoford, Google
 

Recently uploaded

TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

MVVM In real life - Lea Cohen Tannoudji, Lightricks

  • 1. Lea Cohen Tannoudji / Dec. 19 MVVM in Real Life
  • 2. MVVM IN REAL LIFE About me Lea Cohen Tannoudji B.Sc in Computational Biology at Hebrew University Android developer @ Lightricks
  • 3. MVVM IN REAL LIFE • 2013: Founded, 2019: Unicorn Content creation products based on image & video processing technology
 
 • 200+ million downloads and counting • 310 Employees HQ in Israel, branches in the UK and Germany Introducing Lightricks
  • 5. MVVM IN REAL LIFE Enlight Pixaloop
  • 6. MVVM IN REAL LIFE MVVM An architectural pattern that facilitates a separation of GUI (View) from business logic (Model). ViewModel is a value converter, responsible for exposing data objects from the model for presenting.
  • 7. MVVM IN REAL LIFE MVVM - Why? • Clear separation of responsibilities • Maintainable • Testable • Allows reusing of Model • Allows lean Views
  • 8. MVVM IN REAL LIFE Assumptions • One ViewModel per Fragment/Activity • ViewModel to View communications done using LiveData
  • 9. MVVM IN REAL LIFE LiveData An observable data holder class. Lifecycle- aware, only updates app component observers that are in active lifecycle state.
  • 11. MVVM IN REAL LIFE Lesson #1: Save state Explicitly VMs are stored in memory, and are designed to survive configuration changes.
  • 12. MVVM IN REAL LIFE Lesson #1: Save state Explicitly They may NOT survive in cases of low memory (killed by OS).
  • 13. MVVM IN REAL LIFE Save state Explicitly - Example
  • 14. Save state Explicitly - Solved • ViewModel state • Use onSaveInstanceState() (disk persistent) for simple, lightweight state. • Save to storage (external internal ) or SQL database. MVVM IN REAL LIFE Persistability
  • 15. Lesson #2: Multiple Vs. Single LiveData Objects Multiple LiveData objects, for each responsibility (i.e toolbarLiveData, isProUserLiveData, previewLiveData). Vs. Single LiveData, containing all the data needed to draw the fragment. MVVM IN REAL LIFE
  • 16. Single LiveData - Why ? • Single source of truth • Allows synchronous screen changes (i.e animations) because Ui related logic is run on the main thread. Note: calculating diff between old and new data need to be efficient for this to work well. As a rule: any stream should pass immutable objects since changing an existing object is a source of bugs. MVVM IN REAL LIFE
  • 17. MVVM IN REAL LIFE Lesson #3: Single LiveData Events LiveData can be used to tell the Fragment to display data in some form (Toast, AlertDialog etc.) However, this data needs to be displayed only once.
  • 18. MVVM IN REAL LIFE
  • 19. Single LiveData Events - Solved • Create SingleEventLiveData which posts/sets every event only once  Or • Wrap the event, allowing access only if it hasn’t been handled MVVM IN REAL LIFE
  • 20. MVVM IN REAL LIFE Conclusion • Save VM state explicitly • Consider using single LiveData for Ui updates • Handling one time events using LiveData
  • 21. Enlight Pixaloop Enlight Videoleap MVVM IN REAL LIFE Come build cool apps with us! Enlight Photofox