The Actor
class is the parent class of most @fabric/core
components; you
can use it for any Fabric-enabled application.
The Actor
is the basis for most, if not all, native types in the Fabric Compute Space. It is an EventEmitter
and will typically emit the following events:
message
debug
log
warning
error
Some Actor types (such as Service
) also provide beat
, tick
, or state
events.
The Actor
is a standard ECMAScript object with the following properties:
id: String
state: Object
Interacting with a Fabric Actor:
// Use `npm i @fabric/core` first
const Actor = require('@fabric/core/types/actor');
const actor = new Actor({ foo: 'bar' });
// Listen for events
actor.on('message', (message) => {
console.log('Message from Actor:', message);
});
// Adopt a set of changes
actor.adopt([
{ op: 'replace', path: '/baz', value: 'plop' }
]);
console.log('My Actor:', JSON.stringify(actor, null, ' '));
Output:
My Actor: {
"foo": "bar",
"baz": "bop"
}