-
Notifications
You must be signed in to change notification settings - Fork 20
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
Adds cloneAndUpdate to Osdk Objects #1146
base: main
Are you sure you want to change the base?
Conversation
const rawObj = this[UnderlyingOsdkObject]; | ||
const def = this[ObjectDefRef]; | ||
|
||
if ( |
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.
I opted to throw here because I didn't want a mistake like this to go unnoticed, but I realize this may not be what we want to happen in production. I could instead throw only in develop and console.warn in prod? Also, understandably we can expose a more powerful cloneAndUpdate that will replace your primary key for you and hope you know what you're doing, but I'm slightly against that since I'd like to know upfront in develop if I do something wrong
update.$title = update[def.titleProperty]; | ||
} | ||
|
||
const newObject = { ...this[UnderlyingOsdkObject], ...update }; |
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.
I don't filter undefineds, subscribe isn't going to give undefineds for properties it didn't recieve updates for but rather omit the property entirely, and if you get a new object with an undefined via a load I think it should update with that.
packages/api/src/OsdkObjectFrom.ts
Outdated
Q | ||
>["props"][K]; | ||
}, | ||
) => Osdk.Instance<Q, OPTIONS, P>; |
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.
We maintain the scope of the object we call cloneAndUpdate on always in the type, though the raw object may have more properties as well
} | ||
|
||
const newObject = { ...this[UnderlyingOsdkObject], ...update }; | ||
return createOsdkObject(this[ClientRef], this[ObjectDefRef], newObject); |
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.
This also allows random properties to end up as attached to the object(if youas any
type the input). I don't have strong feelings here but opted to expose this functionality if it was really needed by anyone. It would be easy to filter by known properties only here though
89ea2d5
to
b0dc2b8
Compare
b0dc2b8
to
d5246f6
Compare
Invalidated by push of f2c7026
This method will be helpful for updating objects received back from subscriptions.