klum-dsl / klum-ast

Turn your models into super models
https://github.com/klum-dsl/klum-ast/wiki
MIT License
3 stars 0 forks source link

Late binding arguments #164

Open pauxus opened 5 years ago

pauxus commented 5 years ago

It might be an interesting idea to allow (either by default or via switch) Closure Parameters for methods:

@DSL class Foo {
   String name
   String nickname
}

which could create a method String nickname(@DelegateTos(Foo) Closure<String> name) which would only be executed called during PostApply phase.

Foo.create {
  nickname { name.toLowerCase() }
}

Of course, this example could be implemented using @Default

This might be a direct alternative to #84

pauxus commented 5 years ago

LateBinding could be a parameter to @Field (or a separate annotation)

Implementation could be done using a Map<String, Closure> in the RW class that is executed in postApply

pauxus commented 1 year ago

Question: in which phase should late binding run? AutoCreate, autoLink or PostTree? Probably PostTree

LateBinding arguments make no sense on DSL fields, since they already have a Closure argument method

More in spirit with #84 : PostTree (and other lifecycle methods?) could be allowed on fields of type Closure