Closed nfreear closed 6 years ago
Agreed. I've not much experience in doing larger pieces of coding with javascript and it will get unwieldy so good to understand practices for this.
Hi @TimCoughlan,
Do you want to have a meeting in a week or two to talk through some ideas?
I've sketched out a example of how the Javascript could be split:
index.js # This JS `require`s all the following (including JSON);
core.js # initialiseElements(), updateElements(), getElements(), … moveFwdElement();
config.js # var numElements = 30, … ??
assets.js # getIcon(), getEmoticon(), var emojiDir, cardDir;
dimension.js # var iconWidth, iconHeight … postitTextY, postitTextWidth;
layout.js # layoutSvgCards() – based on a single <svg> template ??
file.js # saveJourney(), loadJourney();
share-link.js # createShareLink(), loadShareLink();
user-ui.js # changeBackground(), toggleEditor(), toggleOptions() … ;
utils.js # getElementById(), querySelector();
example/journey-1.json # Example 1;
example/journey-2.json # Example 2;
layout.js
— <svg ...>
— GitHub: IET-OU/our-journey index.html
Ta,
Nick
See pull request ~ #21.
Completed around 11-12 July!
N.
Hi @TimCoughlan,
At the moment there is one large JS file ~ 450 lines. I don't know how much more it will grow, but would you consider breaking it into a number of smaller Javascript files?
For example, one for file read-write (I like what you've done there Btw ;)), one to manage the assets/ image file-paths, one to handle browser compatibility ...?
We could potentially then build a single file using a tool like Browserify. (There are other tools, like Webpack ... I'm most familiar with Browserify.)
Benefits of using such a tool:
window.our_journey
with functions on it, not lots of global functions(!)require()
in the browser to re-use code;Dis-advantages from your point-of-view:
If you want to get a feel, I've used Browserify for gaad-widget,
Something to discuss ...?
Nick