Skip to content

[docs] Document changes to property declarations in #369 #375

Closed

Description

@sorvell

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.

Activity

  1. added this to the 1.0.0 milestone on Dec 15, 2018
  2. kevinpschaaf commented on Dec 15, 2018

    @kevinpschaaf
    Member

    @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)

        type propValue != null propValue == null
        String propValue null
        Number propValue null
        Boolean propValue ? '' : null null
        Object JSON.stringify(propValue) null
        Array JSON.stringify(propValue) null
  3. Repository owner unassigned on Dec 18, 2018
  4. ghost closed this as completedin #380on Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions