[Sugar-devel] sugar-web - How to load non-AMD js modules / libs?

Code iraguet at activitycentral.com
Thu Nov 7 14:09:43 EST 2013


There is a pull-request with this. Feedback and suggestions are welcome.

Thanks,
Code


On Tue, Nov 5, 2013 at 4:47 PM, Manuel Quiñones <manuq at laptop.org> wrote:

> 2013/11/5 Code <iraguet at activitycentral.com>:
> >
> >
> >
> > On Mon, Nov 4, 2013 at 1:54 PM, Manuel Quiñones <manuq at laptop.org>
> wrote:
> >>
> >> 2013/11/4 Code <iraguet at activitycentral.com>:
> >> > I think this is off-topic...
> >> > BTW: perhaps you wanna see this thread from RequireJS' list where
> James
> >> > Burke (core developer of RequireJS lib) talks about these syntax
> forms.
> >> > If there is something realted to this to add, would u open a new
> thread,
> >> > please?
> >> >
> >> >
> >> > Getting back to the former topic (loading non-AMD modules):
> >> > There is another approach, require.config() calls are additive, so it
> is
> >> > possible to call config from other file than loader.js and require
> >> > merges
> >> > it.
> >> >
> >> > example of a require.config() from activity.js:
> >> > https://gist.github.com/code-sur/7305059  ...loader.js stills as it
> is
> >> > in
> >> > sugar-web-template
> >> >
> >> > pros:
> >> > * no need to modify loader.js
> >> > * some developers would set other requirejs options
> >> >
> >> > cons:
> >> > * whole config may spreads among many files
> >> >
> >> > The last "con" may be a "pro" if you want to clearly separete the
> >> > framework
> >> > config from the activity specific config
> >>
> >> Yeah.  I think it is up to the activity developer to choose one or the
> >> other.  The shim looks more prominent in RequireJS docs.
> >>
> >> Here is how I used the shim in Gears activity, just for reference:
> >> https://github.com/manuq/gears-activity/blob/master/js/loader.js
> >>
> >> By the way, I have talked with the developer of the lib involved,
> >> gearsketch, and he is happy if I provide a patch to make his code an
> >> AMD module.  In general I think its good to do this.
> >
> > +1
> > I think that this is the right path, too, but I'm thinking from the
> point of
> > view of an occasional activity developer how just wants to build-up an
> > activity with his/her daily web tools.
> > I want to ease the work of activity devs... if it is somewhat hard to do,
> > they won't build anything.
>
> Absolutely.
>
> > I'd like to write a very tiny paragraph at the doc under the title of
> "Using
> > other JavaScript libraries" that tells you where to put the shim config
> if
> > you have any non-AMD module.
>
> Good.  Feel free to add an explanation, and then just link the
> RequireJS documentation, as Daniel proposed.  Doesn't make sense to
> duplicate their docs.
>
> > Seems weird to ask for putting shim config at loader.js and a few lines
> > above in the doc says that you shouldn't touch that file.
>
> Well nothing is written in stone, we can change the lines above.  But
> we should keep them simple.  Their purpose is to answer the question:
> where should I put my JS code? And my HTML? And my CSS?
>
> So my proposal is around this patch:
>
> --- a/activity.md
> +++ b/activity.md
> @@ -59,10 +59,11 @@ In your new activity, you will find the following
> file structure:
>
>  * `css/activity.css` is where you add the styling of your activity.
>
> -Those are the files you'll modify.  The others are:
> +Those are the files you'll modify in most cases.  The others are:
>
>  * `js/loader.js` configures the libraries paths and loads your
> -  `js/activity.js`
> +  `js/activity.js` . You can add non-AMD libraries here (FIXME link to
> +  section below for non-AMD libs).
>
>  * `lib/` contains the libraries
>
>
>
>
> Cheers,
>
> --
> .. manuq ..
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20131107/eaccff4b/attachment.html>


More information about the Sugar-devel mailing list