tarant-utils
    TypeScript icon, indicating that this package has built-in type declarations

    0.3.66 • Public • Published

    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

    Install

    npm i tarant-utils

    DownloadsWeekly Downloads

    1

    Version

    0.3.66

    License

    MIT

    Unpacked Size

    13.1 kB

    Total Files

    16

    Last publish

    Collaborators

    • kanekotic