Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

javascript - 在另一个传奇中取消传奇(Cancel Saga within another saga)

I have a purchase cancel process, where a user can cancel it's purchase within 30 minutes after purchase.

(我有一个购买取消流程,用户可以在购买后30分钟内取消购买。)

Imagine that the cancellation form is quite long, and the user has to traverse throughout multiple screens in order to successfully cancel it's order.

(想象一下,取消表单相当长,用户必须遍历多个屏幕才能成功取消订单。)

Presumably, the cancellation window can be closed, in the middle of the "paperwork" fulfillment.

(据推测,取消窗口可以在“文书工作”执行的中间关闭。)

When that window closes, I have to send the user to the order detail screen.

(当该窗口关闭时,我必须将用户发送到订单详细信息屏幕。)

What I came up with: When the user loads the order detail screen, I'll verify if the cancellation is available.

(我想到的是:当用户加载订单详细信息屏幕时,我将验证取消是否可用。)

If so, I will present the possibility of cancellation.

(如果是这样,我将提出取消的可能性。)

And I'll also create a saga, to "subscribe" to the end of the window (I have that value on my API).

(而且我还将创建一个传奇,“订阅”窗口的末尾(我的API上具有该值)。)

When that window ends, it'll dispatch an action that will bring me back to the order detail screen.

(当该窗口结束时,它将调度一个操作,该操作会将我带回到订单详细信息屏幕。)

What I need to know, is how to cancel the "subscribe" saga.

(我需要知道的是如何取消“订阅”传奇。)

OrderScreen.jsx :

(OrderScreen.jsx :)

class OrderScreen extends Component {

  componentDidMount() {
    dispatch(subscribeToOrderCancelProcess())
  }

  ...
}

saga.js :

(saga.js :)

function* cancelPurchase({ payload }) {
  const { response } = yield call(fetchCancelPurchase, { id: payload.id })

  if (response) {
    // cancel subscribeToCancelProcess saga!
  }

}

function* subscribeToCancelProcess() {
  yield call(delay, TIME_UNTIL_CANCEL_WINDOW_CLOSES)
  // pushToOrderScreen
}

I tried to use takeLatest(SUBSCRIBE_PATTERN, subscribeToCancelProcess) and it seemed to work, but I'm not sure if that would be a good use of takeLatest .

(我试图使用takeLatest(SUBSCRIBE_PATTERN, subscribeToCancelProcess) ,它似乎可以工作,但是我不确定那是否可以很好地使用takeLatest 。)

  ask by rnarcos translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...