@rxx/core
Version:
React MVI micro framework.
61 lines (60 loc) • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var emptySubject = new rxjs_1.Subject();
var HandlerResponse = (function () {
function HandlerResponse(streamCollection) {
this.streamCollection = streamCollection;
}
HandlerResponse.prototype.for = function (key) {
if (!this.streamCollection.hasWithoutGlobal(key)) {
return this.streamCollection.add(key);
}
return this.streamCollection.getWithoutGlobal(key);
};
return HandlerResponse;
}());
exports.HandlerResponse = HandlerResponse;
var StreamStore = (function () {
function StreamStore(subjectMap) {
if (subjectMap === void 0) { subjectMap = {}; }
this.subjectMap = subjectMap;
}
StreamStore.prototype.hasWithoutGlobal = function (key) {
return !!this.subjectMap[key];
};
StreamStore.prototype.has = function (key) {
return this.get(key).length > 0;
};
StreamStore.prototype.getWithoutGlobal = function (key) {
if (this.subjectMap[key]) {
return this.subjectMap[key];
}
return emptySubject;
};
StreamStore.prototype.get = function (keySpace, create) {
var _this = this;
if (create === void 0) { create = false; }
var ret = [];
var _a = keySpace.split('::'), ns = _a[0], key = _a[1];
var globalKeys = ["*::" + key, ns + "::*"];
var globalBus = globalKeys
.filter(function (key) { return !!_this.subjectMap[key]; })
.map(function (key) { return _this.subjectMap[key]; });
if (this.subjectMap[keySpace]) {
ret.push(this.subjectMap[keySpace]);
}
else if (create) {
ret.push(this.add(keySpace));
}
if (globalBus.length) {
return ret.concat(globalBus);
}
return ret;
};
StreamStore.prototype.add = function (key) {
return (this.subjectMap[key] = new rxjs_1.Subject());
};
return StreamStore;
}());
exports.StreamStore = StreamStore;