tarant-utils

[![npm](https://img.shields.io/npm/v/tarant-utils.svg)](https://www.npmjs.com/package/tarant-utils) [![Build Status](https://travis-ci.org/tarantx/tarant-utils.svg?branch=master)](https://travis-ci.org/tarantx/tarant-utils) [![Coverage Status](https://cov

Usage no npm install needed!

<script type="module">
  import tarantUtils from 'https://cdn.skypack.dev/tarant-utils';
</script>

README

tarant-utils

npm Build Status Coverage Status PRs Welcome issues Welcome npm GitHub issues GitHub pull requests Downloads

Motivation

Provide a set of utils that help apply some of the paterns that tarant uses.

Installation

add it to your project using npm install tarant-utils --save or yarn add tarant-utils

Usage

Decorator

We recomend to use the decorator pattern to keaping separation of concerns in between the business logic of an actor and the logic that some of the resolvers and materializers require.

For example having the next actor


class AppActor extends Actor {

  constructor(name: string) {
      super(name)
  }

  public addOne() : void {
      this.counter++
  }

   public counter = 1; 
}

the definition of the serialization information could be done like

class SerializationDecorator extends decorator<AppActor> {
    constructor(actor: AppActor) {
        super(actor)
    }

    toJson() {
        return {
            id: this.actor.id,
            type: "AppActor",
            counter: this.actor.counter
        }
    }

    updateFrom({ counter }: any): void {
        this.actor.counter = counter
    }
}

and the mix the actor and the decorator for it to be resolved in the actor system that is registered

const DecoratedActor = decorate(AppActor, SerializationDecorator)
export default DecoratedActor
Created my free logo at LogoMakr.com