-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: As per title Reviewed By: fabiocarballo Differential Revision: D44952337 fbshipit-source-id: 4a1948c181e77c13b6e66fbd1577ca6dbfbb4cac
- Loading branch information
1 parent
887d3cf
commit e99d12a
Showing
5 changed files
with
451 additions
and
516 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
107 changes: 0 additions & 107 deletions
107
litho-it/src/test/java/com/facebook/litho/StateUpdateTestComponent.java
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
litho-it/src/test/java/com/facebook/litho/StateUpdateTestComponent.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,79 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.facebook.litho | ||
|
||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
class StateUpdateTestComponent : SpecGeneratedComponent("StateUpdateTest") { | ||
|
||
private val createInitialStateCount = AtomicInteger(0) | ||
|
||
override fun isEquivalentProps(other: Component?, shouldCompareCommonProps: Boolean): Boolean = | ||
this === other | ||
|
||
override fun hasState(): Boolean = true | ||
|
||
override fun createInitialState(c: ComponentContext, stateContainer: StateContainer) { | ||
val testStateContainer = stateContainer as TestStateContainer | ||
testStateContainer.mCount = INITIAL_COUNT_STATE_VALUE | ||
createInitialStateCount.incrementAndGet() | ||
finalCounterValue.set(INITIAL_COUNT_STATE_VALUE) | ||
} | ||
|
||
fun getCount(c: ComponentContext?): Int = finalCounterValue.get() | ||
|
||
val componentForStateUpdate: StateUpdateTestComponent | ||
get() = this | ||
|
||
override fun createStateContainer(): StateContainer = TestStateContainer() | ||
|
||
protected fun getStateContainerImpl(c: ComponentContext): TestStateContainer? = | ||
c.scopedComponentInfo.stateContainer as TestStateContainer? | ||
|
||
class TestStateContainer : StateContainer() { | ||
@JvmField var mCount = 0 | ||
override fun applyStateUpdate(stateUpdate: StateUpdate) { | ||
when (stateUpdate.type) { | ||
STATE_UPDATE_TYPE_NOOP -> {} | ||
STATE_UPDATE_TYPE_INCREMENT -> mCount += 1 | ||
STATE_UPDATE_TYPE_MULTIPLY -> mCount *= 2 | ||
} | ||
finalCounterValue.set(mCount) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val STATE_UPDATE_TYPE_NOOP = 0 | ||
private const val STATE_UPDATE_TYPE_INCREMENT = 1 | ||
private const val STATE_UPDATE_TYPE_MULTIPLY = 2 | ||
const val INITIAL_COUNT_STATE_VALUE = 4 | ||
@JvmStatic | ||
fun createNoopStateUpdate(): StateContainer.StateUpdate = | ||
StateContainer.StateUpdate(STATE_UPDATE_TYPE_NOOP) | ||
|
||
@JvmStatic | ||
fun createIncrementStateUpdate(): StateContainer.StateUpdate = | ||
StateContainer.StateUpdate(STATE_UPDATE_TYPE_INCREMENT) | ||
|
||
@JvmStatic | ||
fun createMultiplyStateUpdate(): StateContainer.StateUpdate = | ||
StateContainer.StateUpdate(STATE_UPDATE_TYPE_MULTIPLY) | ||
|
||
private val idGenerator = AtomicInteger(0) | ||
private val finalCounterValue = AtomicInteger(0) | ||
} | ||
} |
Oops, something went wrong.