You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[docs] Document changes to property declarations in #369 #375
Please refer to the changes noted in the README and CHANGELOG.
We should also add a special note that although it's possible to reflect: true a type: Object|Array property, this should only be done in exceptional situations since the attribute becomes that JSON version of the property. If the property can have a non-trivial value, this will result in poor performance since the attribute can become a very long string.
@katejeffreys Based on the changes in #369, this is the new behavior:
LitElement uses a "converter" to serialize typed property values to string attribute values, and deserialize from string attribute values to typed property value
The "converter" can specify either just a fromAttribute function, or an object with both a toAttribute and a fromAttribute function
The type field is now only used as metadata to the converter. It is no longer invoked as a function by default.
A built-in "default converter" is used if no converter is specified for a property, which handles common types: String, Number, Boolean, Object, and Array. Any types outside of these will pass through the default converter as if they were Strings (generally, it wouldn't make sense to use types outside of these without a custom converter).
If toAttribute returns null, this is used as a signal to call removeAttribute
If toAttribute returns undefined, this is used as a signal to not change the attribute
Behavior of the default converter:
fromAttribute:
type
attrValue !== null
attrValue === null (attribute removed)
String
attrValue
null
Number
Number(attrValue)
null
Boolean
true
false
Object
JSON.parse(attrValue)
null
Array
JSON.parse(attrValue)
null
toAttribute: (note returning null results in removeAttribute)
Activity
kevinpschaaf commentedon Dec 15, 2018
@katejeffreys Based on the changes in #369, this is the new behavior:
fromAttributefunction, or an object with both atoAttributeand afromAttributefunctiontypefield is now only used as metadata to the converter. It is no longer invoked as a function by default.converteris specified for a property, which handles common types:String,Number,Boolean,Object, andArray. Any types outside of these will pass through the default converter as if they wereStrings (generally, it wouldn't make sense to use types outside of these without a customconverter).toAttributereturnsnull, this is used as a signal to callremoveAttributetoAttributereturnsundefined, this is used as a signal to not change the attributefromAttribute:typeattrValue !== nullattrValue === null(attribute removed)StringattrValuenullNumberNumber(attrValue)nullBooleantruefalseObjectJSON.parse(attrValue)nullArrayJSON.parse(attrValue)nulltoAttribute: (note returningnullresults inremoveAttribute)typepropValue != nullpropValue == nullStringpropValuenullNumberpropValuenullBooleanpropValue ? '' : nullnullObjectJSON.stringify(propValue)nullArrayJSON.stringify(propValue)null