@@ -19,17 +19,20 @@ state. Or 2 actions dispatched concurrently could cause an invalid state.
19
19
20
20
** So you there are 3 options:**
21
21
22
- 1) Synchronize access to the store - [createThreadSafeStore()](../api/createThreadSafeStore.md)
23
- 2) Only access the store from the same thread - [createSameThreadEnforcedStore()](../api/createSameThreadEnforcedStore.md)
24
- 3) Live in the wild west and access store anytime, any thread and live with consequences - NOT RECOMMENDED - [createStore()](../api/createStore.md)
22
+ 1 ) Synchronize access to the store - [ createThreadSafeStore()] ( ../api/createThreadSafeStore.md )
23
+ 2 ) Only access the store from the same thread - [ createSameThreadEnforcedStore()] ( ../api/createSameThreadEnforcedStore.md )
24
+ 3 ) Live in the wild west and access store anytime, any thread
25
+ and live with consequences - NOT_RECOMMENDED - [ createStore()] ( ../api/createStore.md )
25
26
26
27
ReduxKotlin allows all these, but most cases will fall into #1 .
27
28
29
+ ## ThreadSafe
30
+
28
31
Starting with ReduxKotlin 0.5.0 there is a threadsafe store which uses synchronization (AtomicFu library)
29
32
to allow safe access to all the functions on the store. This is the recommended usage for 90% of use cases.
30
33
31
34
``` kotlin
32
- val store = createThreadSafeStore(.. . )
35
+ val store = createThreadSafeStore(reducer, state )
33
36
```
34
37
35
38
Who is the other 10%? If you are only targeting Javascript thread safety is not an issue, so
@@ -55,9 +58,13 @@ have do not have the enforcement in place yet.
55
58
56
59
To use ` same thread enforcement ` :
57
60
``` kotlin
58
- val store = createSameThreadEnforcedStore(.. . )
61
+ val store = createSameThreadEnforcedStore(reducer, state )
59
62
```
60
63
64
+ ## Wild west - no enforcement
65
+
66
+ ` createStore() ` may be used if the project is only a single threaded application (i.e. JS only), or you
67
+ just want control access within your codebase(NOT_RECOMMENDED).
61
68
62
69
*** IF*** you are using vanilla ` createStore() ` , then you may use an different artifact,
63
70
and avoid pulling in AtomicFu dependency:
@@ -67,7 +74,7 @@ kotlin {
67
74
sourceSets {
68
75
commonMain {
69
76
dependencies {
70
- implementation "org.reduxkotlin:redux-kotlin:0.5.0 "
77
+ implementation "org.reduxkotlin:redux-kotlin:0.5.1 "
71
78
}
72
79
}
73
80
}
0 commit comments