{"id":25216362,"url":"https://github.com/shirozatou/rem","last_synced_at":"2026-05-01T09:31:17.794Z","repository":{"id":276841671,"uuid":"926405010","full_name":"shirozatou/rem","owner":"shirozatou","description":"Remember any type of object with ViewModel. Scoped ViewModel Store.","archived":false,"fork":false,"pushed_at":"2025-10-05T12:07:07.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-05T14:23:36.768Z","etag":null,"topics":["android-library","compose-multiplatform","compose-multiplatform-library","viewmodel"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shirozatou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-03T07:33:28.000Z","updated_at":"2025-10-05T12:00:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"86898a23-a500-45d6-9eca-e68d2e1a0c69","html_url":"https://github.com/shirozatou/rem","commit_stats":null,"previous_names":["shirozatou/rem"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/shirozatou/rem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirozatou%2Frem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirozatou%2Frem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirozatou%2Frem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirozatou%2Frem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shirozatou","download_url":"https://codeload.github.com/shirozatou/rem/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirozatou%2Frem/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32492081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-library","compose-multiplatform","compose-multiplatform-library","viewmodel"],"created_at":"2025-02-10T19:17:50.285Z","updated_at":"2026-05-01T09:31:17.783Z","avatar_url":"https://github.com/shirozatou.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rem\n\nRemember any type of object with ViewModel. No Parcelable, just in-memory. (Why not?)\n\n## Dependency\n\n`implementation(\"io.github.shirozatou:rem:1.2.0\")`\n\n## Usage\n\n```kotlin\nremember {\n    Any() // ❌ Evaluated again when screen rotated\n}\nrememberSaveable {\n    Any() // ❌ IllegalArgumentException. Cannot be stored to Bundle (Android)\n}\nrememberWithViewModel {\n    Any() // 🥳 Restore from ViewModel when screen rotated\n}\n```\n\nRemembered value is forget when\n- once goes out of scope\n- key changed\n- viewModel in current scope is cleared\n\n### Clean up\n\nCurrently only instance of `Clearable` is allowed.\n```kotlin\nvar flag by remember { mutableStateOf(true) }\nif (flag) {\n    val foo = rememberWithViewModel(key) {\n        object : Clearable {\n            val data = Any()\n            override fun onCleared() {\n                // Called on main thread once flag == false\n            }\n        }\n    }.data\n}\n```\n\n### Can I remember ViewModel with rememberWithViewModel?\n\nViewModel should be managed by `ViewModelStoreOwner`\n\nFor scoped ViewModel, use `ScopedViewModelStore`:\n\n```kotlin\nScopedViewModelStore {\n    val v1 = viewModel\u003cYourViewModel\u003e()\n    val v2 = viewModel\u003cYourViewModel\u003e()\n\n    ScopedViewModelStore {\n        val v3 = viewModel\u003cYourViewModel\u003e()\n\n        assert(v1 === v2)\n        assert(v1 !== v3)\n    }\n}\n```\nScopedViewModelStore is a simple trick btw.\n```kotlin\n@Composable\nfun ScopedViewModelStore(content: @Composable () -\u003e Unit) {\n    val viewModelStoreOwner = rememberWithViewModel {\n        object : ViewModelStoreOwner, Clearable {\n            override val viewModelStore: ViewModelStore = ViewModelStore()\n            override fun onCleared() {\n                viewModelStore.clear()\n            }\n        }\n    }\n    CompositionLocalProvider(\n        LocalViewModelStoreOwner provides viewModelStoreOwner,\n        content = content\n    )\n}\n```\n\n### Solution for LazyList\n```kotlin\nScopedSaveableStateRegistry {\n    LazyColumn {\n        items(count = 100) {\n            val remembered = rememberSaveable {\n                Any() // You can remember any type of object here\n            }\n            val notRemembered = rememberWithViewModel {\n                Any()\n            }\n            Text(text = remembered.toString())\n            Text(text = notRemembered.toString())\n        }\n    }\n}\n```\n\n### Reminder\n\nSimilar to `ViewModel`, don't leak `Context` or something.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshirozatou%2Frem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshirozatou%2Frem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshirozatou%2Frem/lists"}