Function that will be executed after the property or class has been fully processed.
Optional
opt: Partial<PrePostOptions>Optional configution.
The class or property decorator function.
In the following example, the @Post
operator is used to store the value of
the property it decorate inside a global variable that will be accessed by other
part of the code. Currently, the library does not natively support shared
context functionality, this example demonstrates a workaround for achieving
similar behavior.
const GLOBAL_STORAGE = {}
// After the 'Record' class has been processed key-value will be stored
// in the 'GLOBAL_STORAGE' variable.
@Post(_ => { GLOBAL_STORAGE[_.key] = _.value })
class Record {
@NullTerminatedString
@Relation(PrimitiveSymbol.char)
key: string
@NullTerminatedString
@Relation(PrimitiveSymbol.char)
value: string
}
class SubProtocol {
...
constructor (key: string, value: string) {
...
}
}
class Protocol {
@Count(16)
@Relation(Records)
records: Record
// Map 'GLOBAL_STORAGE' to a [key, value] array and pass it to the
// SubProtocol constructor.
@MapTo(_ => Object.entries(GLOBAL_STORAGE))
@Relation(SubProtocol)
map:
}
@Post
decorator defines a function computed after fully reading or writing the value of the decorated property or class .It is typically used for post-processing tasks such as debugging, or to enforce custom constraints that the library cannot handle declaratively.