UNPKG

diffusion

Version:

Diffusion JavaScript client

71 lines (70 loc) 3.35 kB
"use strict"; 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.create = exports.WorkerValueStreamProxy = void 0; var value_stream_1 = require("./../../features/topics/value-stream"); var value_stream_proxy_1 = require("./../../features/topics/value-stream-proxy"); var selector_set_1 = require("./../../topics/selector-set"); var worker_value_stream_adapter_1 = require("./../../webworker/topics/worker-value-stream-adapter"); /** * Internal proxy for Subscriptions with an underlying datatype. */ var WorkerValueStreamProxy = /** @class */ (function (_super) { __extends(WorkerValueStreamProxy, _super); /** * Create a new ValueStreamProxy interface * * @param registry the stream registry * @param selector the topic selector * @param datatype the data type of the value stream * @param fallback whether this is a fallback stream or not */ function WorkerValueStreamProxy(registry, selector, datatype, fallback) { return _super.call(this, registry, selector, datatype, fallback, function (factory, topicSelector) { return new value_stream_1.ValueStreamImpl(factory, topicSelector); }, function (stream, streamDatatype, topicSpec) { return new worker_value_stream_adapter_1.WorkerValueStreamAdapter(stream, streamDatatype, topicSpec); }) || this; } /** * @inheritdoc */ WorkerValueStreamProxy.prototype.onDelta = function (path, specification, oldContent, newContent, delta, oldValue, newValue) { this.emitter.emit('value', path, specification, newContent, oldContent); }; /** * @inheritdoc */ WorkerValueStreamProxy.prototype.onValue = function (path, specification, oldContent, newContent, oldValue, newValue) { this.emitter.emit('value', path, specification, newContent, oldContent); }; return WorkerValueStreamProxy; }(value_stream_proxy_1.ValueStreamProxy)); exports.WorkerValueStreamProxy = WorkerValueStreamProxy; var FALLBACK_SELECTOR = new selector_set_1.SelectorSet([]); /** * Factory function for creating a new ValueStreamProxy interface * * @param registry the stream registry * @param selector the topic selector * @param datatype the data type of the value stream * @param fallback whether this is a fallback stream or not */ function create(registry, datatype, fallback, selector) { if (selector === void 0) { selector = FALLBACK_SELECTOR; } var proxy = new WorkerValueStreamProxy(registry, selector, datatype, fallback); return proxy.subscription; } exports.create = create;