Skip to content

Commit 89a4714

Browse files
author
Sean Levin
committed
automaticResourceNaming
1 parent 5d6edb5 commit 89a4714

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

behavior-graph/src/main/kotlin/behaviorgraph/Extent.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ open class Extent<ExtentContext: Any> @JvmOverloads constructor(val graph: Graph
104104
*/
105105
fun addToGraph() {
106106
if (graph.currentEvent != null) {
107-
nameResources()
107+
if (graph.automaticResourceNaming) {
108+
nameResources()
109+
}
108110
graph.addExtent(this)
109111
} else {
110112
throw BehaviorGraphException("addToGraph must be called within an event. Extent=$this")

behavior-graph/src/main/kotlin/behaviorgraph/Graph.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class Graph @JvmOverloads constructor(private val dateProvider: DateProvider? =
5858
*/
5959
var validateLifetimes: Boolean = true
6060

61+
/**
62+
* System uses reflection to automatically name resources as extents are added to the graph.
63+
* This makes debugging significantly easier; however it does come with some small cost.
64+
* You may disable this here.
65+
*/
66+
var automaticResourceNaming: Boolean = true
67+
6168
/**
6269
* The current action may update one or more resources. Inspecting this list lets us
6370
* identify which action initiated the current event.

behavior-graph/src/test/kotlin/behaviorgraph/ExtentTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ class ExtentTest : AbstractBehaviorGraphTest() {
5050
assertEquals("custom_r2", e.r2.debugName)
5151
}
5252

53+
@Test
54+
fun `automatic naming can be disabled`() {
55+
g.automaticResourceNaming = false
56+
val e = TestExtentLocal(g)
57+
e.addToGraphWithAction()
58+
59+
// won't get automatic name
60+
assertEquals(null, e.r1.debugName)
61+
// custom name still works
62+
assertEquals("custom_r2", e.r2.debugName)
63+
}
64+
5365
@Test
5466
fun `added resource is updated on adding`() {
5567
val e = TestExtent(g)

0 commit comments

Comments
 (0)