Skip to content

✨ core: nested schema objects #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

krispya
Copy link
Member

@krispya krispya commented Jul 13, 2025

Currently if you use nested objects in a schema the object will simply be shared between all instances of that trait data. To make it unique an initializer is necessary.

// Every instance of the force trait shares the same object reference
const Forces = trait({
    coherence: { x: 0, y: 0, z: 0 },
    separation: { x: 0, y: 0, z: 0 },
    alignment: { x: 0, y: 0, z: 0 },
    avoidEdges: { x: 0, y: 0, z: 0 },
});

// To make it unique, we explicitly use an initializer
const Forces = trait({
    coherence: () => ({ x: 0, y: 0, z: 0 }),
    separation: () => ({ x: 0, y: 0, z: 0 }),
    alignment: () => ({ x: 0, y: 0, z: 0 }),
    avoidEdges: () => ({ x: 0, y: 0, z: 0 }),
});

However, I am not sure I like this being the default behavior. I am leaning towards making it so all schema objects are read the same no matter their nesting. IE all schema objects are transformed into SoA stores. In this case if you wanted to share an object you use an initializer to have your own store logic.

Follow up question: Should the same be true for arrays?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant