Skip to main content

Custom Operation

Interface definition

const action = Tingyun.newAction(options);

Parameters

  • options: Operation configuration item object.
    • name: operation name. String type. required.
    • context: additional data included in the operation. Object type. Optional.

Return object

Returns the operation object action, which can be used to end the operation. The action object contains the following functions.

  • end: End the operation.

    action.end(options);
    • options: End the operation configuration object. Optional.
      • context: additional data included in the operation. Object type. Optional.
      • status: Set the operation status success or fail, the default is success. String type. Optional.
  • fail: End the operation in a failed state (end sets status to the abbreviation of fail).

    action.fail(options);
    • options: End the operation configuration object. Optional.
      • context: additional data included in the operation. Object type. Optional.

Example

Simulate order submission operation.

import Tingyun from '../agent/init';

Page({
data: {
order: {}
},
// Submit order callback
submitOrder() {
// Create submit order operation
const action = Tingyun.newAction({
name: 'submit order',
context: {
orderId: this.order.id
}
});
wx.request({
url: SUBMIT_ORDER_URL,
success() {
// Successful operation
action.end();
},
fail(res) {
// operation failed
action.fail({
context: {
errMsg: res.errMsg
}
});
}
})
}
})