Current:
pub fn ProductList(allocator: zx.Allocator) zx.Component {
const products = [_][]const u8{ "Apple", "Banana", "Orange" };
return (
<main @allocator={allocator}>
<h2>Products</h2>
<ul>{for (products) |product| (<li>{product}</li>)}</ul>
</main>
);
}
Proposed:
pub fn ProductList() zx.Component {
const products = [_][]const u8{ "Apple", "Banana", "Orange" };
return (
<main>
<h2>Products</h2>
<ul>{for (products) |product| (<li>{product}</li>)}</ul>
</main>
);
}
Here in order to allocate memory for the product array (and for few other things like using .fmt to format expressions) an allocator is needed, however we don't have access to the per request arena allocator hence we are having to pass in the allocator down to here. We have two options:
- Store the per/request arena allocator to a global and use that from there (zx.server.arena) or add the option to support components that doesn't have allocator and as first option use the allocator from the parent component or use a global allocator and register to be cleaned up before sending out the response.
Current:
Proposed:
Here in order to allocate memory for the product array (and for few other things like using .fmt to format expressions) an allocator is needed, however we don't have access to the per request arena allocator hence we are having to pass in the allocator down to here. We have two options: