Skip to content

Commit 1cc3e98

Browse files
adityasharatfacebook-github-bot
authored andcommitted
Renames some props in debug events api
Summary: Renames some props in debug events api Reviewed By: fabiocarballo Differential Revision: D44744901 fbshipit-source-id: 948997cd8675fe7dddc44c76a02d58b773c5a5ac
1 parent 9f96a28 commit 1cc3e98

File tree

1 file changed

+22
-23
lines changed
  • litho-rendercore/src/main/java/com/facebook/rendercore/debug

1 file changed

+22
-23
lines changed

litho-rendercore/src/main/java/com/facebook/rendercore/debug/DebugEvents.kt

+22-23
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ abstract class DebugEventSubscriber(vararg val events: String) {
132132
/** Object to dispatch debug events */
133133
object DebugEventDispatcher {
134134

135-
val _enabled: AtomicBoolean = AtomicBoolean(false)
135+
val enabledRef: AtomicBoolean = AtomicBoolean(false)
136+
137+
@JvmStatic
136138
var enabled: Boolean
137-
get() = _enabled.get()
139+
get() = enabledRef.get()
138140
set(value) {
139-
_enabled.set(value)
141+
enabledRef.set(value)
140142
}
141143

142144
private val minLogLevelRef = AtomicReference(LogLevel.DEBUG)
@@ -148,22 +150,22 @@ object DebugEventDispatcher {
148150
minLogLevelRef.set(value)
149151
}
150152

151-
private val _mutableSubscribers: MutableSet<DebugEventSubscriber> = mutableSetOf()
153+
private val mutableSubscribers: MutableSet<DebugEventSubscriber> = mutableSetOf()
152154

153155
val subscribers: Set<DebugEventSubscriber>
154-
@Synchronized get() = _mutableSubscribers
156+
@Synchronized get() = mutableSubscribers
155157

156158
@JvmStatic
157159
inline fun dispatch(
158160
type: String,
159161
renderStateId: String,
160162
timestamp: Long = System.currentTimeMillis(), // for calender time
161163
logLevel: LogLevel = LogLevel.DEBUG,
162-
attributesFiller: AttributesFiller = AttributesFiller {},
164+
attributesAccumulator: AttributesAccumulator = AttributesAccumulator {},
163165
) {
164166
if (enabled && logLevel >= this.minLogLevel) {
165167
val attributes = LinkedHashMap<String, Any?>()
166-
attributesFiller.fillAttributes(attributes)
168+
attributesAccumulator.accumulate(attributes)
167169

168170
val event =
169171
DebugMarkerEvent(
@@ -185,13 +187,13 @@ object DebugEventDispatcher {
185187
inline fun dispatch(
186188
type: String,
187189
renderStateId: String,
188-
attributesFiller: AttributesFiller = AttributesFiller {}
190+
attributesAccumulator: AttributesAccumulator = AttributesAccumulator {}
189191
) {
190192
dispatch(
191193
type = type,
192194
renderStateId = renderStateId,
193195
timestamp = System.currentTimeMillis(), // for calender time
194-
attributesFiller = attributesFiller,
196+
attributesAccumulator = attributesAccumulator,
195197
)
196198
}
197199

@@ -200,22 +202,22 @@ object DebugEventDispatcher {
200202
type: String,
201203
renderStateId: String,
202204
logLevel: LogLevel = LogLevel.DEBUG,
203-
attributesFiller: AttributesFiller = AttributesFiller {},
205+
attributesAccumulator: AttributesAccumulator = AttributesAccumulator {},
204206
) {
205207
dispatch(
206208
type = type,
207209
renderStateId = renderStateId,
208210
timestamp = System.currentTimeMillis(), // for calender time
209211
logLevel = logLevel,
210-
attributesFiller = attributesFiller,
212+
attributesAccumulator = attributesAccumulator,
211213
)
212214
}
213215

214216
@JvmStatic
215217
inline fun <T> trace(
216218
type: String,
217219
renderStateId: String,
218-
attributesFiller: AttributesFiller = AttributesFiller {},
220+
attributesAccumulator: AttributesAccumulator = AttributesAccumulator {},
219221
block: (TraceScope?) -> T,
220222
): T {
221223

@@ -236,7 +238,7 @@ object DebugEventDispatcher {
236238
}
237239

238240
val attributes = LinkedHashMap<String, Any?>()
239-
attributesFiller.fillAttributes(attributes)
241+
attributesAccumulator.accumulate(attributes)
240242

241243
val startTime = System.nanoTime()
242244
val res = block(TraceScope(attributes = attributes))
@@ -257,17 +259,17 @@ object DebugEventDispatcher {
257259

258260
@Synchronized
259261
fun subscribe(subscriber: DebugEventSubscriber) {
260-
_mutableSubscribers.add(subscriber)
262+
mutableSubscribers.add(subscriber)
261263
}
262264

263265
@Synchronized
264266
internal fun unsubscribe(subscriber: DebugEventSubscriber) {
265-
_mutableSubscribers.remove(subscriber)
267+
mutableSubscribers.remove(subscriber)
266268
}
267269

268270
@Synchronized
269271
fun unsubscribeAll() {
270-
_mutableSubscribers.clear()
272+
mutableSubscribers.clear()
271273
}
272274

273275
class TraceScope(private val attributes: LinkedHashMap<String, Any?>) {
@@ -313,15 +315,12 @@ object DebugEventBus {
313315
}
314316

315317
/**
316-
* This consumer interface is used so that clients can fill the [DebugEvent] attributes map in a
317-
* cleaner way in both Java and Kotlin.
318-
*
319-
* By doing this (and not use a lambda directly), we can guarantee that Java clients are not forced
320-
* to return `Unit.INSTANCE` or `null`.
318+
* This accumulator interface is invoked to get attributes of a [DebugEvent]. Using this interface
319+
* improve ergonomics in Java; i.e. not return `Unit.INSTANCE` or `null`.
321320
*/
322-
fun interface AttributesFiller {
321+
fun interface AttributesAccumulator {
323322

324-
fun fillAttributes(map: MutableMap<String, Any?>)
323+
fun accumulate(map: MutableMap<String, Any?>)
325324
}
326325

327326
@JvmInline

0 commit comments

Comments
 (0)