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

Dynamic member lookup #246

Merged
merged 2 commits into from
Jul 28, 2022
Merged

Dynamic member lookup #246

merged 2 commits into from
Jul 28, 2022

Conversation

ilyapuchka
Copy link
Collaborator

@ilyapuchka ilyapuchka commented Sep 22, 2018

This is similar to @dynamicMemberLookup in Swift. Would be ideal if there was a way to check if the type supports this in runtime but it's not possible, so had to introduce a custom protocol for that.
Alternatively, we could have a protocol StencilContextConvertible that will require to expose dictionary to be used in template context, but that will require to add all properties in such dictionary, even those accessible through reflection, instead of only those which are not accessible this way.
Unfortunately, this does not work out of the box (by just adding DynamicMemberLookup conformance) with @dynamicMemberLookup unless type defines subscript with Any? return type.
Resolves #219

@schwa
Copy link

schwa commented Nov 20, 2020

This is a really useful addition to stencil (that I'm currently using) that really ought to be merged in. Very handy.

@schwa
Copy link

schwa commented Nov 8, 2021

Presuming this 4 year old PR isn't going to get merged?

@djbe djbe force-pushed the dynamic-member-lookup branch from 5819c29 to f72f1b9 Compare July 27, 2022 16:35
@SwiftGen-Eve
Copy link

SwiftGen-Eve commented Jul 27, 2022

Hey 👋 I'm Eve, the friendly bot watching over Stencil 🤖

Thanks a lot for your contribution!


Seems like everything is in order 👍 You did a good job here! 🤝

Generated by 🚫 Danger

@djbe djbe added this to the 0.15.0 milestone Jul 27, 2022
@djbe djbe force-pushed the dynamic-member-lookup branch 2 times, most recently from 5ffefb5 to 9d55144 Compare July 28, 2022 00:46
@djbe djbe force-pushed the dynamic-member-lookup branch from 9d55144 to 099b841 Compare July 28, 2022 01:05
Copy link
Contributor

@djbe djbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately there's yet to be a mechanism in Swift to check (at runtime) if a type supports this. So the marker protocol is the next best thing.

@djbe djbe enabled auto-merge July 28, 2022 01:05
@djbe djbe merged commit 256388d into master Jul 28, 2022
@djbe djbe deleted the dynamic-member-lookup branch July 28, 2022 01:07
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

Successfully merging this pull request may close these issues.

Computed properties on objects appear to not be supported
4 participants