Skip to content

brainstorm: should we get rid of the requirement to pass in @allocator builtin attribute to every root element? #145

Description

@nurulhudaapon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions