vuex-observable-actions
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

vuex-observable-actions

This is a vuex plugin that allows you to write actions with experience of redux-observerble, where you can manage side effects in rxjs paradigm.

Installation

npm i vuex-observable-actions

Usage

import { createStore } from 'vuex';
import VuexObservableActions from 'vuex-observable-actions';

const epics = {
  increment: (action$, { state }) => {
    return action$.pipe(
      map(() => ({
        type: 'SET_COUNT',
        payload: state.count + 1,
      }))
    );
  },
};

const store = new createStore({
  state,
  mutations,
  ...,
  plugins: [VuexObservableActions(epics)],
});

Configuration

you can add global handler to subscribe all the actions that you registered to epics, such as common behavior or putting some logs like:

...

const store = new createStore({
  state,
  mutations,
  ...,
  plugins: [VuexObservableActions(epics, {
    onActionStarted: ({ type }) => {
        store.commit('SHOW_LOADING_OVERLAY')
        reportLog(`Action '${type}' get triggered`)
    },
    onActionFinished: ({ type }) => {
        store.commit('HIDE_LOADING_OVERLAY')
        reportLog(`Mutation '${type}' get triggered`)
    },
  })],
});

Package Sidebar

Install

npm i vuex-observable-actions

Weekly Downloads

3

Version

0.0.7

License

MIT

Unpacked Size

16.8 kB

Total Files

9

Last publish

Collaborators

  • susanne.liu