react-dnd
Version:
Drag and Drop for React
53 lines • 2.08 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable max-classes-per-file
var isFunction_1 = __importDefault(require("lodash/isFunction"));
var noop_1 = __importDefault(require("lodash/noop"));
/**
* Provides a set of static methods for creating Disposables.
* @param {Function} action Action to run during the first call to dispose.
* The action is guaranteed to be run at most once.
*/
var Disposable = /** @class */ (function () {
function Disposable(action) {
this.isDisposed = false;
this.action = isFunction_1.default(action) ? action : noop_1.default;
}
/**
* Validates whether the given object is a disposable
* @param {Object} Object to test whether it has a dispose method
* @returns {Boolean} true if a disposable object, else false.
*/
Disposable.isDisposable = function (d) {
return d && isFunction_1.default(d.dispose);
};
Disposable._fixup = function (result) {
return Disposable.isDisposable(result) ? result : Disposable.empty;
};
/**
* Creates a disposable object that invokes the specified action when disposed.
* @param {Function} dispose Action to run during the first call to dispose.
* The action is guaranteed to be run at most once.
* @return {Disposable} The disposable object that runs the given action upon disposal.
*/
Disposable.create = function (action) {
return new Disposable(action);
};
/** Performs the task of cleaning up resources. */
Disposable.prototype.dispose = function () {
if (!this.isDisposed) {
this.action();
this.isDisposed = true;
}
};
/**
* Gets the disposable that does nothing when disposed.
*/
Disposable.empty = { dispose: noop_1.default };
return Disposable;
}());
exports.Disposable = Disposable;
//# sourceMappingURL=Disposable.js.map