Skip to content

Conditionals do not shortcut the evaluations under them. #581

Description

@yajaru

Currently we have a problem with enaml Conditionals where subscriptions under the Conditional are evaluating even after the condition has gone false. Effectively, we are missing the short cutting that you would need for this to behave correctly.

Here is a sample app that demonstrates the issue. Press the "Switch" button twice and an exception will be raised due to a type error.

from enaml.widgets.api import MainWindow, Container, PushButton, Label
from enaml.core.api import Conditional

enamldef Main(MainWindow): mw:

	attr string_or_int = "abc"

	Container:
		PushButton:
			text = "Switch"
			clicked::
				mw.string_or_int = 99 if isinstance(mw.string_or_int, str) else "abc" 

		Conditional:
			condition << isinstance(mw.string_or_int, str)
			Label:
				text << mw.string_or_int[1]

		Conditional:
			condition << isinstance(mw.string_or_int, int)
			Label:
				text << str(mw.string_or_int / 3)

One possible option to fix this would be to add a "depth" property to subscriptions and processing in a depth based order, unsubscribing invalidated Conditionals' children as we go, but that seems fairly invasive. Not sure if there is an easier way to fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions