decent-bet/vuex-connex-entities

@MapCallResponse - Design pattern

Opened this issue · 0 comments

A LogResponseWatcher is a design pattern found where

  • A write call is made
  • A log event response must wait for n block confirmation
  • Response is match by id, given a connex-entities AccountEventFilter filter or a Connex filter
  • Decoded args are read and handle by action, which commits to store.

Proposal

@MapCallResponse({
  entity: MessageContract,
  map: 'sendMessageToUser',
  watch: 'logSendMessageToUser$'
})
public sendMessageToUser(arg1, arg2) {
  return (commit, params) => commit('MESSAGE_SENT', params.confirmation)
}

Decorator generates following

    try {
      const quest = getContract(MessageContract);

      // Write
      const resp = await quest.sendMessageToUser(arg1, arg2);

      const logs: any = await quest.logSendMessageToUser$([]);
      const subscription = logs
        .subscribe((i: any) => {
          // decoded.id
          const log = i.filter(j => j.meta.txID === resp.txid);
          if (log.length > 0) {
            console.log(log);
            thunk(commit, log[0].decoded);
            subscription.unsubscribe();
          }
          // eslint-disable-next-line vue/script-indent
        });
    } catch (error) {
      throw error;
    }