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

feat: call map-key w/ parent-schema information #119

Closed

Conversation

rschmukler
Copy link
Contributor

This commit passes the parent-schema (ie. the schema of the map) to get the transformer function used in map-keys.

This is useful if your map-keys wants to introspect the schema to determine
its behavior. An example usecase would be automatically remove the most
prevelant namespace of a key, and adding a string underscore encoding
for other namespaces. Eg. you can use this to write a json encoder that
does something like the following:

{:person/name "Bob" :person/age 36 :pet/name "Edgar"}
;; =>
{"name" "Bob" "age" 36 "pet_name" "Edgar"}

This commit passes the parent-schema (ie. the map) to get the transformer
function.

This is useful if your map-keys wants to introspect the schema to determine
its behavior. An example usecase would be automatically remove the most
prevelant namespace of a key, and adding a string underscore encoding
for other namespaces. Eg. you can use this to write a json encoder that
does something like the following:

```clj
{:person/name "Bob" :person/age 36 :pet/name "Edgar"}
;; =>
{"name" "Bob" "age" 36 "pet_name" "Edgar"}
```
@ikitommi
Copy link
Member

Thanks for the PR. I'm not happy about this breaking the contract of having this as an argument to the transforming function (father schema would be used instead).

There is a discussion about having a link to the parent from all schemas, which would, I believe, solve this without breaking the contract.

Collected info into an new issue #120

@rschmukler
Copy link
Contributor Author

Makes sense! It definitely felt dirty but since map-key is already a bit of a hack (eg. not a truly traversed schema entry, nor IntoSchema I thought it might be acceptable.

For my use case, I can get away with not having it once #122 lands - moving the functionality into the :after of the :map interceptor. I would imagine that for many use cases, the interceptors solve needing parent information. Closing this for now.

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.

2 participants