@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
79 lines • 2.64 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var connectible_1 = require("./connectible");
/**
*
* Represents the basic [pin](https://connective.dev/docs/pin) object.
* This pin type gets locked when its observable is realized,
* will resolve only when its observable is not realized and its resolution
* will be merged observable of all of the incoming pins' observables.
*
*/
var Pin = /** @class */ (function (_super) {
__extends(Pin, _super);
function Pin() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
*
* Determines if this pin is locked, based on whether or not its underlying
* observable has been resolved or not.
*
* @param observable
*
*/
Pin.prototype.isLocked = function (observable) {
return observable !== undefined;
};
/**
*
* Determines whether this pin should resolve its underlying observable,
* based on whether or not its underlying observable has been resolved or not.
*
* @param _
* @param observable
*
*/
Pin.prototype.shouldResolve = function (_, observable) {
return observable === undefined;
};
/**
*
* Resolves its underlying observable, by
* [mergeing](https://rxjs-dev.firebaseapp.com/api/index/function/merge)
* corresponding observables of inbound pins.
*
* @param inbound
*
*/
Pin.prototype.resolve = function (inbound) {
return (inbound.length == 1) ?
inbound[0].observable : rxjs_1.merge.apply(void 0, inbound.map(function (pin) { return pin.observable; }));
};
return Pin;
}(connectible_1.Connectible));
exports.Pin = Pin;
/**
*
* Creates a typical [pin](https://connective.dev/docs/pin) object.
* [Checkout the docs](https://connective.dev/docs/pin) for examples and further information.
*
*/
function pin() { return new Pin(); }
exports.pin = pin;
exports.default = pin;
//# sourceMappingURL=pin.js.map