JSFiddle - React, Tailwind, and code Playground
by TeslaNick
HTML
<script src="https://raw.github.com/gist/2581527/817311eb1f9e0f13ba423825378490bb21fc5e8e/migration.js"></script>
JavaScript
var migrate = new Migration({
version: '0.0.0.0',
name: 'My Migration',
migrate: function() {
var that = this;
// this.do - Returns a scope-corrected function, so you can continue to use `this` without
// doing any hacks like "that = this". For example:
//
// db.Appointment.find().forEach(this.do(function(result) { this.log(result); });
//
this.do(function(arg1) {
console.log(this === that);
console.log(arg1 === "foo");
})("foo");
// this.try - Catches unanticipated errors and continues running the script. Use with
// caution!!! Behaves like this.do, but will continue to execute even if an error is
// raised within the callback.
//
this.try (function(arg1) {
console.log(this === that);
console.log(arg1 === "foo");
})("foo");
// For example, we don't need to wrap this call in a try block. We catch the exception
// and log it transparently.
//
this.try (function(arg1) {
throw "FAILURE";
})("foo");
// Again, this code will raise an exception that will be caught and logged.
//
this.try (function() {
fake.foo.faz = fab;
})();
// Here, we are calling this.fail, which flows up to the parent scope. The original
// message is passed along as well.
//
try {
this.try (function(arg1) {
this.fail("Something really bad happened.");
})("foo");
} catch (e) {
console.log("ERROR: Something really bad happened.");
console.log(e);
}
// Here, we're catching a reference error inside our code, and explicitly throwing
// it up to the parent context.
//
try {
this.try (function(arg1) {
try {
fake.foo.faz = fab ...