@@ -17,15 +17,15 @@ import com.instacart.formula.Transition
17
17
internal class FormulaManagerImpl <Input , State , Output >(
18
18
private val formula : Formula <Input , State , Output >,
19
19
initialInput : Input ,
20
- private val listeners : ScopedListeners ,
20
+ private val listeners : Listeners ,
21
21
private val transitionListener : TransitionListener
22
- ) : SnapshotImpl.Delegate, FormulaManager<Input, Output> {
22
+ ) : FormulaManager<Input, Output> {
23
23
24
24
constructor (
25
25
formula: Formula <Input , State , Output >,
26
26
input: Input ,
27
27
transitionListener: TransitionListener
28
- ): this (formula, input, ScopedListeners (formula ), transitionListener)
28
+ ): this (formula, input, Listeners ( ), transitionListener)
29
29
30
30
private val actionManager = ActionManager ()
31
31
@@ -80,7 +80,6 @@ internal class FormulaManagerImpl<Input, State, Output>(
80
80
state = formula.onInputChanged(prevInput, input, state)
81
81
}
82
82
83
- listeners.evaluationStarted()
84
83
val transitionDispatcher = TransitionDispatcher (input, state, this ::handleTransitionResult, transitionId)
85
84
val snapshot = SnapshotImpl (transitionId, listeners, this , transitionDispatcher)
86
85
val result = snapshot.run { formula.run { evaluate() } }
@@ -147,27 +146,27 @@ internal class FormulaManagerImpl<Input, State, Output>(
147
146
return false
148
147
}
149
148
150
- override fun <ChildInput , ChildOutput > child (
149
+ fun <ChildInput , ChildOutput > child (
150
+ key : Any ,
151
151
formula : IFormula <ChildInput , ChildOutput >,
152
152
input : ChildInput ,
153
153
transitionId : TransitionId
154
154
): ChildOutput {
155
155
@Suppress(" UNCHECKED_CAST" )
156
156
val children = children ? : run {
157
- val initialized: SingleRequestMap <Any , FormulaManager <* , * >> = mutableMapOf ()
157
+ val initialized: SingleRequestMap <Any , FormulaManager <* , * >> = LinkedHashMap ()
158
158
this .children = initialized
159
159
initialized
160
160
}
161
161
162
- val compositeKey = constructKey(formula, input)
163
162
val manager = children
164
- .findOrInit(compositeKey ) {
163
+ .findOrInit(key ) {
165
164
val childTransitionListener = getOrInitChildTransitionListener()
166
165
val implementation = formula.implementation()
167
166
FormulaManagerImpl (implementation, input, childTransitionListener)
168
167
}
169
168
.requestAccess {
170
- throw IllegalStateException (" There already is a child with same key: $compositeKey . Override [Formula.key] function." )
169
+ throw IllegalStateException (" There already is a child with same key: $key . Override [Formula.key] function." )
171
170
} as FormulaManager <ChildInput , ChildOutput >
172
171
173
172
return manager.evaluate(input, transitionId).output
@@ -185,16 +184,6 @@ internal class FormulaManagerImpl<Input, State, Output>(
185
184
listeners.disableAll()
186
185
}
187
186
188
- private fun <ChildInput , ChildOutput > constructKey (
189
- formula : IFormula <ChildInput , ChildOutput >,
190
- input : ChildInput
191
- ): Any {
192
- return FormulaKey (
193
- type = formula.type(),
194
- key = formula.key(input)
195
- )
196
- }
197
-
198
187
private fun getOrInitChildTransitionListener (): TransitionListener {
199
188
return childTransitionListener ? : run {
200
189
TransitionListener { result, isChildValid ->
0 commit comments