@state-sync/redux-path-reducer
Version:
state-sync client only json path reducer
80 lines (79 loc) • 2.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var SyncAreaRegistry = /** @class */ (function () {
function SyncAreaRegistry() {
this.areas = {};
}
SyncAreaRegistry.prototype.add = function (area) {
if (this.areas[area.name]) {
throw new Error("Sync area redeclaration " + area.name);
}
this.areas[area.name] = area;
};
SyncAreaRegistry.prototype.get = function (name) {
return this.areas[name];
};
SyncAreaRegistry.prototype.forEach = function (callback) {
for (var key in this.areas) {
callback(this.areas[key]);
}
};
SyncAreaRegistry.prototype.onEvent = function (event) {
switch (event.type) {
// sync
case 's':
return this.onPatchAreaResponse(event);
case 'p':
return this.onPatchAreaEvent(event);
case 'patchAreaError':
return this.onPatchAreaError(event);
// init & configure
case 'init':
return this.onInit(event);
// signals
case 'signalResponse':
return this.onSignalResponse(event);
case 'signalError':
return this.onSignalError(event);
// area subscription
case 'areaSubscriptionError':
return this.onSubscribeAreaError(event);
case 'areaSubscription':
return this.onSubscribeAreaResponse(event);
case 'areaUnsubscription':
return this.onUnsubscribeAreaResponse(event);
}
};
SyncAreaRegistry.prototype.onInit = function (event) {
return;
};
SyncAreaRegistry.prototype.onPatchAreaResponse = function (event) {
this.areas[event.area].onPatchResponse(event);
};
SyncAreaRegistry.prototype.onPatchAreaEvent = function (event) {
this.areas[event.area].onServerPatch(event);
};
SyncAreaRegistry.prototype.onSubscribeAreaResponse = function (event) {
this.areas[event.area].onSubscribe(event);
};
SyncAreaRegistry.prototype.onUnsubscribeAreaResponse = function (event) {
this.areas[event.area].onUnsubscribe(event);
};
// errors
SyncAreaRegistry.prototype.onPatchAreaError = function (event) {
this.areas[event.area].onPatchAreaError(event);
console.error(event);
};
SyncAreaRegistry.prototype.onSubscribeAreaError = function (event) {
this.areas[event.area].onSubscribeError(event);
console.error(event);
};
SyncAreaRegistry.prototype.onSignalResponse = function (event) {
this.areas[event.area].onSignalResponse(event);
};
SyncAreaRegistry.prototype.onSignalError = function (event) {
this.areas[event.area].onSignalError(event);
};
return SyncAreaRegistry;
}());
exports.default = SyncAreaRegistry;