@ofzza/entt-rxjs

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

Usage no npm install needed!

<script type="module">
  import ofzzaEnttRxjs from 'https://cdn.skypack.dev/@ofzza/entt-rxjs';
</script>

README

enTT RxJS

enTT-RxJS is a RxJS compatible extension of enTT, read as "Entity" - an extensible TypeScript data-modeling solution with some of the typically required functionality, such as change-detection, easy import/export, composition/decomposition, data validation, etc., all available out of the box and easy to use.

Table of contents:

Get enTT-RxJS

To start using enTT-RxJS in your project, simply install it from NPM by running the following in your terminal:

> npm install @ofzza/entt-rxjs --save

Using enTT-RxJS

Usage of enTT-RxJS is nearly identical to enTT, so please read up on basic usage of enTT first! Covered here will be only what is different from the base enTT implementation ...

Cast accepts RxJS Observables

If passed a RxJS Observable, cast will return a piped Observable which will map any resolved value to a cast instance, in line with how the base enTT library works with Promises, like so:

EXAMPLE
import { EnTT } from '@ofzza/entt-rxjs';
import { Subject } from 'rxjs';

class MyPersonClass extends EnTT {
  constructor() {
    super();
    super.entt();
  }

  public firstName = undefined as string;
  public lastName = undefined as string;
}

const instance = new MyPersonClass();
instance.firstName = 'John';
instance.lastName = 'Doe';

const serialized = instance.serialize();
console.log(serialized); // Outputs: { firstName: "John", lastName: "Doe" }

const observable = new Subject(),
  castObservable = MyPersonClass.cast(observable, { target: MyPersonClass });
castObservable.subscribe(value => {
  console.log(value instanceof MyPersonClass); // Outputs: true
  console.log(value.firstName); // Outputs: "John"
  console.log(value.lastName); // Outputs: "Doe"
});
observable.next(serialized);
observable.complete();

Exposes RxJS "cast" operator to use with .pipe()

To cast a value as an EnTT in an RxJS pipe user the cast operator, like so:

EXAMPLE
import { EnTT, cast } from '@ofzza/entt-rxjs';
import { Subject } from 'rxjs';

class MyPersonClass extends EnTT {
  constructor() {
    super();
    super.entt();
  }

  public firstName = undefined as string;
  public lastName = undefined as string;
}

const instance = new MyPersonClass();
instance.firstName = 'John';
instance.lastName = 'Doe';

const serialized = instance.serialize();
console.log(serialized); // Outputs: { firstName: "John", lastName: "Doe" }

const observable = new Subject();
observable.pipe(cast(MyPersonClass)).subscribe(value => {
  console.log(value instanceof MyPersonClass); // Outputs: true
  console.log(value.firstName); // Outputs: "John"
  console.log(value.lastName); // Outputs: "Doe"
});
observable.next(serialized);
observable.complete();

Contributing

Reporting Issues

When reporting issues, please keep to provided templates.

Before reporting issues, please read: GitHub Work-Flow

Contributing Code

For work-flow and general etiquette when contributing, please see:

Please accompany any work, fix or feature with their own issue, in it's own branch (see Git Source-Control Work-Flow for branch naming conventions), and once done, request merge via pull request.

When creating issues and PRs, please keep to provided templates.