-
-
Notifications
You must be signed in to change notification settings - Fork 714
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
1 parent
fc34674
commit c9c849e
Showing
8 changed files
with
203 additions
and
4 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
78 changes: 78 additions & 0 deletions
78
projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/core/context/GlobalContext.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,78 @@ | ||
/* | ||
* Copyright 2017-Present the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.koin.core.context | ||
|
||
import org.koin.core.Koin | ||
import org.koin.core.KoinApplication | ||
import org.koin.core.error.ApplicationAlreadyStartedException | ||
import org.koin.core.module.Module | ||
import org.koin.dsl.KoinAppDeclaration | ||
|
||
/** | ||
* Global context - current Koin Application available globally | ||
* | ||
* Support to help inject automatically instances once KoinApp has been started | ||
* | ||
* @author Arnaud Giuliani | ||
*/ | ||
object GlobalContext : KoinContext { | ||
|
||
private var _koin: Koin? = null | ||
|
||
override fun get(): Koin = _koin ?: error("KoinApplication has not been started") | ||
|
||
override fun getOrNull(): Koin? = _koin | ||
|
||
private fun register(koinApplication: KoinApplication) { | ||
if (_koin != null) { | ||
throw ApplicationAlreadyStartedException("A Koin Application has already been started") | ||
} | ||
_koin = koinApplication.koin | ||
} | ||
|
||
override fun stopKoin() { | ||
_koin?.close() | ||
_koin = null | ||
} | ||
|
||
override fun startKoin(koinApplication: KoinApplication): KoinApplication { | ||
register(koinApplication) | ||
return koinApplication | ||
} | ||
|
||
override fun startKoin(appDeclaration: KoinAppDeclaration): KoinApplication { | ||
val koinApplication = KoinApplication.init() | ||
register(koinApplication) | ||
appDeclaration(koinApplication) | ||
return koinApplication | ||
} | ||
|
||
override fun loadKoinModules(module: Module,createEagerInstances : Boolean) { | ||
get().loadModules(listOf(module), createEagerInstances = createEagerInstances) | ||
} | ||
|
||
override fun loadKoinModules(modules: List<Module>, createEagerInstances : Boolean) { | ||
get().loadModules(modules, createEagerInstances = createEagerInstances) | ||
} | ||
|
||
override fun unloadKoinModules(module: Module) { | ||
get().unloadModules(listOf(module)) | ||
} | ||
|
||
override fun unloadKoinModules(modules: List<Module>) { | ||
get().unloadModules(modules) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/core/logger/PrintLogger.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,27 @@ | ||
/* | ||
* Copyright 2017-Present the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.koin.core.logger | ||
|
||
/** | ||
* Logger that print on system.out | ||
* @author - Arnaud GIULIANI | ||
*/ | ||
class PrintLogger(level: Level = Level.INFO) : Logger(level) { | ||
|
||
override fun display(level: Level, msg: MESSAGE) { | ||
println("[$level] $KOIN_TAG $msg") | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/PlatformTimeTools.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,9 @@ | ||
package org.koin.mp | ||
|
||
import kotlin.time.TimeSource | ||
|
||
actual object KoinPlatformTimeTools { | ||
actual fun getTimeInNanoSeconds(): Long { | ||
return TimeSource.Monotonic.markNow().elapsedNow().inWholeNanoseconds | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
projects/core/koin-core/src/wasmJsMain/kotlin/org/koin/mp/PlatformTools.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,59 @@ | ||
/* | ||
* Copyright 2017-present the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.koin.mp | ||
|
||
import co.touchlab.stately.concurrency.ThreadLocalRef | ||
import org.koin.core.context.GlobalContext | ||
import org.koin.core.context.KoinContext | ||
import org.koin.core.logger.* | ||
import kotlin.random.Random | ||
import kotlin.reflect.KClass | ||
|
||
// actual object PlatformTools { | ||
// actual fun getClassName(kClass: KClass<*>): String { | ||
// return kClass.simpleName ?: "KClass@${hashCode()}" | ||
// } | ||
// | ||
// actual fun printStackTrace(throwable: Throwable) { | ||
// throwable.printStackTrace() | ||
// } | ||
// | ||
// actual fun stackTrace(): List<String> = Exception().toString().split("\n") | ||
// | ||
// actual fun printLog(level: Level, msg: MESSAGE) { | ||
// println("[$level] $KOIN_TAG $msg") | ||
// } | ||
// } | ||
// internal actual fun Any.ensureNeverFrozen() {} | ||
// internal actual fun <R> mpsynchronized(lock: Any, block: () -> R): R = block() | ||
|
||
actual object KoinPlatformTools { | ||
actual fun getStackTrace(e: Exception): String = e.toString() + Exception().toString().split("\n") | ||
actual fun getClassName(kClass: KClass<*>): String = kClass.simpleName ?: "KClass@${kClass.hashCode()}" | ||
|
||
// TODO Better Id generation? | ||
actual fun generateId(): String = Random.nextDouble().hashCode().toString() | ||
actual fun defaultLazyMode(): LazyThreadSafetyMode = LazyThreadSafetyMode.NONE | ||
actual fun defaultLogger(level: Level): Logger = PrintLogger(level) | ||
actual fun defaultContext(): KoinContext = GlobalContext | ||
actual fun <R> synchronized(lock: Lockable, block: () -> R) = block() | ||
actual fun <K, V> safeHashMap(): MutableMap<K, V> = HashMap() | ||
} | ||
|
||
actual typealias Lockable = Any | ||
|
||
actual typealias ThreadLocal<T> = ThreadLocalRef<T> |
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