-
Notifications
You must be signed in to change notification settings - Fork 18
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: remove operations array from the DRP #292
base: main
Are you sure you want to change the base?
Conversation
const drp = cloneDeep(this.originalDRP); | ||
const state = cloneDeep(preOperationState); | ||
|
||
for (const [key, value] of state.entries()) { | ||
drp[key] = value; | ||
} | ||
|
||
const normalizedArgs = Array.isArray(args) ? args : [args]; | ||
drp[fn](...normalizedArgs); |
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 can seperate _computeState
to _computeDRP(dependencies, op)
and getDRPState(drp)
to avoid duplicate these code.
let stateChanged = false; | ||
for (const [key, value] of preOperationState.entries()) { | ||
try { | ||
deepStrictEqual(value, drp[key]); | ||
} catch (e) { | ||
stateChanged = true; | ||
break; | ||
} | ||
} |
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.
create a new function to keep this callFn
not too long
const varNames: string[] = Object.keys(drp); | ||
// biome-ignore lint: values can be anything | ||
const newState: Map<string, any> = new Map(); | ||
for (const varName of varNames) { | ||
newState.set(varName, drp[varName]); | ||
} |
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.
separate _computeState
can avoid this
["grant", "revoke"].includes(vertices[0].operation.type) && | ||
["grant", "revoke"].includes(vertices[1].operation.type) |
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.
it's like the operations array, let's try other solutions
if ( | ||
!(propKey as string).startsWith("_") && | ||
!(propKey as string).startsWith("is") && | ||
!(propKey as string).startsWith("get") && | ||
!(propKey as string).startsWith("query") | ||
) |
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 ( | |
!(propKey as string).startsWith("_") && | |
!(propKey as string).startsWith("is") && | |
!(propKey as string).startsWith("get") && | |
!(propKey as string).startsWith("query") | |
) | |
const excludedPrefixes = ["_", "is", "get", "query"]; // make this a constant, change this when adding a new prefix | |
if (!excludedPrefixes.some(prefix => (propKey as string).startsWith(prefix))) |
refactor code
if (state) { | ||
this.states.set(vertex.hash, { state }); | ||
} else { | ||
const newState = this._computeState( | ||
vertex.dependencies, | ||
vertex.operation, | ||
); | ||
this.states.set(vertex.hash, { state: newState }); | ||
} |
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 (state) { | |
this.states.set(vertex.hash, { state }); | |
} else { | |
const newState = this._computeState( | |
vertex.dependencies, | |
vertex.operation, | |
); | |
this.states.set(vertex.hash, { state: newState }); | |
} | |
if (state) { | |
this.states.set(vertex.hash, { state }); | |
return; | |
} | |
const newState = this._computeState( | |
vertex.dependencies, | |
vertex.operation, | |
); | |
this.states.set(vertex.hash, { state: newState }); |
Reduced Nesting, Readability
Description
This PR closes #257 and closes #310, removing the need to define the operations array by the DRP devs.
Key features:
add(1)
is not creating a new vertex_*
,get*
,is*
orquery*
. By convention such functions are not creating operations