A wrapper class that allows optional values to be passed to transformers without causing errors when the value is undefined.
The Maybe wrapper is typically used with the whenLoaded method to handle relationships that may or may not be loaded.
whenLoaded
class UserTransformer extends BaseTransformer<User> { toObject() { return { id: this.resource.id, profile: this.whenLoaded(this.resource.profile) // Returns Maybe<Profile> } }} Copy
class UserTransformer extends BaseTransformer<User> { toObject() { return { id: this.resource.id, profile: this.whenLoaded(this.resource.profile) // Returns Maybe<Profile> } }}
Creates a new Maybe wrapper for a value
The value to wrap, which may be undefined
const maybeUser = new Maybe(userData)const maybeUndefined = new Maybe(undefined) Copy
const maybeUser = new Maybe(userData)const maybeUndefined = new Maybe(undefined)
The wrapped value, which may be undefined
A wrapper class that allows optional values to be passed to transformers without causing errors when the value is undefined.
The Maybe wrapper is typically used with the
whenLoadedmethod to handle relationships that may or may not be loaded.