4

I'm reading the LWC Developer Guider and I have found this sentence:

Note Fields are reactive. Expandos are not reactive.

I am not able to understand what it means with "expandos". Can you help me or provide some examples of that?

Thanks!

Update: thanks to your help now is clear what expando means but now there is another doubt.

If I have this code:

**app.html**
<template>
    <p>object prop: {x.a}</p>

    <button onclick={init}>Init</button>
    <button onclick={update}>Update</button>
</template>

**app.js**
import { LightningElement, track } from 'lwc';
export default class App extends LightningElement {
    @track x = {};

    init() {
        this.x.a = "a";
    }

    update() {
        this.x.a = "aa";
    }
}

As far as I understood, the property "x.a" is an expando property since I added it after I defined/created the Object but when I click the two buttons the value on the UI is updated and this means the property is reactive.

Am I missing something? Thanks

3

1 Answer 1

1

It is possible to have properties of a tracked object trackable themselves and this has been working for us since Summer '19 at least. You do this is in the declaration of the tracked property. For you, you would update the declaration thus:

@track x: {
    a: undefined
};

This ensures that a change to "x" itself, or to the "a" property within it will both invoke reactive processing.

As mentioned by BritishBoyInDC there have been some recent changes on tracking which may be why you see what you see and the apparent divergence against the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.