Hi Devin,
my plugin modules end up like this:
( function ( module , exports , console , setInterval , clearInterval ,
setTimeout , clearTimeout , Buffer , $tw , require ) { ( function ( ) {
/*\
title: $:/core/modules/parsers/wikiparser/abstractwikiparser.js
type: application/javascript
module-type: global
base class- individual wikiparser inherit from this class
\*/
( function ( ) {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict" ;
var AbstrWikiParser = function ( specifier ) {
exports [ "AbstrWikiParser" ] = AbstrWikiParser ;
} ) ( ) ;
; } ) ( ) ;
return exports ;
} )
so it looks like the IIFE is redundent.
cheer
BJ
On Monday, January 11, 2016 at 1:01:10 AM UTC, Devin Weaver wrote:
>
> I was just curious about the use of IFE in the core plugins. Since using
> them as examples I felt the need to continue the style. However looking at
> how modules are handled in TiddlyWiki it seems that an IIFE might be
> redundant.
>
> For example:
>
> /*\
> title: $:/plugins/my-plugin/plugin.js
> type: application/javascript
> module-type: startup
>
> An example startup plugin
>
> \*/
> (function() {
>
> exports.startup = function startup() {
> // Do stuff
> }
>
> })();
>
> Since TiddlyWiki wraps code in a sandbox in order to manage the exports
> variable would it not be scoped in it's own *context*? Wouldn't this
> wrapping mean the (function() {…})() is redundant?
>
> This became a point of question for me while I was using Babel
> <https://babeljs.io/> which transpiles ES2015 (ES6) modules into CommonJS
> (which the TiddlyWiki code *mostly* emulates). But unlike CoffeeScript
> it's output doesn't warp inside an IIFE. This is because Babel assumes that
> the files it outputs will be bundled with a module system like Browserify
> or AMD. TittleWiki is that bundling system using it's sandbox to evaluate
> plugin tiddlers.
>
> For completeness the above code would look like this in ES2015:
>
> /*\
> title: $:/plugins/my-plugin/plugin.js
> type: application/javascript
> module-type: startup
>
> An example startup plugin
>
> \*/
> export function startup() {
> // Do stuff
> }
>
> Which outputs a file like:
>
> "use strict";
>
> Object.defineProperty(exports, "__esModule", {
> value: true
> });
> exports.startup = startup;
> /*\
> title: $:/plugins/my-plugin/plugin.js
> type: application/javascript
> module-type: startup
>
> An example startup plugin
>
> \*/
> function startup() {
> // Do stuff
> }
>
> So would this cause a startup function to be global? Or is the sandbox
> enough to prevent global pollution? And in the case of the later what is
> the benefit (if any) of wrapping the core code in IIFEs?
>
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/3c1d9e6a-0693-4c04-926d-527ac52dc98c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.