-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
feat: add method to get validation model and it children deeply #1173
base: next
Are you sure you want to change the base?
Conversation
Could you please revert all the unnecessary changes, apart from the actual method to get the models? Your ide probably did those automatically which is unnecessary. |
@dobromir-hristov done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey thanks for the cleanup. We should add some docs and probably a test or two, apart from the comments I left.
* @param {Object} iModel - Internal $model to retrieve the $model for each layer interaction. | ||
* @param {Object} iChildResults - Internal ChildResults from current layer interaction. | ||
* @param {Object} iNestedResults - Internal NestedResults from current layer interaction. | ||
* @returns {Object} - A deep object containing the values of the model and its child and nested results. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param {Object} iModel - Internal $model to retrieve the $model for each layer interaction. | |
* @param {Object} iChildResults - Internal ChildResults from current layer interaction. | |
* @param {Object} iNestedResults - Internal NestedResults from current layer interaction. | |
* @returns {Object} - A deep object containing the values of the model and its child and nested results. | |
*/ | |
* @param {Object} model - Internal $model to retrieve the $model for each layer interaction. | |
* @param {Object} childResults - Internal ChildResults from current layer interaction. | |
* @param {Object} nestedResults - Internal NestedResults from current layer interaction. | |
* @returns {Object} - A deep object containing the values of the model and its child and nested results. | |
*/ |
const unwrappedModel = unwrap(model) | ||
|
||
const treatedModel = | ||
['object', 'array'].includes(typeof unwrappedModel) && !!unwrappedModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the typeof is object or array, !!
will always be true. I think that second check is not necessary.
|
||
const treatedModel = | ||
['object', 'array'].includes(typeof unwrappedModel) && !!unwrappedModel | ||
? { value: unwrappedModel } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the value
just to mimic a ref or computed?
for (const [key, value] of Object.entries(childResults ?? {})) { | ||
result[key] = value?.$values?.() | ||
} | ||
|
||
for (const [key, value] of Object.entries(nestedResults ?? {})) { | ||
result[key] = value?.$values?.() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could merge the two and iterate at once? 🤔
Also why are you iterating over an object that you just built, I dont get that.... cant we just iterate over the childResults?
return Object.keys(result).length > 0 | ||
? { ...treatedModel, ...result } | ||
: treatedModel | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this check at all? What if we just spread them always?
Summary
I use to use this library on my vue applications, but i aways fell its missing a method to get all the
$model
values from all validations and nested children included so i decided to implement it by myself.Metadata
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
next
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information: