Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller is not lazily started if only the effects field is accessed #26

Closed
FlowMo7 opened this issue May 4, 2021 · 1 comment
Closed

Comments

@FlowMo7
Copy link

FlowMo7 commented May 4, 2021

The Controller is not started lazily if only the controller.effects getter is called (and no other property such as the controller.state is accessed or controller.dispatch is being called).

There may be the start() logic missing here:

private val effectEmitter: (Effect) -> Unit = { effect ->
val canBeOffered = effectsChannel.offer(effect)
if (canBeOffered) {
controllerLog.log { ControllerEvent.Effect(tag, effect.toString()) }
} else {
throw ControllerError.Effect(tag, effect.toString())
}
}

In a real world example, this would be relebant if e.g. in a transformer an onStart() with an emitEffect() should be called, which would then only be called after an action has been dispatched.

I'm just about to create a PR which adds a test for that as well as a possible fix, if the current behavior is not considered expected.

@floschu
Copy link
Owner

floschu commented May 7, 2021

good catch 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants