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 tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
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/acb606b3-f6de-46e5-a392-8b05970ec526%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to