I have a module that I use to interactively make changes to widgets in my notebook:
define(["jquery", "lib/jquery.awesome-cursor.min"], function($) {
return {
paintRed: function() {
$('.chiSqValues').awesomeCursor('paint-brush', {
color: 'red',
hotspot: 'center'
});
$('.addEffectButton').addClass('redBorder')
}
}
});
I tried putting
display(Javascript('''
require(["models/chiSq"], function(chiSq) {
chiSq.paintRed()
});
'''))
in the parts of my python code where I wanted the change to occur, only to discover that require is only called once. I have seen suggested here to create a global variable for the module.
require(['models/chiSq'], function(chiSq){
window.chiSq = chiSq;
});
but as was noted in the comments, this is hacky and pollutes the global namespace.
Reguardless, I need to be able to call my module throughout my application based on certain events, and my module has important dependencies. What is the best practice for this kind of situation?