Are tw module closures redundant?

131 views
Skip to first unread message

Felix Küppers

unread,
Jan 12, 2016, 10:13:26 AM1/12/16
to tiddly...@googlegroups.com
Continued discussion started by Devin from: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/tiddlywiki/N7tXELs9z6k/_Of0R3LbDgAJ

Intro:

While a poll in the tw community reveiled "warm feelings" in connection to additional closures – and there are rumors about a study that supports this empirical finding – the question is whether they are actually redundant.

Quote from Devin's source (http://nodejs.org/api/modules.html#modules_modules):

Variables local to the module will be private, as though the module was wrapped in a function


Devin Weaver

unread,
Jan 12, 2016, 1:02:04 PM1/12/16
to TiddlyWikiDev
Thinking about this I bet that TW is bypassing the Node resolver which means it is loosing the private context. Though if that were the case then perhaps there is a way to manage the TW resolver better so the IIFE was not required for every developer to remember. Especially since placing IIFE in Node.js code is considered bad practice.

BJ

unread,
Jan 12, 2016, 5:51:04 PM1/12/16
to TiddlyWikiDev
I can't see how code could be compiled apart from thru the action of boot.js, and in that case vm.runInNewContext(code,sandbox,filename) is run and the code has the sandbox as a global object. What does ' bypassing the Node resolver' mean?

Nathan Cain

unread,
Jan 12, 2016, 10:47:21 PM1/12/16
to TiddlyWikiDev
If I recall, the IIFE wrap was once relevant in the very early days of the TW5 alpha, way back when the UI was bright red. It is no longer necessary, but is still arguably a good practice.

Devin Weaver

unread,
Jan 13, 2016, 12:52:12 PM1/13/16
to TiddlyWikiDev

On Tuesday, January 12, 2016 at 5:51:04 PM UTC-5, BJ wrote:
What does ' bypassing the Node resolver' mean?

I made an assumption since Node.js uses file paths to resolve modules while TW uses tiddler titles to resolve modules. And so I thought TW was implementing it's own module system and not relying on Node.js to resolve the require() statements.

Tobias Beer

unread,
Jan 13, 2016, 1:33:18 PM1/13/16
to TiddlyWikiDev
Hi,
 
What does ' bypassing the Node resolver' mean?

I made an assumption since Node.js uses file paths to resolve modules while TW uses tiddler titles to resolve modules. And so I thought TW was implementing it's own module system and not relying on Node.js to resolve the require() statements.

I think you're right. At least that's how I would interpret $tw.modules.execute().

Best wishes,

Tobias. 

BJ

unread,
Jan 13, 2016, 6:24:56 PM1/13/16
to TiddlyWikiDev
Ah, yes. I like the tw modules, the module metadata give rise to interesting possibilities with functions such as  $tw.modules.getModulesByTypeAsHashmap() etc.

Danielo Rodríguez

unread,
Sep 3, 2016, 12:58:09 PM9/3/16
to TiddlyWikiDev
I come here looking for answers and I didn't find any!

Is the IIFE redundant or not?
I would love to get rid of them.

Regards

BJ

unread,
Sep 5, 2016, 7:03:25 AM9/5/16
to TiddlyWikiDev
yes

Danielo Rodríguez

unread,
Sep 5, 2016, 8:17:23 AM9/5/16
to TiddlyWikiDev


El lunes, 5 de septiembre de 2016, 13:03:25 (UTC+2), BJ escribió:
yes

But then what was Jeremy referring to when he wrote:

The reason for the apparently unnecessary IFE is so that the same .js files can be require()'d by regular Node.js code.

Seems that there is some reasoning (or at least one situation) that makes them necessary.

Regards

 

BJ

unread,
Sep 5, 2016, 5:06:23 PM9/5/16
to TiddlyWikiDev
I think he meant the regular node.js 'require', but actually this does not need iife either see:
http://stackoverflow.com/questions/21531329/are-node-js-modules-need-to-be-wrapped-inside-the-module-pattern

Danielo Rodríguez

unread,
Sep 5, 2016, 5:49:24 PM9/5/16
to TiddlyWikiDev
I know that, I'm a node JS developer. That's why I don't understand Jeremy's concern, because I know that IIFE does not make sense in node neither
Reply all
Reply to author
Forward
0 new messages