Add context option#777
Conversation
|
We also should discuss making it |
|
// @juhovh |
@szmarczak @juhovh @sholladay Any thoughts on this? I guess most will want an object here as they would want to name the data, for example |
|
Ah, forgot about that one.
👍
Shallow merge looks good to me. If someone wants deep merge we can discuss this later. |
|
I would rather name this
As for its type, I would probably go for |
There's a big difference though.
How about |
|
Sorry for not commenting earlier, but I wasn’t quite sure then what would be the best option here. After giving it some thought, I believe this userData is shared between all different hooks, right? Unknown would make sense if it would be per hook, but shared data shouldn’t be of unknown type IMHO. Having an object with unknown values is fine, one argument for doing a shallow merge would be that one could throw an error in case of a conflict between hooks. For the same reason deep merge sounds wrong, since got doesn’t own the data that the hook sets. It all boils down to which part of the code owns what in the end. |
|
FWIW, when I first saw this feature named
Yeah, I was thinking of suggesting that. Sounds good to me. 👍 |
|
Regarding shallow merge: const a = got.extend({
userData: {
unicorn: {
value: "this won't get merged"
},
catSays: "meow"
}
});
const b = a.extend({
userData: {
unicorn: {
color: "rainbow"
},
dogSays: "woof"
}
});
// Result:
{
unicorn: {
color: "rainbow",
},
catSays: "meow",
dogSays: "woof"
}There's one con. Should arrays be merged? Or replaced? So yeah, it can be a object with no merge mechanics. We could simply emit old user data and new user data so the user can decide... |
|
Maybe let's leave it |
Any other naming suggestions? I don't really want the
Cool. Let's make it an object and no merging. TS typed as Actually, should we make it generic? Another question, should it be a |
|
IMO
👍
It depends on the usage. Or maybe let's accept both: generic objects and maps? |
I think we should pick one. If we make it a union, users will have to type assert it, which is annoying. |
|
I'm leaning towards |
|
|
|
Both |
|
@sholladay Thoughts on Map vs object? I’m leaning towards Map. |
|
Let’s go with |
|
Hmm, Map would make it much harder to manually extend if the user wanted to do so. Let's go with object. |
Co-Authored-By: szmarczak <36894700+szmarczak@users.noreply.github.com>
| useElectronNet?: boolean; | ||
| form?: Record<string, any>; | ||
| json?: Record<string, any>; | ||
| context?: object; |
There was a problem hiding this comment.
How do I make this generic?
Co-Authored-By: Sindre Sorhus <sindresorhus@gmail.com>
Fixes #740
Checklist