-
Notifications
You must be signed in to change notification settings - Fork 148
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 Configurable Serializer Function (Solves #153) #155
Conversation
@@ -19,7 +19,8 @@ class JsRoutes | |||
url_links: nil, | |||
camel_case: false, | |||
default_url_options: {}, | |||
compact: false | |||
compact: false, | |||
serializer: "this.default_serializer" |
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.
I think we should use nil here. This value feels too magical if someone will try to debug it.
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.
@bogdan If we set the default to nil
here, we will have to do a check somewhere else to set the default initializer. It has to get set somewhere, we can't just have a nil
initializer floating around. Where would you prefer it get set?
Something like this on line 108?
js.gsub!("SERIALIZER", @options[:serializer] || "this.default_serializer")
I think setting in the defaults is better than this option. This feels like a magic value. And really, this.default_serializer
is the default—not nil
. It doesn't make sense to have a nil
initializer.
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 way we can make it clear is to make default_serializer
a public method and let default be JsRoutes.default_serialize
. In this way people can clearly see where is the default and even test in console it in console comparing to other serializers.
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.
@bogdan I'm not totally sure I follow. How does this work with the configurable namespace? We can't set the default to a public method on JsRoutes
because we don't know that JsRoutes
exists.
It might be better to just make default_serializer
public when we run createGlobalJsRoutesObject
, and then just add a README note that it is public on the namespace that the user defines, rather than try to get the default value to include the name of the configurable namespace.
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.
Hm, you are right. namespace config value makes it not static. Let me think till tomorrow.
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.
js.gsub!("SERIALIZER", @options[:serializer] || "null")
and in coffeescript:
serializer = SERIALIZER
unless serializer?
#use default
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.
I still vote for nil
as default and implementation as @le0pard suggested.
@le0pard @bogdan alright, I set the default to I think you guys are making the wrong call setting the default value to be a nonsense I hope we can get this merged in soon. Thanks |
Funny, @jordanstephens . You think line "this.default_serializer" should mean something for developers, but one condition can slowdown all codebase :) I think to not set initializer each time in function variable with serializer, we can cache it in custom_serializer: SERIALIZER
serialize: (object) ->
if @custom_serializer? and @get_object_type(@custom_serializer) is "function"
@custom_serializer(object)
else
@default_serializer(object) |
Allow Configurable Serializer Function (Solves #153)
Here's a first pass on a configurable serializer for issue #153.
Usage is as described in that issue.
Also note that I removed a bunch of "if jQuery present" specs as they should no longer be relevant.
If everything looks good to you guys, I'll update the readme.
Let me know if you guys have any questions.
Thanks!