Skip to content

Commit b0b429a

Browse files
robingenzclaude
andauthored
chore: trim comments and add the comments rule (#22)
Rewrite the dense comments into short plain sentences, keep doc comments only on the public surface, drop the section banners and the doc comments that repeat a name, and add a Comments section to CLAUDE.md. No code changes. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 8ea98f6 commit b0b429a

35 files changed

Lines changed: 171 additions & 253 deletions

‎CLAUDE.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ The shared types come from `@hotcodepush/protocol` the same way, pinned to a com
6666
- Prose names the feature over-the-air (OTA) updates: "over-the-air (OTA) update" on the first mention of a surface, "OTA update" after it, and the appositive "HotCodePush, the over-the-air (OTA) update platform for React Native, Expo, Capacitor and Cordova". "Live update" is the Capacitor community's word: it stays in the `capacitor-live-updates` package name and in a list of alternative names for search, never as HotCodePush's own term.
6767
- Wherever the supported frameworks are listed, the order is React Native, Expo, Capacitor and Cordova, the larger communities first; this repository's own sentences lead with React Native.
6868

69+
## Comments
70+
71+
- Comment only what the code cannot say: the why behind a choice, an outside quirk or limit, what a regex matches, a TODO with its issue link. Never what the code does.
72+
- Before adding a comment, try a clearer name or a small extracted function first.
73+
- One or two short plain sentences. Capital letter, full stop, own line above the code. No run-on sentences, no chains of possessives.
74+
- Doc comments (JSDoc, KDoc, `///`, docstrings) only on a package's public API: one line that says what it does, then only what a caller must know.
75+
- Never: section banners, commented-out code, change history, the same comment in two places.
76+
6977
## Agent workspace
7078

7179
- `.claude/skills/` holds the developer skills copied from `hotcodepush-team/.github`, pinned in `skills-lock.json`.

‎android/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ buildscript {
1414

1515
apply plugin: 'com.android.library'
1616
apply plugin: 'org.jetbrains.kotlin.android'
17-
// Codegen: the Turbo Module's spec generated from src/NativeHotCodePush.ts.
17+
// Runs Codegen, which generates the Turbo Module spec from src/NativeHotCodePush.ts.
1818
apply plugin: 'com.facebook.react'
1919

2020
android {

‎android/hotcodepush.gradle‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// The build step of the Android build. The app's build.gradle applies this file with the one line `hotcodepush init`
2-
// adds; for every variant, the task below runs the CLI after React Native's bundling: a store build, a build type other
3-
// than debug, runs `binary create`, which writes hotcodepush.json into the variant's assets and creates the binary; any
4-
// other build runs `resource-file write`, which writes the file alone. A variant React Native bundles nothing for gets
5-
// the file without an embedded bundle, and no binary.
1+
// Applied through the line `hotcodepush init` adds to the app's build.gradle.
2+
// After React Native bundles a variant, a store build (any build type but debug) runs `binary create` and any other build runs `resource-file write`.
63

74
import javax.inject.Inject
85
import org.apache.tools.ant.taskdefs.condition.Os
96
import org.gradle.api.tasks.Optional
107

11-
// core-android's maven branch publishes the commit the SDK pins, until the library is on Maven Central.
8+
// The app resolves the core from core-android's maven branch until the library is on Maven Central.
129
repositories {
1310
maven { url 'https://raw.githubusercontent.com/hotcodepush-team/core-android/maven/' }
1411
}
@@ -48,7 +45,7 @@ abstract class HotCodePushBinaryCreateTask extends DefaultTask {
4845

4946
@TaskAction
5047
void createBinary() {
51-
// The embedded bundle as one tree, laid out as an uploaded bundle is: the JavaScript beside its drawable directories.
48+
// Stages the embedded bundle as an uploaded bundle is laid out: the JavaScript beside its drawable directories.
5249
// Without a bundle the tree stays empty, which binary create reads as a build without an embedded bundle.
5350
fileSystemOperations.sync {
5451
if (jsBundleDir.present) it.from(jsBundleDir)
@@ -74,7 +71,7 @@ abstract class HotCodePushBinaryCreateTask extends DefaultTask {
7471
androidComponents.onVariants(androidComponents.selector().all()) { variant ->
7572
def variantName = variant.name.capitalize()
7673
def bundleTaskName = "createBundle${variantName}JsAndAssets"
77-
// A debuggable variant is served by Metro: React Native bundles nothing for it.
74+
// Metro serves a debuggable variant, so React Native bundles nothing for it.
7875
def bundleTask = tasks.names.contains(bundleTaskName) ? tasks.named(bundleTaskName) : null
7976
def reactExtension = project.extensions.findByName('react')
8077
def binaryCreateTask = tasks.register("createHotCodePushBinary${variantName}", HotCodePushBinaryCreateTask) {
@@ -89,7 +86,8 @@ androidComponents.onVariants(androidComponents.selector().all()) { variant ->
8986
it.projectRoot.set(reactExtension == null ? rootProject.layout.projectDirectory.dir('..') : reactExtension.root)
9087
it.stagingDirectory.set(layout.buildDirectory.dir("intermediates/hotcodepush/${variant.name}"))
9188
it.storeBuild.set(variant.buildType != 'debug')
92-
// The resource file carries the build's time as the floor and a store build creates its binary on every run: the step never counts as up to date.
89+
// The resource file carries the build time as its floor, and a store build creates its binary on every run.
90+
// So the task never counts as up to date.
9391
it.outputs.upToDateWhen { false }
9492
}
9593
variant.sources.assets.addGeneratedSourceDirectory(binaryCreateTask) { it.outputDirectory }

‎android/settings.gradle‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// The library built on its own, for its unit tests. React Native comes from the package's devDependency as an app's build
2-
// finds it: the Gradle plugin from its included build, react-android at the version React Native's plugin forces. An app's
3-
// root build script puts the plugin on the classpath; here the root is the library, whose build script stays as it ships.
1+
// Builds the library on its own for its unit tests, with React Native from the devDependency as an app build finds it.
2+
// In an app, the root build script puts the React Native plugin on the classpath. Here the library is the root, so this file adds it.
43
includeBuild('../node_modules/@react-native/gradle-plugin')
54
rootProject.name = 'react-native-code-push'
65

‎android/src/main/java/com/hotcodepush/reactnative/FirstRenderListener.kt‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ import com.facebook.react.bridge.UIManagerListener
77
import com.facebook.react.common.annotations.UnstableReactNativeAPI
88
import com.facebook.react.uimanager.ReactRoot
99

10-
/**
11-
* The first render of one JavaScript instance: the first frame that finds a view inside a React root. The root itself is
12-
* mounted before any render, so an instance that renders nothing never signals it, and an instance that renders while a
13-
* reload the SDK asked for is pending is the one the reload replaces, whose render signals nothing.
14-
*
15-
* The root is checked at every frame React Native dispatches its mounting work, never at a mount alone: the first mount
16-
* can come before React Native reports the instance to the runtime, and a mount made before the root view is attached
17-
* runs at the attach, which no mount listener hears. A reload clears the root before it creates the next instance.
18-
*/
10+
// The first render is the first frame that finds a view inside a React root, since the root itself mounts before any render.
11+
// While a reload the SDK asked for is pending, the render belongs to the replaced instance and signals nothing.
12+
//
13+
// The check runs at every dispatched frame, not at a mount. The first mount can come before React Native reports the instance,
14+
// and a mount before the root view is attached runs at the attach, which no mount listener hears.
1915
@OptIn(UnstableReactNativeAPI::class)
2016
internal class FirstRenderListener(
2117
private val loader: ReactNativeBundleLoader,
@@ -38,7 +34,7 @@ internal class FirstRenderListener(
3834

3935
override fun willMountItems(uiManager: UIManager) = Unit
4036

41-
// The getter called as a method: ReactRoot is Java until React Native 0.82 and Kotlin from 0.83, which has no property for it.
37+
// ReactRoot is Java up to React Native 0.82 and Kotlin from 0.83, which has no property for this getter.
4238
private fun containsRenderedReactRoot(view: View): Boolean = when (view) {
4339
is ReactRoot -> view.getRootViewGroup().childCount > 0
4440
is ViewGroup -> (0 until view.childCount).any { containsRenderedReactRoot(view.getChildAt(it)) }

‎android/src/main/java/com/hotcodepush/reactnative/HotCodePushModule.kt‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ import com.hotcodepush.core.SyncOptions
1616
import com.hotcodepush.core.SyncTrigger
1717
import org.json.JSONObject
1818

19-
/** The Turbo Module `HotCodePush`: the JavaScript surface over [HotCodePushRuntime]. */
2019
class HotCodePushModule(reactContext: ReactApplicationContext) : NativeHotCodePushSpec(reactContext), HotCodePushEventSink {
2120
private val runtime = HotCodePushRuntime.get(reactContext)
2221

2322
init {
2423
runtime.attach(this)
2524
}
2625

27-
/** A reload replaces this instance with the module of the new JavaScript. */
2826
override fun invalidate() {
2927
runtime.detach(this)
3028
super.invalidate()
@@ -101,7 +99,6 @@ class HotCodePushModule(reactContext: ReactApplicationContext) : NativeHotCodePu
10199
}
102100
}
103101

104-
/** Opens the shared core's debug screen over the app's activity. */
105102
override fun showDebugScreen(promise: Promise) = runtime.invoke(promise) { core ->
106103
DebugScreen.show(reactApplicationContext.currentActivity ?: reactApplicationContext, core)
107104
null
@@ -110,7 +107,7 @@ class HotCodePushModule(reactContext: ReactApplicationContext) : NativeHotCodePu
110107
override fun sync(options: ReadableMap, promise: Promise) = runtime.invoke(promise) { it.sync(SyncTrigger.MANUAL, syncOptions(options)).toJson() }
111108

112109
override fun emitEvent(eventName: String, payload: JSONObject) {
113-
// React Native hands the module its emitter callback after init; an event before that has no JavaScript listening yet.
110+
// React Native sets the emitter callback after init. Before that, no JavaScript listens.
114111
if (mEventEmitterCallback == null) return
115112
val value = payload.toWritableMap()
116113
when (eventName) {
@@ -121,13 +118,11 @@ class HotCodePushModule(reactContext: ReactApplicationContext) : NativeHotCodePu
121118
}
122119
}
123120

124-
/** The apply strategies for this call. */
125121
private fun downloadUpdateOptions(options: ReadableMap) = DownloadUpdateOptions(
126122
applyStrategy = option("applyStrategy", options, ApplyStrategy::fromWire),
127123
mandatoryApplyStrategy = option("mandatoryApplyStrategy", options, MandatoryApplyStrategy::fromWire),
128124
)
129125

130-
/** Each stage's strategy for this call. */
131126
private fun syncOptions(options: ReadableMap) = SyncOptions(
132127
applyStrategy = option("applyStrategy", options, ApplyStrategy::fromWire),
133128
downloadStrategy = option("downloadStrategy", options, DownloadStrategy::fromWire),
@@ -148,7 +143,6 @@ class HotCodePushModule(reactContext: ReactApplicationContext) : NativeHotCodePu
148143
}
149144
}
150145

151-
/** A result or an event as the bridge carries it. */
152146
internal fun JSONObject.toWritableMap() = Arguments.makeNativeMap(toMap())
153147

154148
private fun JSONObject.toMap(): Map<String, Any?> = keys().asSequence().associateWith { toBridgeValue(get(it)) }

‎android/src/main/java/com/hotcodepush/reactnative/HotCodePushPackage.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.facebook.react.bridge.ReactApplicationContext
66
import com.facebook.react.module.model.ReactModuleInfo
77
import com.facebook.react.module.model.ReactModuleInfoProvider
88

9-
/** The package autolinking registers: the Turbo Module `HotCodePush`. */
9+
/** Registers the `HotCodePush` Turbo Module. Autolinking adds it to the app. */
1010
class HotCodePushPackage : BaseReactPackage() {
1111
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? =
1212
if (name == HotCodePushModule.NAME) HotCodePushModule(reactContext) else null

‎android/src/main/java/com/hotcodepush/reactnative/HotCodePushReactHost.kt‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ import com.facebook.react.runtime.cxxreactpackage.CxxReactPackage
2020
import com.facebook.react.runtime.hermes.HermesInstance
2121

2222
/**
23-
* The React host of an app on HotCodePush: `DefaultReactHost.getDefaultReactHost` with one difference, the bundle.
24-
* React Native's own host fixes its bundle when it is created; this one asks the SDK at every start and reload,
25-
* so applying a release reloads the JavaScript without restarting the process. `MainApplication` imports this
26-
* `getDefaultReactHost` in place of React Native's; the parameters are the same.
23+
* A drop-in replacement for `DefaultReactHost.getDefaultReactHost` that asks the SDK for the bundle at every start and reload.
24+
* Import it in `MainApplication` in place of the React Native one. The parameters are the same.
25+
* Applying a release then reloads the JavaScript without restarting the process.
2726
*/
2827
object HotCodePushReactHost {
2928
private var reactHost: ReactHost? = null
@@ -75,7 +74,6 @@ object HotCodePushReactHost {
7574
}
7675
}
7776

78-
/** React Native's delegate with the bundle resolved anew each time the host creates its JavaScript instance. */
7977
@OptIn(UnstableReactNativeAPI::class)
8078
private class ServedBundleReactHostDelegate(
8179
delegate: ReactHostDelegate,

‎android/src/main/java/com/hotcodepush/reactnative/HotCodePushRuntime.kt‎

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,12 @@ import kotlinx.coroutines.SupervisorJob
3131
import kotlinx.coroutines.launch
3232
import org.json.JSONObject
3333

34-
/** What the runtime hands the Turbo Module: an event to emit to JavaScript. */
3534
interface HotCodePushEventSink {
3635
fun emitEvent(eventName: String, payload: JSONObject)
3736
}
3837

39-
/**
40-
* The SDK inside the process, one per app: it starts the core when React Native asks for its bundle, so the start's
41-
* verdict — the pending switch, the rollback of a release that never became ready — is in before any JavaScript runs,
42-
* and the Turbo Module of every JavaScript instance since talks to that one core.
43-
*/
38+
// The core starts when React Native first asks for its bundle, so a pending switch or rollback is decided before any JavaScript runs.
39+
// The Turbo Module of every later JavaScript instance talks to that one core.
4440
class HotCodePushRuntime internal constructor(private val context: Context) : CoreListener {
4541
private val scheduler = HandlerScheduler()
4642
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
@@ -51,16 +47,10 @@ class HotCodePushRuntime internal constructor(private val context: Context) : Co
5147
@Volatile private var eventSink: HotCodePushEventSink? = null
5248
private var isStarted = false
5349

54-
/** Why there is no core, which every method rejects with: the resource file is missing, or the core's reader refused it. */
5550
@Volatile private var notConfiguredMessage = Configuration.MISSING_MESSAGE
5651
private var retainedUpdateRolledBackEvent: JSONObject? = null
5752

58-
// The host
59-
60-
/**
61-
* What React Native loads, asked at every start and reload: the served bundle's file, else the bundle the binary ships.
62-
* Nothing thrown on the way stops the host: it then runs the embedded bundle.
63-
*/
53+
// React Native asks at every start and every reload. Any failure falls back to the embedded bundle, so the host always starts.
6454
fun resolveBundleLoader(embeddedBundleLoader: JSBundleLoader): JSBundleLoader {
6555
val bundleFile = try {
6656
loader.serveBundle(resolveServedBundleId())
@@ -71,21 +61,16 @@ class HotCodePushRuntime internal constructor(private val context: Context) : Co
7161
return bundleFile?.let { JSBundleLoader.createFileLoader(it.path) } ?: embeddedBundleLoader
7262
}
7363

74-
/**
75-
* The bundle the new JavaScript instance runs: the start's answer, the bundle of a reload the SDK asked for, else the running one.
76-
* A reload the SDK did not ask for — `DevSettings.reload()`, react-native-restart, a development reload — serves the running bundle and the core is not told.
77-
*/
64+
// A reload the SDK did not ask for, such as `DevSettings.reload()`, react-native-restart or a development reload,
65+
// serves the running bundle without telling the core.
7866
private fun resolveServedBundleId(): String? {
7967
val requestedReload = loader.beginBundleRequest()
8068
if (claimStart()) return createCore(isServedBySdk = true)?.handleAppStartBlocking(isHeadless = !ActivityManagerProcessState.isInForeground())
8169
return if (requestedReload != null) requestedReload.bundleId else loader.runningBundleId
8270
}
8371

84-
/**
85-
* A JavaScript instance was created, at the start and at every reload: its first render, which [FirstRenderListener]
86-
* observes, is the readiness signal `render`, and whatever `readySignal` is, the moment the app is up in this run,
87-
* which the core's own restarts wait for.
88-
*/
72+
// Called for each new JavaScript instance. Its first render is the `render` readiness signal and, for any `readySignal`,
73+
// the moment the core's restarts wait for.
8974
@OptIn(UnstableReactNativeAPI::class)
9075
fun observeFirstRender(reactContext: ReactContext) {
9176
val uiManager = UIManagerHelper.getUIManager(reactContext, UIManagerType.FABRIC) ?: return
@@ -97,9 +82,7 @@ class HotCodePushRuntime internal constructor(private val context: Context) : Co
9782
scope.launch { core.handleRendered() }
9883
}
9984

100-
// The Turbo Module
101-
102-
/** The module of the JavaScript instance that runs now; a reload replaces it. */
85+
// A reload replaces the module, so only the latest one receives events.
10386
fun attach(eventSink: HotCodePushEventSink) {
10487
this.eventSink = eventSink
10588
if (claimStart()) createCore(isServedBySdk = false)?.let { core -> scope.launch { core.handleAppStart() } }
@@ -127,12 +110,8 @@ class HotCodePushRuntime internal constructor(private val context: Context) : Co
127110
@Synchronized
128111
fun takeRetainedUpdateRolledBackEvent(): JSONObject? = retainedUpdateRolledBackEvent.also { retainedUpdateRolledBackEvent = null }
129112

130-
// The start
131-
132-
/**
133-
* Whether the caller starts the core, once per process: the host at its first question for its bundle, which waits for the start's
134-
* answer at most `Core.START_TIMEOUT`, or the module of a host that never asked, which runs JavaScript the SDK does not serve.
135-
*/
113+
// The core starts once per process: from the first bundle request, which waits up to `Core.START_TIMEOUT`,
114+
// or from the module of a host that never asked and so runs JavaScript the SDK does not serve.
136115
@Synchronized
137116
private fun claimStart(): Boolean {
138117
if (isStarted) return false
@@ -152,8 +131,8 @@ class HotCodePushRuntime internal constructor(private val context: Context) : Co
152131
return null
153132
}
154133
if (!isServedBySdk) Log.w(TAG, NOT_SERVED_MESSAGE)
134+
// A run whose JavaScript the SDK does not serve counts as a debug build, and `isEnabledInDebugBuilds` is off.
155135
val configuration = if (isServedBySdk) readConfiguration else readConfiguration.copy(isEnabledInDebugBuilds = false)
156-
// A run whose JavaScript the SDK does not serve counts as a debug build, which `isEnabledInDebugBuilds` then switches off.
157136
val device = DeviceFacts.current(context, SDK_VERSION).let { if (isServedBySdk) it else it.copy(isDebugBuild = true) }
158137
val core = Core(
159138
context = context,
@@ -186,8 +165,6 @@ class HotCodePushRuntime internal constructor(private val context: Context) : Co
186165
(context.applicationContext as? ReactApplication)?.reactHost?.reload(RELOAD_REASON)
187166
}
188167

189-
// The listener
190-
191168
override fun updateAvailable(event: UpdateAvailableEvent) {
192169
eventSink?.emitEvent("updateAvailable", event.toJson())
193170
}
@@ -204,7 +181,7 @@ class HotCodePushRuntime internal constructor(private val context: Context) : Co
204181
eventSink?.emitEvent("downloadProgress", event.toJson())
205182
}
206183

207-
/** Kept until the JavaScript of the start that follows the rollback listens: the instance that saw the rollback is gone by then. */
184+
// Kept until the JavaScript of the next start listens, since the instance that saw the rollback is gone by then.
208185
@Synchronized
209186
override fun updateRolledBack(event: UpdateRolledBackEvent) {
210187
retainedUpdateRolledBackEvent = event.toJson()
@@ -223,7 +200,6 @@ class HotCodePushRuntime internal constructor(private val context: Context) : Co
223200
}
224201
}
225202

226-
/** The two moments the runtime follows; the rest of the interface is noise it leaves empty. */
227203
private abstract class ActivityLifecycleObserver : Application.ActivityLifecycleCallbacks {
228204
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) = Unit
229205

0 commit comments

Comments
 (0)