Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: create service folder #3310

Open
Tracked by #3311
petersopko opened this issue Jun 30, 2022 · 2 comments
Open
Tracked by #3311

Refactor: create service folder #3310

petersopko opened this issue Jun 30, 2022 · 2 comments
Labels
A-refactoring Refactoring stuff, make code more readable, mitigating tech debt

Comments

@petersopko
Copy link
Contributor

following from @roiLeo comment here:

Here's the original comment:

  • create a service folder in order to organise all the actions (vuex actions -> service call)

I'd like to ask @roiLeo to provide additional information here if possible, I'm out of my depth with regards to services

@petersopko petersopko added the A-refactoring Refactoring stuff, make code more readable, mitigating tech debt label Jun 30, 2022
@petersopko petersopko mentioned this issue Jun 30, 2022
20 tasks
@roiLeo
Copy link
Contributor

roiLeo commented Jun 30, 2022

Let's take the example of user identity (from store),
on fetchIdentity action I would call let's say fetchIdentity method from IdentityService.

  async fetchIdentity({ dispatch }: any, address: string) {
    const { api } = Connector.getInstance()
    try {
      const optionIdentity = await api?.isReady.then((a) =>
        a?.query.identity?.identityOf(address)
      )
      const identity = optionIdentity?.unwrapOr(null)
      if (identity) {
        dispatch('setIdentity', { address, identity })
      }
    } catch (e) {
      consola.error('[FETCH IDENTITY] Unable to get identity', e)
    }
  },

become something like

  [FETCH_USER_IDENTITY]: async ({ commit }, address) => {
    const res = await IdentityService.fetchIdentity(address)
    commit(SET_USER_IDENTITY, res)
  },

services folder is used to make/wrap all api calls.
I find this pattern more readable and easier to maintain.

@vikiival
Copy link
Member

vikiival commented Jul 7, 2022

Next candidate for refactor:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-refactoring Refactoring stuff, make code more readable, mitigating tech debt
Projects
Status: No status
Development

No branches or pull requests

3 participants