Comments (6)
Trying to import both Presentation
and VerticalSlidesContext
into one scope by using:
fun Presentation.content() {
verticalSlides {
dslSlide {
content { }
}
// Moved to extension function
// dslSlide {
// content { }
// }
nestedContent(this@content)
}
}
fun VerticalSlidesContext.nestedContent(presentation: Presentation) = with(presentation) {
dslSlide {
content { }
}
}
yields the same error.
from kslides.
Hi Filip,
The issue is there are two dslSlide() calls: VerticalSlidesContext.dslSlide() and Presentation.dslSlide()
Prior to moving the dslSlide() call to an extension function, you are calling it in the context of VerticalSlidesContext.
With the extension function, you are calling it in the context of Presentation. Calling the Presentation version of dslSlide()
in the context of a VerticalSlide causes bookkeeping problems (as you saw).
The solution is easy. The extension function should be defined as:
fun Presentation.nestedContent(verticalSlidesContext: VerticalSlidesContext) {
verticalSlidesContext.dslSlide {
content {
h1 { +"I am here" }
}
}
}
and invoked with:
nestedContent(this) // where this is the VerticalSlidesContext of verticalSlides{}
Please let me know if this addresses your problem. If you still have unnecessary clutter, please let me know and we can get it right.
Cheers,
Paul
from kslides.
Very interesting. It's still a little shady for me how exactly both of those contexts interact with one another, especially with extension functions involved. Must be my inexperience with the internal implementations of DSLs in Kotlin.
Nonetheless it completely solved my problem and my presentation is now neatly divided into functions, thank you!
One last thing - I am not knowledgeable enough in Kotlin to determine such thing, but maybe it would be a good idea to include this example in the README? It certainly was not obvious for me why extentind Presentation
and passing VerticalSlidesContext
solved the issue, but extending VerticalSlidesContext
and passing Presentation
did not.
Either way, thank you very much!
from kslides.
Yes, it is an interesting situation when you have multiple applicable this
values. The Kotlin 1.6.20 release previewed context receivers, which help with the case of multiple this
values. I have not added context receivers to kslides because they are not supported in libraries (that may have since changed).
Also, the confusion you went through would have been avoided had I used a different name for dslSlide{} in the VerticalSlide context, but that muddies things up when you move slides around.
I will add a note about this to the README.
If your slides are public, please send me a link so I can show them as an example of what is possible.
Thanks,
Paul
from kslides.
The presentation slides will be published in September. If, by that time, you will still be interested, I will happily share the link :>
I believe that using the same name (dslSlide
) in both contexts was a good choice. Unfortunate that such pitfalls exist, but I think it's worth the consistency.
from kslides.
I added a note to README.md, and yes, I would appreciate you sending a link to [email protected] when you finish them.
Thanks.
from kslides.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kslides.