1.0.0 • Published 3 years ago

@actorize/core v1.0.0

Weekly downloads
19
License
MIT
Repository
github
Last release
3 years ago

@actorize/core

gzip size

Getting Started

$ npm install @actorize/core
# or
$ yarn add @actorize/core
import {
  createDirector,
  createStore,
} from '@actorize/core';

const director = createDirector({
  store: createStore(),
});

const actorOne = director.registerActor('one');
actorOne.onMessage((msgs) => {
  if (msgs[0].payload === 'DO_SOMETHING') {
    console.log('I DID SOMETHING');
  }
});

const actorTwo = director.registerActor('two');
actorTwo.sendMessage('one', 'DO_SOMETHING');

Plugin System

the most basic plugin is the logging plugin. This can be helpful to see when what actor send what.

import { createDirector, createStore, createLogPlugin } from '@actorize/core'

 // logs into 'debug' with "[ACTORIZE] ({{sender}}) => ({{recipient}}), {{payload}}"
const logPlugin = createLogPlugin()

// you have the option to filter too.
// this would only log messages from the actor named "ui"
// createLogPlugin({ filter: (msg) => msg.sender === 'ui'  })

const director = createDirector({
  store: createStore(),
  plugins: [logPlugin]
})

A plugin in general can be used to transform messages before they are saved to the store too. At the moment it just as options for onMessage which gets a Message and has to return a Message. The Typescript interface for the Plugin is

interface ActorizePlugin {
  onMessage?: (msg: Message) => Message,
}
1.0.0

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.5

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.4

3 years ago

0.0.1

3 years ago