Skip to content

Allow additional properties with @Configuring #150

@JavierSegoviaCordoba

Description

@JavierSegoviaCordoba

@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.

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