-
Notifications
You must be signed in to change notification settings - Fork 38
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
Refactor frontend pt. 1 #805
Conversation
Also, reactivate backend cmd line argument.
Also update examples to not use outdated Viz class.
WebpackWebpack is the first tool that I'm looking into. Everyone that uses it seems to love it, but the documentation is really rough. After looking into this in some detail today, webpack seems well suited for our current situation as we have a ton of assets that get loaded in Link dump for future me, and for those looking to learn more about webpack:
ModulesThe point of webpack is to manage modules, where modules might refer to JS files, CSS, or something that transpiles to JS, CSS, etc. Unfortunately there is not one but three standards for how to define modules: CommonJS, AMD, and ES6 (a.k.a ECMA Script 6, a.k.a. ECMA Script 2015) modules. The consensus I got early on was that CommonJS is the one to use, even though ES6 will be incorporated in browsers eventually. Unfortunately, TypeScript (which, at the moment, I think we should use) uses ES6 modules, and webpack doesn't support ES6 module natively yet (though it will in webpack 2, whenever that gets released). So, at the moment, I'm thinking I'll have to know both CommonJS and ES6 syntax. Hopefully this will be a temporary thing and not the permanent state of affairs, but neither syntax is too complicated, so whatever!
That's all for today; I think I'm getting webpack enough to start actually implementing stuff tomorrow. The biggest decisions that I will have to mull over will be: Where should Bonus link for those who feel like raw JS is fine: ES6 syntax cheatsheet, which we would get access to through TypeScript. Default function arguments! |
Node Package ManagerOkay, I need to introduce one more tool before I actually start making code changes. With this, however, I think we'll be able to radically simplify the The JavaScript ecosystem is weird. The majority of JavaScript is run in people's browsers, through whatever JS engine is used by the browser; Firefox has SpiderMonkey, Safari has JavaScriptCore, and Chrome has V8. Since these JS engines are super-mega-optimized so that people get their webpages 20 ms faster (and get to see 8 more ads), and some of the are open source, someone had the idea to add a few things to the V8 JavaScript engine and make JavaScript a Legit Programming Language that you can run on the desktop, without a browser. The desktop usage of JavaScript is under the node.js banner. Being a Legit Programming Language means that you can do general purpose stuff like make files and FTP clients and all that kind of stuff. An ecosystem of node.js packages spring up, and they want to use those packages to make new packages, so you need a way of managing JS packages. From that comes the Node Package Manager (npm) and CommonJS modules to interact with packages installed with npm. npm and pip have a lot in common; they solve the same basic problem of managing metadata about packages, resolving dependencies, and interacting with package repositories (e.g., pypi, npmjs.com). However, there are a few key differences which are worth pointing out for those that are familiar with pip:
There are other differences, like explicitly tracking dependencies and developer dependencies, but we don't have to concern ourselves with those differences very much. We will only have developer dependencies, for example. Oh, one last thing to mention about the oddities of the JavaScript ecosystem. As I mentioned at the start, most JS is executed in the browser, yet node.js is designed for the desktop and managing desktop JS packages. Well, since it ended up being the de facto way to deal with JavaScript packages, JS packages that should only ever be used in the browser (e.g., Bootstrap, Ace editor, D3.js) are also installable through npm. Which is basically the reason that we're using npm. NPM + webpackOne thing that might not be clear at this point is the relationship between NPM and webpack. Their relationship is somewhat like the relationship between pip and setuptools, though I think the responsibilities are more clear cut with NPM and webpack. Put simply:
Once we use these tools, the experience for the end-user will be unchanged, aside from faster startup times and (hopefully) less buggy code. For developers, the main change will be an additional step when first setting up nengo GUI for development. Instead of just Note that since |
If |
On the dangers of relying on npm. ;) But in all seriousness, it probably makes sense to use it. |
Basically, if you're changing any of the frontend files (JS, CSS) then you'll need to do
Indeed, we should also stop using pip, apt, conda, etc etc and deliver all code printed out on reams of paper ;) |
Okay, so the update for this afternoon is that I've resolved all of our dependencies through npm. They all exist in the Aside from that fact that I'll need to do the webpack stuff before I can get the GUI in a workable state again (about half done at this point), there was one other issue that I ran into today: some of the versions of JS packages that we're using aren't installable with npm, though later versions are. For now, I'm depending on the updated versions that are installable with npm to see if they work; if they don't, then we can put the old versions back in this repo. Specifically, here are the forced upgrades I've done so far:
Note that unlike all the other packages, git config --global url."https://".insteadOf git://
git config --global url."https://github.com/".insteadOf git@github.com: Finally, for interest, here's the {
"name": "nengo",
"version": "0.2.1",
"description": "Frontend components for Nengo GUI",
"author": "Nengo developers",
"license": "Free for non-commercial use",
"main": "nengo_gui/www/nengo.js",
"repository": {
"type": "git",
"url": "https://github.com/nengo/nengo_gui.git"
},
"bugs": {
"url": "https://github.com/nengo/nengo_gui/issues"
},
"private": true,
"scripts": {
"build": "webpack"
},
"devDependencies": {
"ace-builds": "^1.2.2",
"bootstrap": "^3.3.4",
"bootstrap-validator": "^0.8.1",
"d3": "^3.5.3",
"interact.js": "^1.2.4",
"jquery": "^2.1.3",
"jquery-ui": "^1.10.4",
"jqueryfiletree": "jqueryfiletree/jqueryfiletree#2.1.4",
"webpack": "^1.13.1"
}
} |
This PR is similar to #673 in that it refactors a relatively large part of the codebase, but this time it's all frontend stuff. Frontend meaning anything that the browser touches (mostly JavaScript, but also CSS and HTML). This is a work in progress -- I haven't even implemented anything yet, but since this PR will involve introducing some new tools / concepts, and frontend development moves fast and none of us are on the cutting edge, I'm making the PR now so I can document the process in addition to doing the actual refactoring.
I'll be posting updates frequently throughout the next week or two or however long this takes. If this sounds annoying to you, keep in mind that you can mute individual issues / PRs with this little button on right side of this page:
That's not the actual button, but that's what it looks like. It's over on the right. Just saying.