Skip to content
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

Data binding - RegisterCustomDataVariableDefinition impossible to use effectively #412

Closed
LoneBoco opened this issue Feb 11, 2023 · 1 comment · Fixed by #413
Closed

Comments

@LoneBoco
Copy link
Contributor

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?

@LoneBoco
Copy link
Contributor Author

In your opinion, do you think it would be best to add a function to return the DataTypeRegister in the DataModelConstructor or the Context? I've added it to the DataModelConstructor personally and it works great.

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 a pull request may close this issue.

1 participant