-
Notifications
You must be signed in to change notification settings - Fork 335
Don't break wrangler preview
when kv namespaces present
#353
Conversation
pub fn build_script_upload_form( | ||
project: &Project, | ||
include_kv: bool, | ||
) -> Result<Form, failure::Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, boolean parameters are generally considered to be a bad style. I actually really like what you did above, with
let include_kv = false;
rather than just passing false
and true
. But we can do even better!
// note this isn't pub!
fn build_script_upload_form_with_namespaces(
project: &Project,
kv_namespaces: Vec<NamespaceTypeOrWhatever>,
) -> Result<Form, failure::Error> {
// previous body of build_script_upload_form goes here
//
// except you don't need to set up the kv_namespaces variable
}
pub fn build_script_upload_form(
project: &Project,
) -> Result<Form, failure::Error> {
build_script_upload_form_with_namespaces(project, Vec::new())
}
pub fn build_script_upload_form_with_kv(
project: &Project,
) -> Result<Form, failure::Error> {
build_script_upload_form_with_namespaces(project, project.kv_namespaces())
}
I do not know how @ashleygwilliams feels about this kind of refactoring, but I generally prefer it. That being said, boolean parameters are not the worst, so if she prefers this code as-is, I don't think it's the end of the world.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the boolean parameter did indeed feel Gross. I like this better, ty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented this, except called out the "weird" case which is building without kv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Great call on reversing the names.
the preview service as we use it today does not ignore kv namespace bindings, but throws an error when sent a script with those bindings. we don't want to take away a user's ability to use preview, for one, and we also want to give a helpful warning when they do.