Actions

Actions provide a structured way to handle an action / mutation on the server. Once the action is completed any data changes are smoothly handled by refreshing the page data.


Create a new file in the @/plugins/custom/actions directory,

import defineAction from '@/lib/action/defineAction.js'

export default defineAction({
    id: 'upvotePost',
    resolve: async (ctx, { postId }) => {

        // find user in database

        // find post

        // register upvote for post + user
    }
})

Then within the @/plugins/custom/actions/index.js

import upvotePost from './upvotePost'

export default ([
    upvotePost
])

The actions are registered within @/plugins/custom/register.js

import definePlugin from '@/lib/module/definePlugin'
import actions from './actions'

export default definePlugin({
    actions,
})

Roadmap

  • Ability to define actions at the Page Type level, which encapsulates them. Global level actions are preferrable in many cases.