apiref
ride@2.0.1

ride.wrap()  Function

Calls the wrapper function instead of the original function. The wrapper function is passed a function that can invoke the original function with the original arguments.

Signature

function wrap<T, A extends any[], R>(wrapper: (this: T, wrapped: () => R, ...args: A) => R): Decorator<T, (this: T, ...args: A) => R>;

Example

ride(test, 'deletePost', ride.wrap(function(wrapped, postId) {
  if (this.user.owns(postId)) {
    return wrapped()
  } else {
    throw new Error('No, you can\'t do that!')
  }
})

Parameters

ParameterTypeDescription
wrapper(this: T, wrapped: () => R, ...args: A) => R

The function that will be called instead of the original function. The first parameter passed to the wrapper function is a function that will call the original function with the original arguments and return its result.

(Returns)Decorator<T, (this: T, ...args: A) => R>