JSPM

vuex-magic-class

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q41020F
  • License MIT

Vuex magic class helps to get vuex function in your object

Package Exports

  • vuex-magic-class

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vuex-magic-class) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

#Import vuex store

####import state from 'admin/store';

import vuex from 'vuex-magic-class';
vuex(this, {
    name: 'note', //namespace
    state,
    dispatch: [
        'createNote',
        'updateNote'
    ],
    commit: [
        'updateState'
    ],
});

#Example

import vuex from 'vuex-magic-class';
import state from 'admin/store';

export default class Note {

    constructor(instance) {
        
        vuex(this, {
            name: 'note', //namespace
            state,
            dispatch: [
                'createNote',
                'updateNote'
            ],
            commit: [
                'updateState'
            ],
        });
    }

    create() {
        this.createNote(data);
    }

    update() {
        this.dispatch('note/updateNote', data);
        this.commit('note/updateState', data);
    }
}



# Initiate Multiple module Function
export default class Note {

    constructor(instance) {
        
        vuex(this, {
           state : vuexStore
           modules : [
               {
                   name: 'website',
                   dispatch: [
                       'createNote'
                   ]
               },
               {
                   name: 'loading',
                   dispatch: [
                       'loading',
                       'loadingComplete',
                   ],
               }
           ]
        });
    }

    create(data) {
        this.loading();
        this.createNote(data);
        this.loadingComplete();
    }

    update(data) {
        this.dispatch('note/updateNote', data);
        this.commit('note/updateState', data);
    }
}

# Without namespace Just remove name if you dont need namespace
export default class Note {

    constructor(instance) {
        
        vuex(this, {
           state : vuexStore
           modules : [
               {
                  dispatch: [
                       'createNote',
                   ],
                   commit: [
                       'RESET_FORM'
                   ]
               }
           ]
        });
    }

    create(data) {
        this.createNote(data);
    }

    update(data) {
        this.dispatch('note/updateNote', data);
        this.commit('note/updateState', data);
    }
}