-
Notifications
You must be signed in to change notification settings - Fork 7
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
4 changed files
with
57 additions
and
23 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
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
34 changes: 34 additions & 0 deletions
34
...ar/seskar-gradle-plugin/src/main/kotlin/seskar/gradle/plugin/ReactLazyComponentFactory.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,34 @@ | ||
package seskar.gradle.plugin | ||
|
||
import seskar.gradle.plugin.Modules.ORIGINAL_MODULE_SUFFIX | ||
|
||
class ReactLazyComponentFactory : | ||
LazyItemFactory { | ||
override fun create( | ||
export: String, | ||
): LazyItem { | ||
val fileName = export | ||
.removePrefix("get_") | ||
.substringBefore("__react__component") | ||
|
||
val originalComponentPath = "./$fileName$ORIGINAL_MODULE_SUFFIX" | ||
|
||
val componentName = "$fileName\$\$__react__lazy__component" | ||
|
||
// language=javascript | ||
val body = """ | ||
const $componentName = lazy(() => | ||
import("$originalComponentPath") | ||
.then(module => module.${export}()) | ||
.then(component => ({ default: component })) | ||
) | ||
export const $export = () => $componentName | ||
""".trimIndent() | ||
|
||
return LazyItem( | ||
imports = """import { lazy } from "react"""", | ||
body = body, | ||
) | ||
} | ||
} |