Create a file named plugins/decimal-payload.ts
and copy+paste the code.
The definePayloadReducer
function is invoked for each nested object.
In JavaScript, the &&
operator evaluates the expression and returns the rightmost truthy value. Decimal.isDecimal(data)
evaluates to false
when false
, otherwise the expression continues and returns the value data.toJSON()
.
definePayloadReviver
is easier to understand, data
is what you have return from the previous function, any value you return gonna be used in it's place instead.
The official documentation: