Closed Bug 572181 Opened 15 years ago Closed 15 years ago

Defining exports.main() in a main script should be optional

Categories

(Add-on SDK Graveyard :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: avarma, Assigned: avarma)

Details

Attachments

(1 file)

It occurred to me while planning the FlightDeck tutorial (bug 566261) that casual developers who just want to make simple addons, but not their own modules, shouldn't really even have to know what the "exports" object is. In fact, since the addon's main script is evaluated immediately before exports.main() is called, the whole notion of having to explicitly define exports.main() should be optional! In other words rather than hello world having to be: exports.main = function() { console.log("hello world"); } it should instead be even simpler: console.log("hello world"); of course, the former should still work too, for folks who actually know what exports and exports.main() is, and want to take advantage of it to modularize their code better. This philosophy is actually taken from Processing, where developers can do the same kind of thing. A patch for this should be real easy to implement.
+1!
OS: Mac OS X → All
Hardware: x86 → All
In fact, I've actually built a few working addons that stubbed exports.main and inlined what they needed to do. It'd be great not to have to stub exports.main for the simple cases. Besides making that exported function optional are there issues around the exact point in the application startup process at which main.js is parsed (relative to when exports.main is called) that need to be dealt with?
Nope, no other issues myk--this one-line patch should do the trick. I don't think this is very high-risk, personally, as all we're doing is treating the absence of 'exports.main' as a non-failure-condition. It'd make it easier for me to write the FlightDeck tutorial since I wouldn't have to explain what 'exports' is. More importantly, though, it means less stuff that can go wrong for the novice jetpack developer, improving developer ergonomics for a really early part of the learning process. I'd love to get this in to 0.5 if at all possible!
Attachment #451360 - Flags: review?(myk)
Assignee: nobody → avarma
Comment on attachment 451360 [details] [diff] [review] insanely trivial patch This looks great and indeed seems very low risk. r=myk
Attachment #451360 - Flags: review?(myk) → review+
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
The Add-on SDK is no longer a Mozilla Labs experiment and has become a big enough project to warrant its own Bugzilla product, so the "Add-on SDK" product has been created for it, and I am moving its bugs to that product. To filter bugmail related to this change, filter on the word "looptid".
Component: Jetpack SDK → General
Product: Mozilla Labs → Add-on SDK
QA Contact: jetpack-sdk → general
Version: Trunk → unspecified
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: