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 context to be initialised with Any #281

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

adam-fowler
Copy link

@adam-fowler adam-fowler commented Jul 17, 2019

Given Mirror is being used to serialize objects that are members of the Context dictionary, it only seems logical we shouldn't be limited to initializing a Context with a dictionary. This PR adds the ability to initialize a context with Any

Initialize Context with Any by converting to dictionary
Allow Any to be pushed onto a Context in a similar way
Change Environment functions to use these new functions

Initialise Context with Any by converting to dictionary
Allow Any to be pushed onto a Context in a similar way
Change Environment functions to use these new functions
@adam-fowler
Copy link
Author

This will fix #223 (comment)

Tests/StencilTests/TemplateSpec.swift Outdated Show resolved Hide resolved
Tests/StencilTests/TemplateSpec.swift Outdated Show resolved Hide resolved
Sources/Context.swift Outdated Show resolved Hide resolved
@adam-fowler
Copy link
Author

@ilyapuchka Is this getting merged in or do I need another approval?

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.

Can we possibly avoid the Mirror(...).asDictionary() bit? Stencil already has quite extensive reflection capabilities for multiple types (when rendering a template).

Sources/Context.swift Outdated Show resolved Hide resolved
Co-authored-by: David Jennes <[email protected]>
@adam-fowler
Copy link
Author

Can we possibly avoid the Mirror(...).asDictionary() bit? Stencil already has quite extensive reflection capabilities for multiple types (when rendering a template).

I'll have to have a good look at the code again. It was a wee while ago when I wrote this

@adam-fowler
Copy link
Author

Can we possibly avoid the Mirror(...).asDictionary() bit? Stencil already has quite extensive reflection capabilities for multiple types (when rendering a template).

@djbe I had a look through the code again. None of the reflection code seems accessible at this point. Is there function that takes an object and converts it to a [String: Any] somewhere else?

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.

3 participants