legend-pure
legend-pure copied to clipboard
Support the use of Store objects that do not exist globally, but rather via local variables.
Feature Request / Question
Description of Problem:
I am currently trying to implement a Database via my own class. Hence, I define my database via the use of local variables rather than global ones, as, naturally, there is no dedicated syntax for this database type yet (such as in the case of Relational Databases). However, the router component heavily invokes the function elementToPath
on store objects that are present in the mapping object handed over to the execute
function. The function elementToPath
, however, errors when invoked on objects that do not exist globally but are rather bound via local variables.
Potential Solutions:
This is the problematic code segment of elementToPath
:
function meta::pure::functions::meta::elementToPath(element:PackageableElement[1], separator:String[1]):String[1]
{
let path = $element->elementPath();
if($path->size() == 1,
| let first = $path->at(0);
if(is(::, $first),
| '',
| $first.name->toOne());,
| $path->tail()->map(e | $e.name)->joinStrings($separator));
}
If $first
does not have a name
attribute, the call to toOne()
errors. My current workaround is to provide a name
attribute to my custom Store. However, I guess this is rather a hack, as in reality, my local object does not have a package path.
One solution would be to provide a wrapper type that lets me expose my custom store as a packagable element so that calls to that functions do not error. Does such a type/solution exist?