Skip to content

Commit 39a1253

Browse files
authored
Merge pull request #1 from reduxkotlin/pj-update-builders
package update on SelectorSubscriberBuilder and minor changes
2 parents a89aea4 + c40ae46 commit 39a1253

File tree

5 files changed

+58
-46
lines changed

5 files changed

+58
-46
lines changed

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ apply plugin: 'kotlin-multiplatform'
77
archivesBaseName = 'redux-kotlin-reselect'
88

99
group 'org.reduxkotlin'
10-
version '0.2.5'
10+
version '0.2.7'
1111

1212
kotlin {
1313
jvm()

lib/src/commonMain/kotlin/org/reduxkotlin/reselect.kt renamed to lib/src/commonMain/kotlin/org/reduxkotlin/Reselect.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ fun <S,O> S.whenChangeOf(selector: Selector<S, O>, blockfn: (O) -> Unit) {
138138
* abstract base class for all selectors
139139
*/
140140
abstract class AbstractSelector<S, O> : Selector<S, O> {
141+
fun invoke(tmp: ()-> Unit): O {
142+
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
143+
}
144+
141145
@JvmField protected var recomputationsLastChanged = 0L
142146
@JvmField protected var _recomputations = 0L
143147
override val recomputations: Long get() = _recomputations
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.reduxkotlin
2+
3+
4+
/**
5+
* A Selector Subscriber - group of selectors that subscribe to store state changes.
6+
*
7+
* @param State is the type of the state object returned by the store.
8+
* @property store The redux store
9+
* @constructor creates an empty SelectorSubscriberBuilder
10+
*/
11+
class SelectorSubscriberBuilder<State : Any>(val store: Store) {
12+
13+
private val selectorList = mutableMapOf<Selector<State, Any>, (Any) -> Unit>()
14+
15+
//state is here to make available to lambda with receiver in DSL
16+
val state: State
17+
get() = store.getState() as State
18+
19+
var withAnyChangeFun: (() -> Unit)? = null
20+
21+
fun withAnyChange(f: () -> Unit) {
22+
withAnyChangeFun = f
23+
}
24+
25+
26+
fun withSingleField(selector: (State) -> Any, action: (Any) -> Unit) {
27+
val selBuilder = SelectorBuilder<State>()
28+
val sel = selBuilder.withSingleField(selector)
29+
selectorList[sel] = action
30+
}
31+
32+
infix fun SelectorSubscriberBuilder<State>.select(selector: (State) -> Any): AbstractSelector<State, Any> =
33+
SelectorBuilder<State>().withSingleField(selector)
34+
35+
infix fun SelectorSubscriberBuilder<State>.on(selector: (State) -> Any): AbstractSelector<State, Any> =
36+
SelectorBuilder<State>().withSingleField(selector)
37+
38+
operator fun (() -> Any).unaryPlus(): AbstractSelector<State, Any> {
39+
val that = this
40+
return SelectorBuilder<State>().withSingleField { that() }
41+
}
42+
43+
infix fun AbstractSelector<State, Any>.then(action: (Any) -> Unit) {
44+
selectorList[this] = action
45+
}
46+
47+
infix operator fun AbstractSelector<State, Any>.plus(action: (Any) -> Unit) {
48+
selectorList[this] = action
49+
}
50+
}
51+
52+

lib/src/commonMain/kotlin/org/reduxkotlin/builders.kt

Lines changed: 0 additions & 44 deletions
This file was deleted.

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pluginManagement {
99
}
1010

1111
include ':lib'
12-
rootProject.name='Redux-Kotlin-thunk'
12+
rootProject.name='Redux-Kotlin-reselect'
1313

1414

1515
rootProject.name = 'test'

0 commit comments

Comments
 (0)