Skip to content

Commit

Permalink
Use Injekt instead of Dagger
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Egan committed Feb 9, 2016
1 parent 3d938f4 commit 14cacc7
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 82 deletions.
6 changes: 1 addition & 5 deletions examples/counter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,14 @@ buildscript {
}

dependencies {
kapt 'com.squareup.dagger:dagger-compiler:1.2.2'

compile project(':bansa')

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'co.trikita:anvil-sdk15:0.2.0'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'io.reactivex:rxjava:1.0.16'
compile "uy.kohesive.injekt:injekt-core:1.12.+"
compile 'io.reactivex:rxandroid:1.0.1'
compile 'com.android.support:design:23.1.1'
compile 'com.jakewharton.rxbinding:rxbinding:0.3.0'
compile 'com.jakewharton.rxbinding:rxbinding-support-v4:0.3.0'

testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:1.7.1'
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package com.brianegan.bansa.counter

import com.brianegan.bansa.counter.ApplicationModule
import com.brianegan.bansa.counter.StoreModule
import dagger.ObjectGraph
import com.brianegan.bansa.Action
import com.brianegan.bansa.Store
import com.brianegan.bansa.createStore
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.InjektMain
import uy.kohesive.injekt.api.InjektRegistrar
import uy.kohesive.injekt.api.fullType
import uy.kohesive.injekt.api.get

class Application : android.app.Application() {
var objectGraph: ObjectGraph? = null

override fun onCreate() {
super.onCreate()
instance = this
objectGraph = ObjectGraph.create(ApplicationModule(this), StoreModule())
companion object : InjektMain() {
override fun InjektRegistrar.registerInjectables() {
addSingleton(
fullType<Store<ApplicationState, Action>>(),
createStore(ApplicationState(), applicationReducer));
}
}

companion object {
private var instance: Application? = null
val store = Injekt.get(fullType<Store<ApplicationState, Action>>())

fun getObjectGraph(): ObjectGraph? {
return instance?.objectGraph
}
override fun onCreate() {
super.onCreate()
store.dispatch(CounterActions.INIT) // Initialize the store
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.brianegan.bansa.Action
import com.brianegan.bansa.Store
import javax.inject.Inject
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.fullType
import uy.kohesive.injekt.api.get

public open class RootActivity : AppCompatActivity() {
@Inject lateinit var store: Store<ApplicationState, Action>
open class RootActivity : AppCompatActivity() {
val store: Store<ApplicationState, Action> = Injekt.get(fullType<Store<ApplicationState, Action>>())

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Application.getObjectGraph()?.inject(this)
store.dispatch(CounterActions.INIT) // Initialize the store
setContentView(RootView(this, store)) // Set the root view
setContentView(RootView(this, store))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import trikita.anvil.Anvil
import trikita.anvil.DSL.*
import trikita.anvil.RenderableView

public class RootView(c: Context, val store: Store<ApplicationState, Action>) : RenderableView(c) {
class RootView(c: Context, val store: Store<ApplicationState, Action>) : RenderableView(c) {
override fun view() {
template(buildPresentationModel())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ fun <A : Action, S : State, VM> connect(
view(mapStoreToViewModel(store))
}
}


}
3 changes: 1 addition & 2 deletions examples/listOfTrendingGifs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ dependencies {
compile 'io.reactivex:rxjava:1.0.16'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'com.android.support:design:23.1.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.android.support:support-v4:23.0.2'

compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp3:okhttp:3.0.1'
compile 'com.squareup.moshi:moshi:1.1.0'

testCompile "org.jetbrains.spek:spek:0.1.194"
testCompile 'org.assertj:assertj-core:1.7.1'
compile 'com.squareup.picasso:picasso:2.5.2'
}

0 comments on commit 14cacc7

Please sign in to comment.