owl icon indicating copy to clipboard operation
owl copied to clipboard

Cannot iterate over Set and Array props in Components

Open Zynton opened this issue 5 years ago • 4 comments

If I have a prop that is of type Array or Set, I currently can't use their forEach methods (or over iteration methods for that matter) in my Components, effectively making these Set props in particular unusable. This is due to props being Proxys and A discussion of this issue can be found at Stack Overflow.

Zynton avatar Dec 06 '19 09:12 Zynton

duplicate of #420

kebeclibre avatar Dec 12 '19 11:12 kebeclibre

@Zinston could you give me a short example to demonstrate this issue? I can't reproduce it

ged-odoo avatar Dec 14 '19 13:12 ged-odoo

@ged-odoo One of the objects in my state (with useState) is a Set. In a Component, I need to iterate over its values, which implies using forEach on it. That doesn't work. If I don't use useState it works fine.

For example, off the top of my hat: In a Component

state = useState({
    mySet: new Set();
});
setToString(mySet: Set): string {
    const items = [];
    VNode[key].forEach(item => {
        items.push(item);
    });
    return items.join('; ');
}

in XML:

<t t-esc="setToString(state.mySet)"/>

Error: Method Set.prototype.forEach called on incompatible receiver [object Object].

Zynton avatar Dec 16 '19 08:12 Zynton

Same is true of Map.get within XML. Similar error.

Zynton avatar Dec 18 '19 09:12 Zynton