-
Notifications
You must be signed in to change notification settings - Fork 806
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 requirejs
vs. require
#1165
Conversation
Thanks @gnestor. Most of these I think actually don't need changing, since the |
@@ -41,7 +41,7 @@ define(function(require, exports, module) { | |||
"postfix": ", output=FALSE)[['text.tidy']], collapse='\n')))" | |||
}, | |||
"javascript": { | |||
"library": "jsbeautify = require(" + "'js-beautify')", | |||
"library": "jsbeautify = requirejs(" + "'js-beautify')", |
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.
not sure about this, it's a javascript kernel which is running this require call, so it likely doesn't want requirejs?
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.
Good catch! Correct.
@jcb91 Thanks for the feedback. I haven't used requirejs or amd outside of the notebook project, so I don't understand the intricacies. I'm totally open to suggestions about how to best update this repo to reflect the changes in jupyter/notebook#155. |
a mistaken replacement from earlier commit 50ac4b3
fix unintended change to skill keywords. Third-party code from/adapted from codemirror and jquery should function ok on node anyway, because they actually test for typeof define == "function" && define.amd then use define (ratehr than require), which is what we're aiming for.
* use requirejs over require variable name to avoid confusion on node. See jupyter/notebook#155 for details. * don't use the requirejs simplified commonjs wrapper ipython-contrib/jupyter_contrib_nbextensions#1165 which is slower than a dependency array, and relies on toString parsing. See ipython-contrib/jupyter_contrib_nbextensions#1165 for details.
* use requirejs over require variable name to avoid confusion on node. See jupyter/notebook#155 for details. * don't use the requirejs simplified commonjs wrapper ipython-contrib/jupyter_contrib_nbextensions#1165 which is slower than a dependency array, and relies on toString parsing. See ipython-contrib/jupyter_contrib_nbextensions#1165 for details.
* use requirejs over require variable name to avoid confusion on node. See jupyter/notebook#155 for details. * don't use the requirejs simplified commonjs wrapper ipython-contrib/jupyter_contrib_nbextensions#1165 which is slower than a dependency array, and relies on toString parsing. See ipython-contrib/jupyter_contrib_nbextensions#1165 for details.
* use requirejs over require variable name to avoid confusion on node. See jupyter/notebook#155 for details. * don't use the requirejs simplified commonjs wrapper http://requirejs.org/docs/api.html#cjsmodule which is slower than a dependency array, and relies on toString parsing. See ipython-contrib/jupyter_contrib_nbextensions#1165 for details.
* use requirejs over require variable name to avoid confusion on node. See jupyter/notebook#155 for details. * don't use the requirejs simplified commonjs wrapper http://requirejs.org/docs/api.html#cjsmodule which is slower than a dependency array, and relies on toString parsing. See ipython-contrib/jupyter_contrib_nbextensions#1165 for details.
* use requirejs over require variable name to avoid confusion on node. See jupyter/notebook#155 for details. * don't use the requirejs simplified commonjs wrapper http://requirejs.org/docs/api.html#cjsmodule which is slower than a dependency array, and relies on toString parsing. See ipython-contrib/jupyter_contrib_nbextensions#1165 for details.
as it works by searching through the module definition function's toString representation, the commonjs style requirejs wrapper is slower, and prone to subtle errors. We don't actually need it anywhere, so use regular requirejs define calls instead.
it's slower & relies on parsing toString :O see jupyter/notebook#155 ipython-contrib/jupyter_contrib_nbextensions#1165 for details
@gnestor no problem.
Nor have I really, but I've been bitten by a few of its intricacies in the commonjs wrapper style that got me to dig into how it behaves 😆 For almost all cases, I think we could get away with just doing nothing, given I've made a few fixes which I've pushed into this PR branch, hope that's ok. Essentially they are
The simplified commonjs wrapper is used when you have a call without explicit dependencies, like define(function (require, exports, module) {
var other_module = require('./my_custom_module'); // synchronous require call
}); in this format, requirejs actually searches the var my_dependency = './my_files/' + some_other_var;
require(my_dependency); which also doesn't match the requirejs regex 🐛 |
Thanks for making these changes, @jcb91!
Does this require further refactoring then? Should it be done in this PR? |
@gnestor np! I think I've covered everything for this repo in this PR already in d668614 - there were only a few instances anyway. There are a couple of dependencies which should also be dealt with, but they'll be handled in their respective repos anyway (e.g. minrk/nbextension-scratchpad#19, jfbercher/jupyter_latex_envs, jcb91/jupyter_highlight_selected_word#22). In summary, I think this is ok to merge as-is, if anything breaks (hopefully not super likely!), we should hear about it soon enough before any pip/conda releases. |
See jupyter/notebook#155