-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
350 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
core/src/commonMain/kotlin/ksm/configuration/interceptor/CombinedConfigurationInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ksm.configuration.interceptor | ||
|
||
import ksm.annotation.MutateContext | ||
import ksm.context.StateContext | ||
|
||
internal class CombinedConfigurationInterceptor( | ||
private val first: ConfigurationInterceptor?, | ||
private val second: ConfigurationInterceptor | ||
) : ConfigurationInterceptor { | ||
@MutateContext | ||
override fun onConfigure(context: StateContext): StateContext { | ||
var applied = context | ||
applied = first?.onConfigure(applied) ?: applied | ||
applied = second.onConfigure(applied) | ||
return applied | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
core/src/commonMain/kotlin/ksm/configuration/interceptor/ConfigurationInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package ksm.configuration.interceptor | ||
|
||
import ksm.annotation.MutateContext | ||
import ksm.context.StateContext | ||
|
||
public fun interface ConfigurationInterceptor { | ||
@MutateContext | ||
public fun onConfigure(context: StateContext): StateContext | ||
} | ||
|
||
public operator fun ConfigurationInterceptor?.plus(other: ConfigurationInterceptor): ConfigurationInterceptor { | ||
return CombinedConfigurationInterceptor( | ||
first = this, | ||
second = other | ||
) | ||
} |
4 changes: 2 additions & 2 deletions
4
...configuration/interceptor/StateContext.kt → ...configuration/interceptor/StateContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
core/src/commonMain/kotlin/ksm/configuration/plugin/ConfigurationStateController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ksm.configuration.plugin | ||
|
||
import ksm.configuration.interceptor.ConfigurationInterceptor | ||
import ksm.context.StateContext | ||
|
||
internal class ConfigurationStateController : StateContext.Element { | ||
override val key = ConfigurationStateController | ||
|
||
var interceptor: ConfigurationInterceptor? = null | ||
|
||
companion object : StateContext.Key<ConfigurationStateController> | ||
} |
12 changes: 8 additions & 4 deletions
12
core/src/commonMain/kotlin/ksm/context/CreateChildStateContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
core/src/commonMain/kotlin/ksm/context/configuration/interceptor/ConfigurationInterceptor.kt
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
core/src/commonMain/kotlin/ksm/context/configuration/plugin/ConfigurationStateController.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
core/src/commonMain/kotlin/ksm/lifecycle/LifecycleInterceptor.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package ksm.lifecycle | ||
|
||
import ksm.context.StateContext | ||
import ksm.lifecycle.interceptor.LifecycleInterceptor | ||
import ksm.lifecycle.plugin.LifecyclePlugin | ||
import ksm.plugin.plugin | ||
|
||
public fun StateContext.addLifecycleInterceptor(interceptor: LifecycleInterceptor) { | ||
plugin(LifecyclePlugin).addLifecycleInterceptor( | ||
context = this, | ||
observer = interceptor | ||
interceptor = interceptor | ||
) | ||
} |
35 changes: 35 additions & 0 deletions
35
core/src/commonMain/kotlin/ksm/lifecycle/interceptor/CombinedLifecycleInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ksm.lifecycle.interceptor | ||
|
||
import ksm.context.StateContext | ||
|
||
internal class CombinedLifecycleInterceptor( | ||
private val first: LifecycleInterceptor?, | ||
private val second: LifecycleInterceptor | ||
) : LifecycleInterceptor { | ||
override fun onCreate(context: StateContext) { | ||
first?.onCreate(context) | ||
second.onCreate(context) | ||
} | ||
|
||
override fun onPause(context: StateContext) { | ||
first?.onPause(context) | ||
second.onPause(context) | ||
} | ||
|
||
override fun onResume(context: StateContext) { | ||
first?.onResume(context) | ||
second.onResume(context) | ||
} | ||
|
||
override fun onFinish(context: StateContext) { | ||
first?.onFinish(context) | ||
second.onResume(context) | ||
} | ||
|
||
override fun onChildCreate(context: StateContext): StateContext { | ||
var applied = context | ||
applied = first?.onChildCreate(applied) ?: applied | ||
applied = second.onChildCreate(applied) | ||
return applied | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
core/src/commonMain/kotlin/ksm/lifecycle/interceptor/LifecycleInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ksm.lifecycle.interceptor | ||
|
||
import ksm.context.StateContext | ||
|
||
public interface LifecycleInterceptor { | ||
public fun onCreate(context: StateContext) {} | ||
public fun onResume(context: StateContext) {} | ||
public fun onPause(context: StateContext) {} | ||
public fun onFinish(context: StateContext) {} | ||
public fun onChildCreate(context: StateContext): StateContext = context | ||
} | ||
|
||
public operator fun LifecycleInterceptor?.plus(other: LifecycleInterceptor): LifecycleInterceptor { | ||
return CombinedLifecycleInterceptor( | ||
first = this, | ||
second = other | ||
) | ||
} |
30 changes: 3 additions & 27 deletions
30
core/src/commonMain/kotlin/ksm/lifecycle/plugin/LifecycleEntry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,13 @@ | ||
package ksm.lifecycle.plugin | ||
|
||
import ksm.context.StateContext | ||
import ksm.lifecycle.LifecycleInterceptor | ||
import ksm.lifecycle.interceptor.LifecycleInterceptor | ||
import ksm.lifecycle.interceptor.plus | ||
|
||
internal class LifecycleEntry : StateContext.Element { | ||
override val key = LifecycleEntry | ||
|
||
private val observers = mutableListOf<LifecycleInterceptor>() | ||
|
||
fun addInterceptor(observer: LifecycleInterceptor) { | ||
observers += observer | ||
} | ||
|
||
fun onCreate(context: StateContext) { | ||
for (observer in observers) { | ||
observer.onCreate(context) | ||
} | ||
} | ||
fun onResume(context: StateContext) { | ||
for (observer in observers) { | ||
observer.onResume(context) | ||
} | ||
} | ||
fun onPause(context: StateContext) { | ||
for (observer in observers) { | ||
observer.onPause(context) | ||
} | ||
} | ||
fun onFinish(context: StateContext) { | ||
for (observer in observers) { | ||
observer.onFinish(context) | ||
} | ||
} | ||
var interceptor: LifecycleInterceptor? = null | ||
|
||
companion object : StateContext.Key<LifecycleEntry> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.