In ember documentation it says the following for the method DS.attr():
By default, attributes are passed through as-is, however you can specify an optional type to have the value automatically transformed
If you go to the transform method documentation it says the following:
You can specify that you would like a transform to run for an attribute by providing the transform name as the first argument to the attr method. Ember Data supports attribute types of string, number, boolean, and date, which coerce the value to the JavaScript type that matches its name.
So my question is: is it bad to explicitly insert the type of the attribute? It seems it forces some kind of cast as mentioned after (quoted below). So it could have some performance decrease (almost nothing).
The boolean transform can handle values other than true or false. The strings "true" or "t" in any casing, "1", and the number 1 will all coerce to true, and false otherwise.
The only reason I see to insert the type is to make it easier to read in your model, but that can be done in a comment as well...
Aucun commentaire:
Enregistrer un commentaire