Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'kotlin-multiplatform'
archivesBaseName = 'redux-kotlin-reselect'

group 'org.reduxkotlin'
version '0.2.5'
version '0.2.7'

kotlin {
jvm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ fun <S,O> S.whenChangeOf(selector: Selector<S, O>, blockfn: (O) -> Unit) {
* abstract base class for all selectors
*/
abstract class AbstractSelector<S, O> : Selector<S, O> {
fun invoke(tmp: ()-> Unit): O {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

@JvmField protected var recomputationsLastChanged = 0L
@JvmField protected var _recomputations = 0L
override val recomputations: Long get() = _recomputations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.reduxkotlin


/**
* A Selector Subscriber - group of selectors that subscribe to store state changes.
*
* @param State is the type of the state object returned by the store.
* @property store The redux store
* @constructor creates an empty SelectorSubscriberBuilder
*/
class SelectorSubscriberBuilder<State : Any>(val store: Store) {

private val selectorList = mutableMapOf<Selector<State, Any>, (Any) -> Unit>()

//state is here to make available to lambda with receiver in DSL
val state: State
get() = store.getState() as State

var withAnyChangeFun: (() -> Unit)? = null

fun withAnyChange(f: () -> Unit) {
withAnyChangeFun = f
}


fun withSingleField(selector: (State) -> Any, action: (Any) -> Unit) {
val selBuilder = SelectorBuilder<State>()
val sel = selBuilder.withSingleField(selector)
selectorList[sel] = action
}

infix fun SelectorSubscriberBuilder<State>.select(selector: (State) -> Any): AbstractSelector<State, Any> =
SelectorBuilder<State>().withSingleField(selector)

infix fun SelectorSubscriberBuilder<State>.on(selector: (State) -> Any): AbstractSelector<State, Any> =
SelectorBuilder<State>().withSingleField(selector)

operator fun (() -> Any).unaryPlus(): AbstractSelector<State, Any> {
val that = this
return SelectorBuilder<State>().withSingleField { that() }
}

infix fun AbstractSelector<State, Any>.then(action: (Any) -> Unit) {
selectorList[this] = action
}

infix operator fun AbstractSelector<State, Any>.plus(action: (Any) -> Unit) {
selectorList[this] = action
}
}


44 changes: 0 additions & 44 deletions lib/src/commonMain/kotlin/org/reduxkotlin/builders.kt

This file was deleted.

2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pluginManagement {
}

include ':lib'
rootProject.name='Redux-Kotlin-thunk'
rootProject.name='Redux-Kotlin-reselect'


rootProject.name = 'test'
Expand Down