Skip to content

Instantly share code, notes, and snippets.

@Slashed
Created April 3, 2010 13:47
Show Gist options
  • Save Slashed/354490 to your computer and use it in GitHub Desktop.
Save Slashed/354490 to your computer and use it in GitHub Desktop.
var sys = require('sys');
var hotcode = require('./hotcode');
var exampleLib = hotcode.load('./example_lib');
sys.puts(exampleLib.Name); // Output: "John"
// ...e.g. some changes were made to file.
exampleLib = hotcode.load('./example_lib');
sys.puts(exampleLib.Name); // Output: "Victoria"
var sys = require('sys');
var hotcode = require('./hotcode');
// Auto hot code loading. Second argument is a callback with reference to exported functions.
var exampleLib = hotcode.load('./example_lib', function(obj) {
sys.puts('Reloading "example_lib"..');
exampleLib = obj;
});
var Msg = 'Name(or type "unwatch" to stop Auto Code Loading): ';
process.stdio.open();
sys.print(Msg);
process.stdio.addListener('data', function(data) {
data = data.trim();
if(data == 'unwatch') {
hotcode.unwatch('./example_lib');
} else { exampleLib.sayHello(data); }
sys.print(Msg);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment