Class: Message<T>
Message is a message that can be sent along the event bus to subscribers. Message has a generic type payload for passing more data than just the message type.
Type parameters
Name |
---|
T |
Hierarchy
-
↳ Message
Implements
Table of contents
Constructors
Properties
Methods
Constructors
constructor
+ new Message<T>(type
: string, payload?
: T): Message<T>
Type parameters:
Name |
---|
T |
Parameters:
Name | Type |
---|---|
type |
string |
payload? |
T |
Returns: Message<T>
Inherited from: Pooled
Properties
objectInPool
• objectInPool: boolean= false
objectInPool is true if an object is made available in the object pool. If it is false it is not currently available in the object pool. This is used to avoid adding the same object to the same object pool multiple times if there are successive calls to free the the same object.
Implementation of: IPoolable.objectInPool
Inherited from: Pooled.objectInPool
payload
• Optional
payload: undefined | T
type
• type: string
Implementation of: IMessage.type
CLASS_SERIALIZATION_KEY
▪ Readonly
Static
CLASS_SERIALIZATION_KEY: jamjar.Message= "jamjar.Message"
pools
▪ Protected
Static
pools: Map<string, [number, IPoolable[]]>
pools is the global, static mapping of string keys to object pools. An object pool contains two pieces of data, the maximum size of the pool (first value), and the objects that make up the pool as an array (second value).
Methods
Free
▸ Free(): void
Free releases an object or it's constituent parts back into any available object pools.
Returns: void
Implementation of: IPoolable
Recycle
▸ Recycle(type
: string, payload?
: T): IPoolable
Parameters:
Name | Type |
---|---|
type |
string |
payload? |
T |
Returns: IPoolable
Serialize
▸ Serialize(): string
Returns: string
Implementation of: ISerializable
Deserialize
▸ Static
Deserialize(json
: any): Message<unknown>
Parameters:
Name | Type |
---|---|
json |
any |
Returns: Message<unknown>
Free
▸ Static
Free<T>(obj
: Message<T>): void
Free the provided Message.
Type parameters:
Name |
---|
T |
Parameters:
Name | Type |
---|---|
obj |
Message<T> |
Returns: void
Init
▸ Static
Init(size
: number): void
Initialize the Message pool to the size provided.
Parameters:
Name | Type |
---|---|
size |
number |
Returns: void
New
▸ Static
New<T>(type
: string, payload?
: T): Message<T>
Create a Message.New, using pooling if available.
Type parameters:
Name |
---|
T |
Parameters:
Name | Type |
---|---|
type |
string |
payload? |
T |
Returns: Message<T>
free
▸ Protected
Static
free(poolKey
: string, obj
: IPoolable): void
free is used to mark a provided object as free in the pool provided. This method can be called multiple times with the same object, it will only add one entry to the pool.
Parameters:
Name | Type | Description |
---|---|---|
poolKey |
string | The key of the pool to add the object to. |
obj |
IPoolable | The object to add to the pool. |
Returns: void
Inherited from: Pooled
init
▸ Protected
Static
init(poolKey
: string, emptyGenerator
: () => IPoolable, size
: number): void
init is used to initialize an object pool to a certain size. This method takes a key of the pool to initialize, an 'empty generator' which is a function that should return an empty/blank instance of the object being pooled which can be overwritten at a later point, and the maximum size of the pool (which it will be initialized to at the start using the empty generator).
Parameters:
Name | Type |
---|---|
poolKey |
string |
emptyGenerator |
() => IPoolable |
size |
number |
Returns: void
Inherited from: Pooled
new
▸ Protected
Static
newpoolKey
: *string*, type
: (...args
: *any*) => T, ...args
: any): T
new is used to request a new object from the pool specified, if the pool is unavailable or empty it will use the type to provision a new object through a constructor. This is a generic method, it includes a cast to the generic type provided - this cast can fail if the objects returned from the pool are not the type expected.
Type parameters:
Name | Type |
---|---|
T |
IPoolable |
Parameters:
Name | Type | Description |
---|---|---|
poolKey |
string | The key of the pool to retrieve from. |
type |
(...args : any) => T |
The fallback constructor to use if the pool is not initialized/empty. |
...args |
any | The args to use when creating/recycling the object. |
Returns: T
Inherited from: Pooled