Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Nakhimovich digitalbuddha

View GitHub Profile
View HiltUserComponent.kt
@DefineComponent(parent = ApplicationComponent::class)
internal interface UserComponent
@DefineComponent.Builder
internal interface UserComponentBuilder {
fun withUserId(@BindsInstance userId: Int): UserComponentBuilder
fun build(): UserComponent
}
@DefineComponent(parent = UserComponent::class)
View MvrxRenderer.kt
MyMvrxViewModel<State, Rendering>(services:Services, userId:String, loadingVM: LoadingViewModel, dataVM:DataViewModel){
sealed class State{
object Loading():State
data class Data(value:String)
}
override fun render(context:RenderScope, state:State):{
View Foo.kt
interface Foo{
fun doStuff()
companion object
}
fun Foo.Companion.CreateFoo():Foo = RealFoo()
private class RealFoo : Foo{
View Foo.kt
interface Foo{
fun doStuff()
companion object
}
fun Foo.Companion.CreateFoo():Foo = RealFoo()
private class RealFoo : Foo{
View CreatStore.kt
Store<Article, Integer> store = StoreBuilder.<Integer, BufferedSource, Article>parsedWithKey()
.fetcher(articleId -> api.getArticles(articleId))
.persister(FileSystemPersister.create(FileSystemFactory.create(context.getFilesDir()), pathResolver))
.parser(GsonParserFactory.createSourceParser(gson, String.class))
.open();
View PipelinePersisterReactive.kt
val networkTrigger = Channel<Unit>(capacity = Channel.RENDEZVOUS)
val diskCommands = Channel<DiskCommand>(capacity = Channel.RENDEZVOUS)
launch {
// trigger first load
diskCommands.send(DiskCommand.ReadFirst)
}
val networkFlow = networkTrigger
.consumeAsFlow()
View sample.kt
class Mario(pipes:List<Pipeline>){
}
View RetroStore.kt
interface Api {
@GET("r/{subredditName}/new/.json")
@RefershOnStale
@Persister
fun subRedditStore(@Path("subredditName") subredditName: String): RetroStore<RedditData>
}
fun getData() {
View StoreCallAdapterFactory.kt
package com.jakewharton.retrofit2.adapter.kotlin.coroutines
import com.nytimes.android.external.store3.base.DiskRead
import com.nytimes.android.external.store3.base.DiskWrite
import com.nytimes.android.external.store3.base.Fetcher
import com.nytimes.android.external.store3.base.impl.RealStoreBuilder
import com.nytimes.android.external.store3.base.impl.Store
import com.nytimes.android.external.store3.base.impl.StoreBuilder
import com.nytimes.android.sample.data.remote.Persister
import com.nytimes.android.sample.data.remote.RefershOnStale
You can’t perform that action at this time.