-
Notifications
You must be signed in to change notification settings - Fork 479
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
[Expression] Add support of create object via {key: value} syntax #3694
Conversation
Could we use variable as key in this grammar? |
As the discussion result, object key should be a constant and variable is definitely not supported, since the object definition is a syntactic sugar for user to create an initialized object quickly. |
Maybe we can add a new builtin function called
solution 2:
Any ideas? @vishwacsena |
@Danieladu I'm not sure I fully understand the @xieofxie can you share your intended use case/ scenario for key as a variable? Is this something you could achieve via new SetProperties()
{
Assignments = new List<PropertyAssignment>()
{
new PropertyAssignment()
{
Property = "user.foo",
Value = "={}"
},
new PropertyAssignment()
{
Property = "user.foo[dialog.dynamicKey]",
Value = "bar"
}
}
} |
No, I don't have a use case now. I am just curious. SetProperty and AddProperty will do the work |
@vishwacsena the Why we want to create a
It is ugly, with endless nesting. So, we want replace it as: It is more readable. |
It is sufficient if we get the inline notation to work for stable release. we can consider making a function like createObject public if the inline notation + |
fixes: #3493
fixes: #3696
Now in LG and Expression, user can create an object by {key, value, ...}
For example:
{user: "Wilson"}, {user: {age: 27}}
Also, the value can be some variable defined in the scope,
For example, if the scope is {userName: "Allen"}
{user: userName} will be evaluated as {user: "Allen"}