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

Allow additional properties with @Configuring #150

Open
JavierSegoviaCordoba opened this issue Dec 1, 2024 · 0 comments
Open

Allow additional properties with @Configuring #150

JavierSegoviaCordoba opened this issue Dec 1, 2024 · 0 comments

Comments

@JavierSegoviaCordoba
Copy link

JavierSegoviaCordoba commented Dec 1, 2024

@Configuring only supports one Action<T> param:

@Configuring
public fun bar(action: Action<Bar>) {
    action.execute(bar)
}

I would like to add a parameter to enable/disable a configuration:

@Configuring
public fun bar(enabled: Boolean = true, action: Action<Bar>) {
    bar = enabled
    action.execute(bar)
}

If I set that property manually in .dcl, it is too late and it keeps false even when it should be enabled, some samples:

// does not work
foo {
    bar {
        enabled = true // too late as I am configuring `foo`
        ...
    }
}
// works
foo {
    barEnabled = true // it uses `bar.enabled` under the hood (*)
    bar {
        ...
    }
}

// (*)
@Restricted
public abstract class Foo {

    @get:Nested public abstract val bar: Bar

    @get:Restricted
    public var barEnabled: Boolean
        get() = bar.enabled
        set(value) {
            bar.enabled = value
        }

    //...
}

Ideally, I would like to do:

// 1.
foo {
    bar(enabled = true) {
        ...
    }
}

// 2.
foo {
    bar { // same as above as default param is `true`
        ...
    }
}

// 3.
foo {
    bar(enabled = false) {
        ...
    }
}

I tried @Adding too with no luck.

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

No branches or pull requests

1 participant