Skip to content

Instantly share code, notes, and snippets.

@AkshayChordiya
Created July 5, 2017 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkshayChordiya/80fc62d271d41e99cf82cea617bb1194 to your computer and use it in GitHub Desktop.
Save AkshayChordiya/80fc62d271d41e99cf82cea617bb1194 to your computer and use it in GitHub Desktop.
ViewModelStore
public class ViewModelStore {
private final HashMap<String, ViewModel> mMap = new HashMap();
public ViewModelStore() {}
final void put(String key, ViewModel viewModel) {
ViewModel oldViewModel = (ViewModel)this.mMap.get(key);
if(oldViewModel != null) {
oldViewModel.onCleared();
}
this.mMap.put(key, viewModel);
}
final ViewModel get(String key) {
return (ViewModel)this.mMap.get(key);
}
public final void clear() {
Iterator var1 = this.mMap.values().iterator();
while(var1.hasNext()) {
ViewModel vm = (ViewModel)var1.next();
vm.onCleared();
}
this.mMap.clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment