-
Notifications
You must be signed in to change notification settings - Fork 1
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
Formalizing Patches. Fix #46 #47
base: main
Are you sure you want to change the base?
Conversation
Still a work in progress, however, its at the stage to finalize changes/review |
aca9948
to
d3b4d4d
Compare
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.
Nice. I added a comment about how we might be able to refactor it a little further to remove some of the remaining boilerplate!
@@ -25,4 +27,17 @@ export class NodeChangeSet implements ChangeSet { | |||
diffObj.value | |||
); | |||
} | |||
|
|||
validated(fn: (ch: NodeChangeSet) => boolean, errMsg: string): Result<NodeChangeSet, Error> { |
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 we are passing the validation function here (which is only called once per patch operation right before applying it), it probably doesn't really buy us much defining this here. I know I initially suggested something like this but it might make more sense to just define a validation function for patch operations. I made an example of what I mean in a commit and pushed it.
this.nodeSearchUtils = nodeSearchUtils; | ||
} | ||
|
||
keyLengthValidator(change) { |
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.
Neither would this (at least not on the base class where I am not convinced it makes the most sense).
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.
Kept it for reuse in couple of places
} | ||
|
||
async put(node: Core.Node, change: NodeChangeSet, resolvedSelectors: NodeSelections): PatchResultPromise { | ||
return this._validChange(change) |
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 is an example of what I meant. Each patch operation just defines their own _put
and _delete
methods which accept a validated change. Validation can be defined in another method, _validChange
. (I am sure there is a better name - maybe getValidChange
or something?)
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.
There are two changes I had to make:
- There should be two validators:
validChangePut
andvalidChangeDelete
. - Not every error can be resolved (deletion for MemberAttributes for example with the above signature).
_put = async (node: Core.Node, change: NodeChangeSet, resolvedSelectors: NodeSelections): PatchResultPromise => { | ||
const [/*type*/, name] = change.key; | ||
this.core.setAttribute(node, name, change.value || ''); | ||
return new PatchResult(change); // I am not sure we need this PatchResult as it seems that it only ever returns the NodeChangeSet that was passed to it...? |
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 didn't remove PatchResult
but does this ever return something other than the change that was applied?
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.
Based on your suggestion, I have created a PatchInfo
object and the signature of _put
and _delete
methods go as follows:
class PatchInfo {
nodeId: GmeCommon.Path;
nodeGuid: Core.GUID;
target: string;
appliedPatch: ChangeSet;
}
type PatchFunction = (node: Core.Node, change: NodeChangeSet, resolvedSelectors: NodeSelections) => Promise<void>;
No description provided.