UNPKG

@ofzza/entt-rxjs

Version:

RxJS compatible extension of enTT - a modular TypeScript data-modeling solution

43 lines 1.5 kB
"use strict"; // enTT RxJS lib main, extensible class // ---------------------------------------------------------------------------- Object.defineProperty(exports, "__esModule", { value: true }); exports.cast = exports.EnTT = void 0; // Import dependencies const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const entt_1 = require("@ofzza/entt"); /** * Main, extensible EnTT class definition */ class EnTT extends entt_1.EnTT { // Implementation static cast(value, { into = undefined, type = 'object', validate = true } = {}) { // using @Serializable // Return observable of cast, resolved value if (value instanceof rxjs_1.Observable) { // Pipe observable through a casting transformation return value.pipe(operators_1.map(value => { return entt_1.EnTT.cast.bind(this)(value, { into, type, validate }); })); } // Cast value using base EnTT class else { return entt_1.EnTT.cast.bind(this)(value, { into, type, validate }); } } /** * Creates an extended instance of EnTT. */ constructor() { super(); super.entt(); } } exports.EnTT = EnTT; function cast(into, type = 'object', validate = true) { // tslint:disable-next-line: only-arrow-functions return rxjs_1.pipe(operators_1.map(value => EnTT.cast(value, { into, type, validate }))); } exports.cast = cast; //# sourceMappingURL=index.js.map