Skip to content

Commit b01a7a8

Browse files
committed
Update changelog
1 parent 0e49973 commit b01a7a8

File tree

9 files changed

+164
-70
lines changed

9 files changed

+164
-70
lines changed

CHANGELOG.md

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
## Unreleased
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
---
9+
10+
## [Unreleased]
11+
12+
---
13+
14+
## [0.6.0]
215

316
### Added
417

518
- All missing ios, watchos, tvos and macos simulator targets added
619
- Added `androidNativeX64` and `androidNativeX86` targets
720
- Added proper android release and debug variants instead of piggybacking on jvm artefact
21+
- New and improved `typedReducer` and `createTypedStore` builders for those needing a simple action-typed store.
22+
Recommended to use with sealed interface hierarchies.
823

924
### Changed
1025

@@ -16,50 +31,74 @@
1631

1732
- Remove deprecated `wasm32` target
1833

34+
---
35+
1936
## [0.5.5] - 2020-08-16
2037

2138
- update to Kotlin 1.4.0
2239
- added platforms (androidNativeArm32, androidNativeArm64, iosArm32, linuxArm64, linuxX64,
2340
mingwX86, tvosArm64, tvosX64, watchosArm32, watchosArm64, watchosX86)
2441
- remove spek & atrium deps and use plain kotlin tests & assertions. Tests run for all platforms now.
2542

43+
---
44+
2645
## [0.5.2] - 2020-07-03
2746

2847
- publish all available platforms to maven
2948
- add CI/CD through github actions
3049

50+
---
51+
3152
## [0.5.1] - 2020-06-11
3253

3354
- update lib dependency to api import, so core lib is included in redux-kotlin-threadsafe
3455

56+
---
57+
3558
## [0.5.0] - 2020-06-11
3659

3760
- kotlin 1.3.72
3861
- createThreadSafeStore fun added for thread synchronized access
3962
- createEnsureSameThreadStore to provide existing same-thread-enforcement
4063

64+
---
65+
4166
## [0.4.0] - 2020-03-23
4267

4368
- kotlin 1.3.70
4469

70+
---
71+
4572
## [0.3.2] - 2020-02-22
4673

4774
- issue #34 - incorrect same thread enforcement behavior fixed
4875

76+
---
77+
4978
## [0.3.1] - 2019-12-16
5079

5180
### Changed
5281

5382
- update same thread enforcement message to not be getState only
5483

84+
---
85+
5586
## [0.3.0] - 2019-12-16
5687

5788
### Added
5889

5990
- thread enforcement
6091

92+
---
93+
6194
## [0.2.9] - 2019-11-23
6295

6396
### Changed
6497

6598
- update Kotlin to 1.3.60
99+
100+
---
101+
102+
[Unreleased]: https://github.com/reduxkotlin/redux-kotlin/compare/v0.6.0...HEAD
103+
[0.6.0]: https://github.com/reduxkotlin/redux-kotlin/compare/v0.5.5...0.6.0
104+
[0.5.5]: https://github.com/reduxkotlin/redux-kotlin/releases/tag/v0.5.5

README.md

+46-24
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
![badge][badge-linux]
1010
![badge][badge-windows]
1111
![badge][badge-mac]
12-
[![Slack chat](https://img.shields.io/badge/kotlinlang-%23redux-green?logo=slack&style=flat-square)](https://kotlinlang.slack.com/archives/C8A8G5F9Q)
12+
[![Slack chat](https://img.shields.io/badge/kotlinlang-%23redux-green?logo=slack&style=flat-square)][slack]
1313
[![Dokka docs](https://img.shields.io/badge/docs-dokka-orange?style=flat-square&logo=kotlin)](http://reduxkotlin.github.io/redux-kotlin)
1414
[![Version maven-central](https://img.shields.io/maven-central/v/org.reduxkotlin/redux-kotlin?logo=apache-maven&style=flat-square)](https://mvnrepository.com/artifact/org.reduxkotlin/redux-kotlin/latest)
1515
[![Version maven-snapshot](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Foss.sonatype.org%2Fcontent%2Frepositories%2Fsnapshots%2Forg%2Freduxkotlin%2Fredux-kotlin%2Fmaven-metadata.xml&logo=apache-maven&label=maven-snapshot&style=flat-square)](https://oss.sonatype.org/content/repositories/snapshots/org/reduxkotlin/redux-kotlin/)
@@ -18,23 +18,29 @@ A redux standard for Kotlin that supports multiplatform projects.
1818

1919
Full documentation at http://reduxkotlin.org.
2020

21-
## Misson Statement
21+
## Mission Statement
2222

23-
Provide a standard redux implementation for Kotlin. In doing so will foster a ecosystem of middleware, store
23+
Provide a standard redux implementation for Kotlin. In doing so will foster a ecosystem of
24+
middleware, store
2425
enhancers, & dev tools. These core values will guide descisions for the project:
2526

2627
* core redux-kotlin will be a minimal implementation that other libraries can build upon
2728
* modular development (follow example of https://github.com/reduxjs)
2829
* support for all platforms supported by Kotlin multiplatform (JVM, iOS, Native, JS, WASM)
29-
* developed in open and enable discussion for all interested parties via open channels (slack, github, etc. TBD)
30+
* developed in open and enable discussion for all interested parties via open channels (slack,
31+
github, etc. TBD)
3032
* not owned by a individual or company
3133

32-
Redux in Kotlin, and in mobile in particular, may differ a bit from javascript. Many have found the basic pattern useful
33-
on Android & iOS leading to tens of opensource redux libraries in Kotlin, Java, and Swift, yet an ecosystem has yet to
34-
emerge. A port of javascript redux is a good starting point for creating a standard and will aid in cross-pollination of
34+
Redux in Kotlin, and in mobile in particular, may differ a bit from javascript. Many have found the
35+
basic pattern useful
36+
on Android & iOS leading to tens of opensource redux libraries in Kotlin, Java, and Swift, yet an
37+
ecosystem has yet to
38+
emerge. A port of javascript redux is a good starting point for creating a standard and will aid in
39+
cross-pollination of
3540
middleware, store enhancers, & dev tools from the javascript world.
3641

37-
Redux has proven helpful for state management in mobile. A multiplatform Kotlin implementation & ecosystem will increase
42+
Redux has proven helpful for state management in mobile. A multiplatform Kotlin implementation &
43+
ecosystem will increase
3844
developer productivity and code reuse across platforms.
3945

4046
[Droidcon NYC Slides](https://www.slideshare.net/PatrickJackson14/reduxkotlinorg-droidcon-nyc-2019)
@@ -44,31 +50,35 @@ Video TBA
4450

4551
__How to add to project:__
4652

47-
Artifacts are hosted on maven central. They are published with gradle metadata, so you may need to enable
48-
with `enableFeaturePreview("GRADLE_METADATA")` in your settings.gradle file. For multiplatform, add the following to
53+
Artifacts are hosted on maven central. They are published with gradle metadata, so you may need to
54+
enable
55+
with `enableFeaturePreview("GRADLE_METADATA")` in your settings.gradle file. For multiplatform, add
56+
the following to
4957
your shared module:
5058

5159
```kotlin
5260
kotlin {
5361
sourceSets {
5462
commonMain { // <--- name may vary on your project
5563
dependencies {
56-
implementation("org.reduxkotlin:redux-kotlin-threadsafe:0.5.5")
64+
implementation("org.reduxkotlin:redux-kotlin-threadsafe:_")
5765
}
5866
}
5967
}
68+
}
6069
```
6170

6271
For JVM only:
6372

6473
```kotlin
65-
implementation("org.reduxkotlin:redux-kotlin-threadsafe-jvm:0.5.5")
74+
implementation("org.reduxkotlin:redux-kotlin-threadsafe-jvm:_>")
6675
```
6776

6877
*Non threadsafe store is available. Typical usage will be with the threadsafe
6978
store. [More info read here](https://www.reduxkotlin.org/introduction/getting-started)
7079

71-
Usage is very similar to JS Redux and those docs will be useful https://redux.js.org/. These docs are not an intro to
80+
Usage is very similar to JS Redux and those docs will be useful https://redux.js.org/. These docs
81+
are not an intro to
7282
Redux, and just documentation on Kotlin specific bits. For more info on Redux in general, check
7383
out https://redux.js.org/.
7484

@@ -136,11 +146,13 @@ You then will have access to dispatch and subscribe functions from the `store`.
136146
__Create a synchronized store__
137147

138148
```kotlin
139-
val store = createThreadSafeStore(reducer, AppState(user, listOf()), applyMiddleware(loggingMiddleware))
149+
val store =
150+
createThreadSafeStore(reducer, AppState(user, listOf()), applyMiddleware(loggingMiddleware))
140151
```
141152

142-
Access to `store` methods like `dispatch` and `getState` will be synchronized. Note: if using a thread safe store with
143-
enhancers or middleware that require access to store methods, see usage below.
153+
Access to `store` methods like `dispatch` and `getState` will be synchronized. Note: if using a
154+
thread safe store with enhancers or middleware that require access to store methods, see usage
155+
below.
144156

145157
__Create a synchronized store using an enhancer__
146158

@@ -155,19 +167,27 @@ val store = createStore(
155167
)
156168
```
157169

158-
Access to `store` methods like `dispatch` and `getState` will be synchronized, and enhancers (eg. `applyMiddleware`)
159-
that are placed above `createSynchronizedStoreEnhancer` in the enhancer composition chain will receive the synchronized
160-
store.
170+
Access to `store` methods like `dispatch` and `getState` will be synchronized, and enhancers (
171+
eg. `applyMiddleware`) that are placed above `createSynchronizedStoreEnhancer` in the enhancer
172+
composition chain will receive the synchronized store.
161173

162-
## Communication
174+
## Extensions
163175

164-
Want to give feedback, contribute, or ask questions?
176+
Here's a list of optional extensions available. Raise an issue to add yours!
165177

166-
__\#redux__ slack channel in [kotlinlang](https://kotlinlang.slack.com)
178+
- [redux-kotlin-thunk](https://github.com/reduxkotlin/redux-kotlin-thunk)
179+
- [redux-kotlin-compose](https://github.com/reduxkotlin/redux-kotlin-compose)
180+
- [presenter-middleware](https://github.com/reduxkotlin/presenter-middleware)
167181

168-
Trello boards - https://trello.com/reduxkotlinorg
182+
## Communication
169183

170-
Or create an issue on [github](https://github.com/reduxkotlin/redux-kotlin/issues).
184+
Want to give feedback, contribute, or ask questions?
185+
186+
- Chat on [#redux][slack] slack channel
187+
- Use [Trello boards](https://trello.com/reduxkotlinorg)
188+
- Raise GitHub [issues](https://github.com/reduxkotlin/redux-kotlin/issues)
189+
- Ask questions on
190+
GitHub [discussions](https://github.com/reduxkotlin/redux-kotlin/discussions/categories/q-a)
171191

172192
[badge-android]: http://img.shields.io/badge/platform-android-brightgreen.svg?style=flat
173193

@@ -184,3 +204,5 @@ Or create an issue on [github](https://github.com/reduxkotlin/redux-kotlin/issue
184204
[badge-windows]: http://img.shields.io/badge/platform-windows-informational.svg?style=flat
185205

186206
[badge-mac]: http://img.shields.io/badge/platform-macos-lightgrey.svg?style=flat
207+
208+
[slack]: https://kotlinlang.slack.com/archives/C8A8G5F9Q

redux-kotlin-threadsafe/src/commonMain/kotlin/org/reduxkotlin/threadsafe/CreateThreadSafeStore.kt

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package org.reduxkotlin.threadsafe
22

3-
import org.reduxkotlin.*
3+
import org.reduxkotlin.Reducer
4+
import org.reduxkotlin.Store
5+
import org.reduxkotlin.StoreEnhancer
6+
import org.reduxkotlin.TypedReducer
7+
import org.reduxkotlin.TypedStore
8+
import org.reduxkotlin.asTyped
9+
import org.reduxkotlin.createStore
10+
import org.reduxkotlin.typedReducer
411

512
/**
613
* Creates a SYNCHRONIZED, THREADSAFE Redux store that holds the state tree.
@@ -29,7 +36,7 @@ public fun <State> createThreadSafeStore(
2936
reducer: Reducer<State>,
3037
preloadedState: State,
3138
enhancer: StoreEnhancer<State>? = null
32-
): Store<State> = SynchronizedStore(createStore(reducer, preloadedState, enhancer))
39+
): Store<State> = ThreadSafeStore(createStore(reducer, preloadedState, enhancer))
3340

3441
/**
3542
* Creates a thread-safe [TypedStore]. For further details see the matching [createThreadSafeStore].
@@ -38,4 +45,11 @@ public inline fun <State, reified Action : Any> createTypedThreadSafeStore(
3845
crossinline reducer: TypedReducer<State, Action>,
3946
preloadedState: State,
4047
noinline enhancer: StoreEnhancer<State>? = null
41-
): TypedStore<State, Action> = SynchronizedStore(createTypedStore(reducer, preloadedState, enhancer))
48+
): TypedStore<State, Action> =
49+
createThreadSafeStore(typedReducer(reducer), preloadedState, enhancer).asTyped()
50+
51+
/**
52+
* Converts a given [Store] to a [ThreadSafeStore].
53+
*/
54+
public inline fun <State> Store<State>.asThreadSafe(): ThreadSafeStore<State> =
55+
ThreadSafeStore(store)

redux-kotlin-threadsafe/src/commonMain/kotlin/org/reduxkotlin/threadsafe/Enhancers.kt

+12-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,22 @@ import org.reduxkotlin.StoreEnhancer
1313
1414
* @returns {StoreEnhancer} A store enhancer that synchronizes the store.
1515
*/
16-
public fun <State> createSynchronizedStoreEnhancer(): StoreEnhancer<State> {
16+
public fun <State> createThreadSafeStoreEnhancer(): StoreEnhancer<State> {
1717
return { storeCreator ->
1818
{ reducer, initialState, en: Any? ->
1919
val store = storeCreator(reducer, initialState, en)
20-
val synchronizedStore = SynchronizedStore(store)
20+
val synchronizedStore = ThreadSafeStore(store)
2121
synchronizedStore
2222
}
2323
}
2424
}
25+
26+
@Deprecated(
27+
"Renamed to createThreadSafeStoreEnhancer",
28+
replaceWith = ReplaceWith(
29+
expression = "createThreadSafeStoreEnhancer",
30+
"org.reduxkotlin.threadsafe.createThreadSafeStoreEnhancer"
31+
)
32+
)
33+
public fun <State> createSynchronizedStoreEnhancer(): StoreEnhancer<State> =
34+
createThreadSafeStoreEnhancer()

redux-kotlin-threadsafe/src/commonMain/kotlin/org/reduxkotlin/threadsafe/SynchronizedStore.kt redux-kotlin-threadsafe/src/commonMain/kotlin/org/reduxkotlin/threadsafe/ThreadSafeStore.kt

+19-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ package org.reduxkotlin.threadsafe
22

33
import kotlinx.atomicfu.locks.SynchronizedObject
44
import kotlinx.atomicfu.locks.synchronized
5-
import org.reduxkotlin.*
5+
import org.reduxkotlin.Dispatcher
6+
import org.reduxkotlin.GetState
7+
import org.reduxkotlin.Reducer
8+
import org.reduxkotlin.Store
9+
import org.reduxkotlin.StoreSubscriber
10+
import org.reduxkotlin.StoreSubscription
611

712
/**
813
* Threadsafe wrapper for ReduxKotlin store that synchronizes access to each function using
@@ -11,22 +16,31 @@ import org.reduxkotlin.*
1116
* This does have a performance impact for JVM/Native.
1217
* TODO more info at [https://ReduxKotlin.org]
1318
*/
14-
public class SynchronizedStore<State, Action>(private val store: TypedStore<State, Action>) : TypedStore<State, Action>,
19+
public class ThreadSafeStore<State>(override val store: Store<State>) :
20+
Store<State>,
1521
SynchronizedObject() {
16-
17-
override var dispatch: TypedDispatcher<Action> = { action ->
22+
override var dispatch: Dispatcher = { action ->
1823
synchronized(this) { store.dispatch(action) }
1924
}
2025

2126
override val getState: GetState<State> = {
2227
synchronized(this) { store.getState() }
2328
}
2429

25-
override val replaceReducer: (TypedReducer<State, Action>) -> Unit = { reducer ->
30+
override val replaceReducer: (Reducer<State>) -> Unit = { reducer ->
2631
synchronized(this) { store.replaceReducer(reducer) }
2732
}
2833

2934
override val subscribe: (StoreSubscriber) -> StoreSubscription = { storeSubscriber ->
3035
synchronized(this) { store.subscribe(storeSubscriber) }
3136
}
3237
}
38+
39+
@Deprecated(
40+
"Renamed to ThreadSafeStore",
41+
replaceWith = ReplaceWith(
42+
expression = "ThreadSafeStore",
43+
"org.reduxkotlin.threadsafe.ThreadSafeStore"
44+
)
45+
)
46+
public typealias SynchronizedStore<State> = ThreadSafeStore<State>

redux-kotlin-threadsafe/src/jvmCommonTest/kotlin/org/reduxkotlin/threadsafe/CreateThreadSafeStoreTest.kt

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
package org.reduxkotlin.threadsafe
22

3-
import kotlinx.coroutines.*
3+
import kotlinx.coroutines.Dispatchers
4+
import kotlinx.coroutines.coroutineScope
5+
import kotlinx.coroutines.launch
6+
import kotlinx.coroutines.runBlocking
7+
import kotlinx.coroutines.withContext
48
import org.junit.Test
59
import org.reduxkotlin.applyMiddleware
610
import org.reduxkotlin.compose
711
import org.reduxkotlin.createStore
812
import test.TestApp
9-
import java.util.*
13+
import java.util.Timer
1014
import kotlin.concurrent.timerTask
1115
import kotlin.system.measureTimeMillis
1216
import kotlin.test.assertEquals
1317

1418
class CreateThreadSafeStoreTest {
15-
private suspend fun massiveRun(numCoroutines: Int, numRepeats: Int, action: suspend () -> Unit) {
19+
private suspend fun massiveRun(
20+
numCoroutines: Int,
21+
numRepeats: Int,
22+
action: suspend () -> Unit
23+
) {
1624
val time = measureTimeMillis {
1725
coroutineScope {
1826
repeat(numCoroutines) {
@@ -47,7 +55,7 @@ class CreateThreadSafeStoreTest {
4755
compose(
4856
applyMiddleware(TestApp.createTestThunkMiddleware()),
4957
// needs to be placed after enhancers that requires synchronized store methods
50-
createSynchronizedStoreEnhancer()
58+
createThreadSafeStoreEnhancer()
5159
)
5260
)
5361
runBlocking {

0 commit comments

Comments
 (0)