diff --git a/packages/focal/src/react/react.ts b/packages/focal/src/react/react.ts index bddaa9f..2d25803 100644 --- a/packages/focal/src/react/react.ts +++ b/packages/focal/src/react/react.ts @@ -312,7 +312,9 @@ class FakeComponent
{ public props: LiftWrapperProps
) {} - setState(newState: LiftWrapperState) { + setState(state: (LiftWrapperState | ((state: LiftWrapperState) => LiftWrapperState))) { + const newState = typeof state === 'function' ? state(this.state) : state + if ('subscription' in newState) this.state.subscription = newState.subscription if ('renderCache' in newState) @@ -390,8 +392,9 @@ class RenderOne
implements Subscription { const { component, props } = liftedComponent.props const renderCache = render(component, props, [value]) - if (!structEq(liftedComponent.state.renderCache, renderCache)) - liftedComponent.setState({ renderCache }) + liftedComponent.setState(state => + !structEq(state.renderCache, renderCache) ? { renderCache } : {} + ) } private _handleCompleted() { @@ -486,8 +489,9 @@ class RenderMany
implements Subscription {
const { component, props } = liftedComponent.props
const renderCache = render(component, props, this._values)
- if (!structEq(liftedComponent.state.renderCache, renderCache))
- liftedComponent.setState({ renderCache })
+ liftedComponent.setState(state =>
+ !structEq(state.renderCache, renderCache) ? { renderCache } : {}
+ )
}
private _handleCompleted(idx: number) {
diff --git a/packages/test/src/app.tsx b/packages/test/src/app.tsx
index e0b9e2e..5d61ff1 100644
--- a/packages/test/src/app.tsx
+++ b/packages/test/src/app.tsx
@@ -11,7 +11,8 @@ declare var require: (path: string) => any
const tests: { name: string, test: TestComponentFocal
+ React
+
+ {list.map(l =>
+ >
+ )
+ }
+}
+
+const trigger = new Subject