-
Notifications
You must be signed in to change notification settings - Fork 520
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
Proposal: switch to a real module system for better modular designs #245
Comments
Actually, I think that the concept of include() came from OPENSCAD so possibly this compatibility can be maintained via the JSCAD library. |
@z3dev true, but not sure if it can /should behave the same way : unlike Openscad we have a full programming language at our disposal :) |
Just my 2p after submitting the metaball PR above... This looks great (esp the common.js format for defining modules), but IMO simplicity (and it working easily on https://openjscad.org) is key. The majority of your users won't be Node.js devs, so asking them to submit to NPM will probably cut down the amount of submissions you get a lot. The great bonus of openjscad.org is it works in the browser, so asking for a full Node.js install just to submit code seems like a step backwards. While I mentioned Also, while I said about common.js above, having the ability to find someone's jscad object online and just |
Sorry for the late reply, I introduced Now that things we modular, it surely makes sense to adapt common ways, but keep |
Sorry, not sure how I missed that it's already there: https://en.wikibooks.org/wiki/OpenJSCAD_User_Guide#Including_Files Looking at the docs, include via URL isn't possible yet... Would it be possible to add it? It'd be amazingly handy for referencing a file on GitHub, Gist or similar. Obviously cross-origin could be a pain, but I think GitHub at least is ok from that point of view? |
@gfwilliams
Side notes:
|
@gfwilliams while adding loading from an URL is possible to add it relatively simply I really don't think it should be done : simplicity is good
|
hi @Spiritdude ! :) I am ok with keeping include as it is, but building upon its very fragile foundations seem like a bad idea for all the reasons above. |
btw I am also willing to provide a proof of concept for 'require-lite' functionality for demo purposes :) |
I'm still VERY new to OpenJSCAD so I don't know the historic reasons for The wiki says
In es6 for say cube.js: Essentially, I'll echo the "don't reinvent the wheel" arguments in this thread. |
Check out https://aframe.io/aframe-registry/ for inspiration regarding a repo of community modules. |
thanks a lot for the feedback @meta-meta ! Wow Btw I have seen a lot of users create module based code that gets 'flattened' down (ie something like browserify) for simple online use, so I think it is up to us to making the modules approachable even for non technical folks ? Ie a simple UI that could wrap up your current work as a reuseable package? (with optional github/npm publishing ?) I think we could re-use the |
As a follow up to this discussion, the newly relased pre alpha of jscad-desktop supports common.js code for jscad designs :) https://github.com/jscad/jscad-desktop/blob/master/src/core/scripLoading.js#L75 I think there might be a way to do something very similar in the browser, stay tuned! |
A bit of update on this front :
|
Any feature that allows either of the 2 options below is welcomed!
This would finally allow giving out URLs of objects you have made that uses lower level libraries, without requiring you to copy/paste the libraries into a single file, or forcing the use of node.js for the same task. |
@udif while I can understand the appeal of those options, I am honestly not sure if they are feasible at all without major hassles: (as always, contributions are very welcome !)
If you see solutions for this that do not require a specific backend, please post , we are really open to discussing these things and finding solutions about node.js : when I say node modules, I really mean the common.js syntax of require & imports : you could have a set of files containing / folders containing your different pieces of code without actually needing node.js itself : the main goal of the changes above is to move to a more sane management of reuseable code : it is no wonder pill that solves all issues, but at least we will stop doing hacky globals-insertions etc |
I do this kind of thing in the Espruino IDE - you can just do CORS can bite you, but 99% of the time people are linking to GitHub, and in that case we detect the URL and just use GitHub's API to access the file directly. |
Before I start, let me just state that I have zero experience as a web frontend/backend designer. I merely use Openjscad and pure Javascript to create 3D objects. @kaosat-dev regarding your points:
I just saw @gfwilliams answer before I posted mine - limiting loading from github would be more than enough for me. |
I think I just answered myself: |
Correct. There’s a small sever piece that happens behind the scene. With the require() approach, this piece (and CORS) is not required. |
@gfwilliams that is very interesting ! I took a look at the relevant Espruino docs , it is a nice solution ! :) Since dynamic |
@udif it is a bit more complicated then that , sadly
|
In Espruino, for
|
Seems to me that include() and mockImport() are the same, unless you can point out something significantly different. Trying to provide something that looks like import() proposal... and let’s see...
Umm... nothing there is easy. |
@gfwilliams thanks for the insights! pre-emptive loading works but can get a headache :) and adds complexity @z3dev they would not the same at all, one is sync, the other async : require() returns the exports of the given module, mockImport() would return a PROMISE of a module
but yes, all this is horribly complex (too many edge cases): this is why for now , my main goal it jus to have support for modules , how/when/if to load them is another layer of complexity on top :) (guess what? I managed to get node modules loading from the web drag & drop, and the crappy circular dependencies in CSG.js breaks stuff ... ) |
Cool! A little progress anyway. CSG.js.... working on that little by little. |
With the release of V2 JSCAD, this issue has been resolved as the Common.js (Node) method for require() has been adopted. This may be extended or changed in the future. Thanks all for the feedback! |
Curent system
Hi everyone ! right now we are using a custom and rather limited
include
system to enable modular design & part reuse, with a few major flaws:pros
cons
include()
are pushed to the global scopeProposal
The node.js & js ecosystem have been very successfully using modules for years, let's use that tech and knowledge to our advantage :
pros
(in addition to all the cons of the current system, which are all resolved in commonjs/es6 modules)
export: (coolPart.jscad)
import
cons
Of course this could be rolled out progressively, tested & tried, and would not need to impact the current implementation of include.
As you can likely see, I am quite passionate about the subject .
Any thoughts ?
The text was updated successfully, but these errors were encountered: