Skip to content

Data binding - RegisterCustomDataVariableDefinition impossible to use effectively #412

@LoneBoco

Description

@LoneBoco

Maybe I'm missing something but I find RegisterCustomDataVariableDefinition to be impossible to use. As an example, here is a use case:

I have a std::map<int, MyClass> and I want to use this as a model. I want to be able to iterate over the items like an array:

<div id="container" data-model="items">
	<div data-for="item : items" data-attr-name="item.id">
		<p>Item {{item.id}}</p>
	</div>
</div>

To do this, I go about registering a custom VariableDefinition based on ArrayDefinition. I then change the return value to void* next_ptr = &(it->second);

That's all and good, but I then immediately notice a problem. I have to return a new DataVariable for my result, but in order to do that, I need to know the VariableDefinition of the child element. That shouldn't be a problem, right? The ArrayDefinition constructor passes in the child VariableDefinition so I take a look at DataModelConstructor::RegisterArray and see that it gets the registered definition of the array's value_type using the DataTypeRegister. So I just need to ask the type register for one of my previously registered types and pass that inside my custom VariableDefinition. So where can I gain access to this type register that is storing all my registered types? Well its not accessible in the DataModelConstructor. Nor in any of the returned handles like StructHandle. Nor in the whole Context. As far as I can tell, it isn't publicly accessible anywhere.

Without access to the DataTypeRegister, I cannot make a custom VariableDefinition that contains a Child overload. There is no way to return child data without it. So am I missing something or is this an oversight?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions