Skip to content

Async/await proposal #16

Closed
Closed
@pavel-redkin

Description

@pavel-redkin

createPost ({commit}, message) {

Hi!
I would like to propose async/await approach.
There are some more lines of code and it looks more habitually (to me :) )

async/await version

actions: {
        async createPost ({commit}, message) {
            commit('CREATING_POST')
            try {
                const response = await PostAPI.create(message)
                commit('CREATING_POST_SUCCESS', response.data))
                return response.data
            } catch (err) {
                commit('CREATING_POST_ERROR', err)
                return null
            }
        },
      // ...
}

And some additional actions to make it work (async/await).

webpack.config.js

    .configureBabel(function(babelConfig) {
      babelConfig.plugins.push("@babel/plugin-transform-runtime");
    })

Babel 7

$ yarn add -D @babel/plugin-transform-runtime
$ yarn add -D @babel/runtime

package.json

{
 ...
    "browserslist": [
        "> 0.5%",
        "last 2 versions",
        "Firefox ESR",
        "not dead"
    ]
 ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions