-
Notifications
You must be signed in to change notification settings - Fork 479
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 get for all Dust references #360
Conversation
dot-notation references will now use get, and getPath is deprecated. Also in this commit: * Update to version 2.2.0 * When get returns a function, add an `isFunction` attribute to the returned function and set it to true. This fixes the bug that was causing dustjs-helpers tests to fail.
Currently merging changes. Will update PR shortly. |
…ath2get Conflicts: lib/dust.js
@@ -302,7 +321,7 @@ dust.nodes = { | |||
}, | |||
|
|||
key: function(context, node) { | |||
return "ctx.get(\"" + node[1] + "\")"; | |||
return "ctx.get(false, [\"" + node[1] + "\"])"; |
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 one of the lines that actually changed.
lgtm, let's get another pair of eyes on it before we merge. |
Let me step back and ask why do this? get/getPath is a mostly internal interface (barring helpers) between the compiler and the dust runtime. Other than refactoring to consolidate to one routine what does this gain us? I guess it might slow down get and getPath each a bit as they were specialized for their own cases before. It's not like we can get rid of getPath either for a long time due to use by helpers so download size will presumably get larger. |
The reason for this change is actually based on a bug in the dustjs-helpers repo. As we were trying to debug, we tracked the problem down to the get method. However, the method was very difficult to understand as it was written. As I rewrote it, I found the source of the bug (PR to be added to the dustjs-helpers repo after this PR is merged). The new Finally, the new version will reduce the total amount of code, because the In summary, this change (1) makes |
does this pass the tests added in #357 it would be good to fix this once. |
See also my comment/proposed fix on #340. This should also be verified to be OK. |
As discussed let's address a few issues:
I think we agree the API should be intuitive and simple and the compiler output should be fast and direct..... not sure what the best solution is. |
The public API (to be used in helpers) now supports getting in the following ways: 'key' '.key' // Only searches in the current context 'path.to.key' '.path.to.key' // Only searches starting in the current context ['key'] ['path', 'to', 'key']
Go straight from getPath to _get Also, update documentation for _get
the dist file seems to be out of date. did you |
thanks for the fixes. This looks good. |
Just this one question: In _get, this bit of code: _get is a new private function so presumably no one is calling it directly from old code. The actual get function, seems to ensure cur is a boolean. |
Good point. It's not needed anymore. |
Use get for all Dust references
dot-notation references will now use get, and getPath is deprecated.
Also in this commit:
isFunction
attribute to the returned function and set it to true. This fixes the bug that was causing dustjs-helpers tests to fail.