-
Notifications
You must be signed in to change notification settings - Fork 2
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
Use '.@' at the end of the param, to pass effective path instead of the value #1
Conversation
src/rule.js
Outdated
@@ -57,7 +59,13 @@ const defaultEnabler = [() => true], | |||
}, | |||
queryPath = (value, context) => (p) => { | |||
if (isFunction(p)) return 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.
Yes, this is good, my only doubt is that we are taking another symbol "@" as operation. Intention is to make path as less DSL filled as possible. What do you think of another approach, where we can add current path as a parameter to a function here? Not just p() but p(contextPath)?
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.
Function as parameter will have something extra in terms of input data, it might be context path and value also
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 did it somewhat more as a "function as decorator" than "function as parameter".
This way we have someting that is looking as functional thing (and for simplicity i decided to go with the creating function that has a special "tag value" assigned as own key).
Other implementations I've done was based on the getPathTo returning object that had "original parameter" and flags (which was effectively pretty much the same as this implementation, but had more lines and ifs) and the "hoc style" that has created new function that was "identifying" itself when it received special argument (and that was too magical, and there was a chance of side effects if someone passed function as a param and if that function had side effects).
The most "stylish" would be probably based on class, then we could check if the object is instance of some our tool class, and then we could use that information to get the path instead of data, but that would then be biggest in the LOC sense, I think.
I agree, this is not ellegant to just "attach" own key to the function, but I think it's a) small, b) easy, c) fast.
This is something I was thinking of.
Such a path specification received as a param would make some things a lot easier.