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

Unable to render using nested if else statement #51

Open
Tracked by #74
ltfschoen opened this issue Apr 3, 2023 · 2 comments
Open
Tracked by #74

Unable to render using nested if else statement #51

ltfschoen opened this issue Apr 3, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@ltfschoen
Copy link
Contributor

ltfschoen commented Apr 3, 2023

I can get it to render if i do a single level of if, else if, and else statements
Screen Shot 2023-04-03 at 12 29 38 pm

But if i use the code that has been commented out instead, which seems to be the same code, but so i have just nested if else statements, then it gives the following error. is the idea that i should proceed trying to figure out how to use Box::new if i want to use nested if else statements?
Screen Shot 2023-04-03 at 12 32 26 pm

@maciejhirsz maciejhirsz added the bug Something isn't working label Apr 3, 2023
@maciejhirsz
Copy link
Owner

Yeah, that's stretching the limits of what auto_branch can do atm, the control flow analysis is pretty dumb because I don't want to pull in syn and kill compile times. It's fixable, but for now you might have to disable auto_branch and wrap the view! invocations in appropriate BranchN enum.

@ltfschoen
Copy link
Contributor Author

Yeah, that's stretching the limits of what auto_branch can do atm, the control flow analysis is pretty dumb because I don't want to pull in syn and kill compile times. It's fixable, but for now you might have to disable auto_branch and wrap the view! invocations in appropriate BranchN enum.

Thanks, I got it to work with Branch3

...
use kobold::branching::Branch3;
...
#[component]
fn Cell(col: usize, row: usize, state: &Hook<State>) -> impl View + '_ {
    let value = state.source.get_text(&state.rows[row][col]);

    if state.editing == (Editing::Cell { row, col }) {
        let onchange = state.bind(move |state, e: Event<InputElement>| {
            state.rows[row][col] = Text::Owned(e.target().value().into());
            state.editing = Editing::None;
        });

        Branch3::A(view! {
            <td.edit>
                { ref value }
                <input.edit {onchange} value={ ref value } />
            </td>
        })
    // https://github.com/maciejhirsz/kobold/issues/51
    } else {
        let ondblclick = state.bind(move |s, _| s.editing = Editing::Cell { row, col });

        if value.contains("0x") {
            Branch3::B(view! {
                <td {ondblclick}>
                    { ref value }
                    <QRForTask {value} />
                </td>
            })
        } else {
            Branch3::C(view! {
                <td {ondblclick}>{ ref value }</td>
            })
        }
    }
}

ltfschoen added a commit to ltfschoen/kobold that referenced this issue Apr 3, 2023
@maciejhirsz maciejhirsz mentioned this issue Apr 14, 2023
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants