Changing params API #727
Replies: 29 comments 15 replies
-
Is there something that prevents using |
Beta Was this translation helpful? Give feedback.
-
That could work but then the compile time type would be You'd have to do stuff like this: page = params.get(:page).as(String)
user_params = params.get(:user).as(Hash(String, String))
users = params.get(:users).as(Array(Hash(String, String))) The other bummer is that the error it throws when it is not the correct type is kind of opaque. Using methods like The other option would be to have a wrapper class like Crystal uses with |
Beta Was this translation helpful? Give feedback.
-
Sounds like a decent reason to me. I don't think I've really needed to use the nested yet, however, I don't like I haven't checked, but if you did |
Beta Was this translation helpful? Give feedback.
-
Yeah for the most part the methods are used internally by Lucky and Avram but I figure if we can make them better we should haha. In the case of array_of(:page) it would raise because the param is not an array
|
Beta Was this translation helpful? Give feedback.
-
I also wonder if |
Beta Was this translation helpful? Give feedback.
-
I think hash_for is a good change (on top of the suggested changes). We also may want to look towards Onyx’s param handling for other ideas in dealing with params Harrison Bachrach
|
Beta Was this translation helpful? Give feedback.
-
@HarrisonB Can you provide a bit more detail on what you mean? I think Onyx has a great type safe way to handle this, but this is for more ad-hoc param access. I do want to see if we could work with Onyx param handling for query params at the action level. That way Lucky doesn't need to roll its own! |
Beta Was this translation helpful? Give feedback.
-
@paulcsmith Ah, gotcha. Yes, I think integrating with Onyx itself for structured params makes sense.
This was the other thing I was thinking but these are valid points. The only thing that I might suggest is changing "for" to another preposition? Maybe Also, what would |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Maybe |
Beta Was this translation helpful? Give feedback.
-
Would this |
Beta Was this translation helpful? Give feedback.
-
I wrote the wrong thing at first. I meant |
Beta Was this translation helpful? Give feedback.
-
I vote to have also params[:name] to return single value. value_at is too long. |
Beta Was this translation helpful? Give feedback.
-
One thing to keep in mind is that you should rarely ever use these methods yourself, so length may not matter as much. The only time I ever use these is when I'm writing code in Lucky or Avram. With that said I kind of agree with the Then again maybe I should just make the param parser a hash :P I think that could be hard to traverse but maybe it is worth it for simplicity. |
Beta Was this translation helpful? Give feedback.
-
I like the naming of
I don't love the idea of the params being a hash, mostly because then all the value would have to be some kind of union type like |
Beta Was this translation helpful? Give feedback.
-
Well said @edwardloveall. I think |
Beta Was this translation helpful? Give feedback.
-
Thoughts on |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I think I’ll just keep it simple and do
|
Beta Was this translation helpful? Give feedback.
-
An alternative to |
Beta Was this translation helpful? Give feedback.
-
I’m not sure about single or scalar. Seems a bit unclear to me. What do you think about sticking with the types?
|
Beta Was this translation helpful? Give feedback.
-
I still like |
Beta Was this translation helpful? Give feedback.
-
@jwoertink me too 😬 Looking it up just now, my understanding is it's a single value, but possibly with the caveat of being able to be increased and decreased. I think it comes from vector math where you have a unit vector pointing in a direction, and you "scale" each axis by a value to get the final vector. So the vector |
Beta Was this translation helpful? Give feedback.
-
This makes a very consistent API: params.string(:page)
params.hash(:user)
params.array(:users) |
Beta Was this translation helpful? Give feedback.
-
What I would like is params[:key] - As I usually try to avoid to send post like I like to have one hash with everything, like:
(I know this is like JSON more than a hash, but bear with me :D) What I do now in my production app to make it simple for myself is to just do I think I understand if it has to be sent through Operation, but what If I don't or have to process it somehow before sending it to operation. |
Beta Was this translation helpful? Give feedback.
-
@confact Could you clarify the use case a bit? I think you can do |
Beta Was this translation helpful? Give feedback.
-
@wout oh wow that is fantastic! Can't wait to hear how it goes. I'm setting up my "sponsors" page soon and one of the tiers has some consulting time and you can choose a feature or bug for me to prioritize. Might be worth it for your company, but no pressure. Just an option in case you run into stuff and need some help! Don't feel pressured though. I am happy to help in Gitter like I try to do anyway regardless of "sponsorship" :D |
Beta Was this translation helpful? Give feedback.
-
@paulcsmith I don't suppose you'd mind reviewing this thread and providing a final summary we can mark as the answer? I don't have a strong opinion on how this is tackled, but am happy to create the issue after we decide on a final approach. |
Beta Was this translation helpful? Give feedback.
-
Was reminded of this discussion from this conversation luckyframework/avram#408 (comment) The issue that we're having right now is that we need to be able to cover all these bases:
All of these bases are covered except for the multiple nested values and that is only if you consider it ok that nested key/values can not have any values that are arrays or themselves nested. As long as we are not defining expected params in the Action class, I think we need to convert The other thing I would like to see is that We will need two different data stores, one for regular data and one for file uploads so that they don't overlap. Ideally, we could base |
Beta Was this translation helpful? Give feedback.
-
The current way
These methods are mostly used for internal Lucky/Avram code and rarely used in user code, but I think we should make them clearer so when people try to contribute it makes sense.
What might be better
I think these new names read a lot better, make more sense, and are a tad bit shorter too :)
Thoughts? cc @HarrisonB @jwoertink @edwardloveall
Beta Was this translation helpful? Give feedback.
All reactions