├── .babelrc ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── docs ├── css │ └── app.9a2c2913.css ├── favicon.ico ├── index.html └── js │ ├── app.8bd56d8b.js │ ├── app.8bd56d8b.js.map │ ├── chunk-vendors.8ce39230.js │ └── chunk-vendors.8ce39230.js.map ├── example-module-patterns ├── example-module.js └── module.js ├── example-vmg-modules ├── async.js ├── clone.js ├── crud.js ├── export.js ├── import.js ├── move.js └── sort.js ├── example ├── .eslintrc.js ├── .gitignore ├── .postcssrc.js ├── babel.config.js ├── package.json ├── public │ ├── favicon.ico │ └── index.html ├── src │ ├── App.vue │ ├── api │ │ └── index.js │ ├── assets │ │ └── logo.png │ ├── components │ │ ├── Customer.vue │ │ └── ModuleDetail.vue │ ├── main.js │ ├── mock │ │ └── customer.json │ ├── router.js │ ├── store │ │ ├── Customer.js │ │ └── index.js │ └── views │ │ └── Home.vue ├── vue.config.js └── yarn.lock ├── package.json ├── src ├── action │ ├── __tests__ │ │ ├── clone.actions.test.js │ │ ├── crud.actions.test.js │ │ ├── export.actions.test.js │ │ ├── import.actions.test.js │ │ ├── move.actions.test.js │ │ └── sort.actions.test.js │ ├── clone.js │ ├── crud.js │ ├── export.js │ ├── import.js │ ├── move.js │ ├── plain.js │ └── sort.js ├── index.js ├── mutations │ ├── __tests__ │ │ ├── clone.test.js │ │ ├── crud.test.js │ │ ├── export.test.js │ │ ├── import.test.js │ │ ├── move.test.js │ │ └── sort.test.js │ ├── clone.js │ ├── crud.js │ ├── export.js │ ├── import.js │ ├── move.js │ └── sort.js ├── state │ ├── clone.js │ ├── crud.js │ ├── export.js │ ├── import.js │ ├── move.js │ └── sort.js └── type │ ├── __tests__ │ └── types.test.js │ ├── active.js │ ├── async.js │ ├── clone.js │ ├── crud.js │ ├── export.js │ ├── import.js │ ├── move.js │ └── sort.js ├── test └── jest.conf.js ├── webpack.config.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "env", 5 | { 6 | "targets": { 7 | "browsers": [ 8 | "> 1%", 9 | "last 2 versions", 10 | "not ie <= 8" 11 | ] 12 | } 13 | } 14 | ], 15 | "stage-2" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | /dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | /test/unit/coverage/ 8 | 9 | # Editor directories and files 10 | .idea 11 | .vscode 12 | .env 13 | .env.* 14 | *.suo 15 | *.ntvs* 16 | *.njsproj 17 | *.sln 18 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .babelrc 3 | .git 4 | .gitignore 5 | .npmignore 6 | README.md 7 | node_modules 8 | src 9 | test 10 | webpack.config.js 11 | yarn.lock 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Abdullah 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vuex Module Generator (VMG) 2 | 3 | `VMG` allows you to create a `vuex` module easily. 4 | 5 | See [All implementations](https://github.com/abdullah/vuex-module-generator/blob/master/example-vmg-modules). 6 | 7 | See [Customer Example](https://abdullah.github.io/vuex-module-generator/). 8 | 9 | ### Supported module types 10 | 11 | * Clone 12 | * Crud 13 | * Export 14 | * Import 15 | * Move 16 | * Sort 17 | 18 | ## Motivation 19 | 20 | Most of the web applications contain CRUD actions. Vuex or other state management libraries like `redux` implement `stores` which handle CRUD actions. 21 | According to some store patterns each module must contain `isLoading`, `isLoaded`, `data` and `errors` properties in own state, therefore, a module's state can be implemented like this; 22 | 23 | ```javascript 24 | const customerState = { 25 | list: { 26 | isLoading: false, 27 | isLoaded: false, 28 | data: [], 29 | errors: {} 30 | } 31 | }; 32 | ``` 33 | 34 | Sure, there must be other module members `type`, `actions` and `mutations`. Check completed [ vuex module](https://github.com/abdullah/vuex-module-generator/blob/master/example-module-patterns/example-module.js) according to module pattern. 35 | 36 | This module contains `list` state with `isLoading`, `isLoaded`, `data` and `errors` properties. When `fetchCustomer` action is called, these states will be changed according to three action types. 37 | 38 | * `INDEX.REQUEST`, it sets `isLoading` true, this means list has been being fetching 39 | * `INDEX.SUCCESS`, it sets `isLoading` false, `isLoaded` true and data with `payload.data`, this means list has been fetched and there is no problem when it was happening 40 | * `INDEX.FAILURE`, it sets `isLoading` false, `isLoaded` false, `data`: empty array (b/c it is a list), this means there is an error and it was failed 41 | 42 | 43 | 44 | Finally, the developer can use these different states of the module in different cases. For instance, `isLoading` state can be used by a list to show an indicator or `error` that can be used to show an error component. 45 | 46 | The purpose of `VMG` is reducing code lines and making development easy. 47 | 48 | ## Use cases 49 | 50 | * If you have a large application which contains **CRUD** actions in each page/module/component. 51 | * If you want to control **async** states. 52 | * If you want to set a rule which limits to do **CRUD** actions. 53 | 54 | 55 | ## Usage 56 | 57 | Import generator members. 58 | 59 | ``` 60 | import { createCrudActions, createCrudActionTypes, createCrudMutation, createCrudState } from 'vuex-module-generator'; 61 | ``` 62 | 63 | **`createCrudState`** returns an object which contains `list`, `active`, `creating`, `updating`, `destroying` properties. 64 | These properties contain some sub-properties. Check [CRUD state](https://github.com/Vispera/vuex-module-generator/blob/master/src/state/crud.js) . 65 | 66 | **`createCrudActions`** returns CRUD methods to manage `index`, `show`, `create` etc. resource. 67 | Check [CRUD actions](https://github.com/Vispera/vuex-module-generator/blob/master/src/action/crud.js) . 68 | 69 | 70 | **`createCrudActionTypes`** returns action types which will be used by `createCrudActions`. 71 | 72 | **`createCrudMutation`** return functions which handle `CRUD` state mutations. Check [CRUD mutations](https://github.com/Vispera/vuex-module-generator/blob/master/src/mutations/crud.js) . 73 | 74 | 75 | # Complete example 76 | 77 | **Note**: This example can be used for other `VMG` members. 78 | 79 | ```javascript 80 | /* eslint-disable no-param-reassign */ 81 | import { createCrudActions, createCrudActionTypes, createCrudMutation, createCrudState } from 'vuex-module-generator'; 82 | 83 | export const types = { 84 | ...createCrudActionTypes('MODULE_NAME') 85 | }; 86 | 87 | export const actions = createCrudActions(types); 88 | 89 | export default { 90 | state: { ...createCrudState() }, 91 | mutations: { ...createCrudMutation(types) }, 92 | actions: { 93 | async fetchSomeResource({ commit }) { 94 | commit(actions.index.request()); 95 | try { 96 | const res = await asyncSomeResourceAction(); 97 | const { data, meta } = res.data; 98 | commit(actions.index.success({ data })); 99 | return { data, meta }; 100 | } catch (error) { 101 | commit(actions.index.failure(error)); 102 | return Promise.reject(error); 103 | } 104 | } 105 | } 106 | }; 107 | ``` 108 | 109 | 110 | Credit 111 | 112 | Thanks [Altay Aydemir](https://github.com/altayaydemir), he was my previous developer which wrote this factory for redux, I have implemented it for vuex. That's all :) 113 | -------------------------------------------------------------------------------- /docs/css/app.9a2c2913.css: -------------------------------------------------------------------------------- 1 | #app{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;color:#2c3e50;font-family:Avenir,Helvetica,Arial,sans-serif}#nav{padding:30px}#nav a{color:#2c3e50;font-weight:700;text-decoration:none}#nav a.router-link-exact-active{color:#42b983}button{background:#fff;border:1px solid #ddd;margin-bottom:15px;padding:7px 10px}.home{display:-webkit-box;display:-ms-flexbox;display:flex}.tails{margin-left:30px;min-width:400px} -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullah/vuex-module-generator/d4ba2509533924f989529bc8e6aad4d73e434438/docs/favicon.ico -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | vmg-example
-------------------------------------------------------------------------------- /docs/js/app.8bd56d8b.js: -------------------------------------------------------------------------------- 1 | (function(e){function a(a){for(var t,l,m=a[0],s=a[1],o=a[2],c=0,u=[];c1&&void 0!==m[1]&&m[1],n(H.index.request()),e.prev=3,e.next=6,S(t);case 6:return r=e.sent,i=r.data,l=r.meta,n(H.index.success({data:i,meta:l})),e.abrupt("return",{data:i,meta:l});case 12:return e.prev=12,e.t0=e["catch"](3),n(H.index.failure({message:e.t0.message})),e.abrupt("return",Promise.reject(e.t0));case 16:case"end":return e.stop()}},e,this,[[3,12]])}));return function(a){return e.apply(this,arguments)}}()}};t["a"].use(h["a"]);var K=new h["a"].Store({modules:{Customer:T}});t["a"].config.productionTip=!1,new t["a"]({router:E,store:K,render:function(e){return e(o)}}).$mount("#app")},boi5:function(e,a,n){},nNx0:function(e,a,n){"use strict";var t=n("boi5"),r=n.n(t);r.a},"u4p/":function(e){e.exports=[{id:1,first_name:"Jeffie",last_name:"Buckerfield",email:"jbuckerfield0@gmpg.org",gender:"Male"},{id:2,first_name:"Kelly",last_name:"Abramin",email:"kabramin1@g.co",gender:"Female"},{id:3,first_name:"Arnie",last_name:"Courtier",email:"acourtier2@yahoo.co.jp",gender:"Male"},{id:4,first_name:"Aurthur",last_name:"Marusik",email:"amarusik3@cbsnews.com",gender:"Male"},{id:5,first_name:"Hubert",last_name:"Corbitt",email:"hcorbitt4@yahoo.com",gender:"Male"},{id:6,first_name:"Finlay",last_name:"Codman",email:"fcodman5@bing.com",gender:"Male"},{id:7,first_name:"Suzanna",last_name:"Doniso",email:"sdoniso6@dailymotion.com",gender:"Female"},{id:8,first_name:"Gal",last_name:"Oliver-Paull",email:"goliverpaull7@macromedia.com",gender:"Male"},{id:9,first_name:"Dalli",last_name:"MacCome",email:"dmaccome8@dmoz.org",gender:"Male"},{id:10,first_name:"Dayle",last_name:"Moyer",email:"dmoyer9@bing.com",gender:"Female"},{id:11,first_name:"Connie",last_name:"McGilmartin",email:"cmcgilmartina@oakley.com",gender:"Female"},{id:12,first_name:"Aguistin",last_name:"MacKowle",email:"amackowleb@senate.gov",gender:"Male"},{id:13,first_name:"Lindon",last_name:"Bambury",email:"lbamburyc@networkadvertising.org",gender:"Male"},{id:14,first_name:"Trace",last_name:"Clemenson",email:"tclemensond@github.io",gender:"Male"},{id:15,first_name:"Emlynn",last_name:"Vauter",email:"evautere@rambler.ru",gender:"Female"},{id:16,first_name:"Coop",last_name:"Bandy",email:"cbandyf@skyrock.com",gender:"Male"},{id:17,first_name:"Caresse",last_name:"Le Brum",email:"clebrumg@ed.gov",gender:"Female"},{id:18,first_name:"Dolley",last_name:"Gentzsch",email:"dgentzschh@weebly.com",gender:"Female"},{id:19,first_name:"Rebeka",last_name:"Smallshaw",email:"rsmallshawi@blogger.com",gender:"Female"},{id:20,first_name:"Onfre",last_name:"Corter",email:"ocorterj@hatena.ne.jp",gender:"Male"},{id:21,first_name:"Fonsie",last_name:"Syrett",email:"fsyrettk@over-blog.com",gender:"Male"},{id:22,first_name:"Alfie",last_name:"Lackey",email:"alackeyl@csmonitor.com",gender:"Male"},{id:23,first_name:"Katerine",last_name:"Marritt",email:"kmarrittm@buzzfeed.com",gender:"Female"},{id:24,first_name:"Mohammed",last_name:"Geal",email:"mgealn@marketwatch.com",gender:"Male"},{id:25,first_name:"Huntington",last_name:"Pymer",email:"hpymero@artisteer.com",gender:"Male"},{id:26,first_name:"Meggy",last_name:"Pelchat",email:"mpelchatp@google.com.br",gender:"Female"},{id:27,first_name:"Antonius",last_name:"Castanone",email:"acastanoneq@opera.com",gender:"Male"},{id:28,first_name:"Mona",last_name:"Dugood",email:"mdugoodr@smugmug.com",gender:"Female"},{id:29,first_name:"Waylen",last_name:"Cosford",email:"wcosfords@google.ca",gender:"Male"},{id:30,first_name:"Carlye",last_name:"Woosnam",email:"cwoosnamt@cloudflare.com",gender:"Female"},{id:31,first_name:"Marga",last_name:"Ianno",email:"miannou@drupal.org",gender:"Female"},{id:32,first_name:"Rosabelle",last_name:"Peck",email:"rpeckv@irs.gov",gender:"Female"},{id:33,first_name:"Burt",last_name:"Aylen",email:"baylenw@china.com.cn",gender:"Male"},{id:34,first_name:"Gusella",last_name:"Kyrkeman",email:"gkyrkemanx@studiopress.com",gender:"Female"},{id:35,first_name:"Gleda",last_name:"Chapell",email:"gchapelly@cbsnews.com",gender:"Female"},{id:36,first_name:"Cordi",last_name:"Venditti",email:"cvendittiz@google.de",gender:"Female"},{id:37,first_name:"Rodd",last_name:"Hryniewicz",email:"rhryniewicz10@nasa.gov",gender:"Male"},{id:38,first_name:"Blondell",last_name:"Divill",email:"bdivill11@pbs.org",gender:"Female"},{id:39,first_name:"Chrissy",last_name:"Colby",email:"ccolby12@reddit.com",gender:"Male"},{id:40,first_name:"Tamqrah",last_name:"Pund",email:"tpund13@discovery.com",gender:"Female"},{id:41,first_name:"Sherlocke",last_name:"Woodnutt",email:"swoodnutt14@360.cn",gender:"Male"},{id:42,first_name:"Zea",last_name:"Gorton",email:"zgorton15@google.ca",gender:"Female"},{id:43,first_name:"Biddie",last_name:"Aukland",email:"baukland16@wix.com",gender:"Female"},{id:44,first_name:"Tawsha",last_name:"Avrahamian",email:"tavrahamian17@wikipedia.org",gender:"Female"},{id:45,first_name:"Levy",last_name:"Veregan",email:"lveregan18@go.com",gender:"Male"},{id:46,first_name:"Bari",last_name:"Arlott",email:"barlott19@google.it",gender:"Female"},{id:47,first_name:"Horace",last_name:"Junkin",email:"hjunkin1a@histats.com",gender:"Male"},{id:48,first_name:"Rafaela",last_name:"Corteney",email:"rcorteney1b@cbslocal.com",gender:"Female"},{id:49,first_name:"Bronny",last_name:"Wansbury",email:"bwansbury1c@wp.com",gender:"Male"},{id:50,first_name:"Gibby",last_name:"Billinge",email:"gbillinge1d@icio.us",gender:"Male"},{id:51,first_name:"Maegan",last_name:"Bollard",email:"mbollard1e@ustream.tv",gender:"Female"},{id:52,first_name:"Corny",last_name:"Mellers",email:"cmellers1f@ucoz.ru",gender:"Female"},{id:53,first_name:"Zachary",last_name:"Maclaine",email:"zmaclaine1g@lulu.com",gender:"Male"},{id:54,first_name:"Edgardo",last_name:"McNamara",email:"emcnamara1h@webs.com",gender:"Male"},{id:55,first_name:"Rosalynd",last_name:"Innwood",email:"rinnwood1i@baidu.com",gender:"Female"},{id:56,first_name:"Hill",last_name:"Iohananof",email:"hiohananof1j@cbc.ca",gender:"Male"},{id:57,first_name:"Irita",last_name:"Carson",email:"icarson1k@quantcast.com",gender:"Female"},{id:58,first_name:"Gisele",last_name:"Paolino",email:"gpaolino1l@nps.gov",gender:"Female"},{id:59,first_name:"Judd",last_name:"Croke",email:"jcroke1m@addthis.com",gender:"Male"},{id:60,first_name:"Eva",last_name:"Davley",email:"edavley1n@delicious.com",gender:"Female"},{id:61,first_name:"Clair",last_name:"Watting",email:"cwatting1o@usgs.gov",gender:"Male"},{id:62,first_name:"Franzen",last_name:"Haselup",email:"fhaselup1p@lulu.com",gender:"Male"},{id:63,first_name:"Leese",last_name:"Pordal",email:"lpordal1q@salon.com",gender:"Female"},{id:64,first_name:"Colleen",last_name:"Yggo",email:"cyggo1r@bandcamp.com",gender:"Female"},{id:65,first_name:"Harp",last_name:"Delgado",email:"hdelgado1s@php.net",gender:"Male"},{id:66,first_name:"Hyatt",last_name:"Duffy",email:"hduffy1t@mysql.com",gender:"Male"},{id:67,first_name:"Barb",last_name:"Cronk",email:"bcronk1u@bravesites.com",gender:"Female"},{id:68,first_name:"Karita",last_name:"Apthorpe",email:"kapthorpe1v@tiny.cc",gender:"Female"},{id:69,first_name:"Gray",last_name:"Corker",email:"gcorker1w@odnoklassniki.ru",gender:"Male"},{id:70,first_name:"Fenelia",last_name:"Tregale",email:"ftregale1x@behance.net",gender:"Female"},{id:71,first_name:"Meredeth",last_name:"Hoyles",email:"mhoyles1y@flickr.com",gender:"Male"},{id:72,first_name:"Lindie",last_name:"Anger",email:"langer1z@ebay.co.uk",gender:"Female"},{id:73,first_name:"Gwenny",last_name:"Ellen",email:"gellen20@huffingtonpost.com",gender:"Female"},{id:74,first_name:"Annalise",last_name:"Cullerne",email:"acullerne21@behance.net",gender:"Female"},{id:75,first_name:"Ewan",last_name:"Artus",email:"eartus22@elpais.com",gender:"Male"},{id:76,first_name:"Kit",last_name:"Rankling",email:"krankling23@intel.com",gender:"Male"},{id:77,first_name:"Price",last_name:"Walkingshaw",email:"pwalkingshaw24@craigslist.org",gender:"Male"},{id:78,first_name:"Dorena",last_name:"Ainslie",email:"dainslie25@github.com",gender:"Female"},{id:79,first_name:"Isidora",last_name:"Bleddon",email:"ibleddon26@angelfire.com",gender:"Female"},{id:80,first_name:"Margette",last_name:"Lamble",email:"mlamble27@skype.com",gender:"Female"},{id:81,first_name:"Burt",last_name:"Minihan",email:"bminihan28@google.com",gender:"Male"},{id:82,first_name:"Dre",last_name:"Bome",email:"dbome29@sciencedaily.com",gender:"Female"},{id:83,first_name:"Elroy",last_name:"Hanscome",email:"ehanscome2a@indiatimes.com",gender:"Male"},{id:84,first_name:"Ella",last_name:"Taunton.",email:"etaunton2b@ihg.com",gender:"Female"},{id:85,first_name:"Mirelle",last_name:"Attwater",email:"mattwater2c@dagondesign.com",gender:"Female"},{id:86,first_name:"Sandro",last_name:"Wiggin",email:"swiggin2d@washington.edu",gender:"Male"},{id:87,first_name:"Cort",last_name:"Randlesome",email:"crandlesome2e@nytimes.com",gender:"Male"},{id:88,first_name:"Ira",last_name:"Legister",email:"ilegister2f@ifeng.com",gender:"Female"},{id:89,first_name:"Lincoln",last_name:"Pickthorn",email:"lpickthorn2g@ifeng.com",gender:"Male"},{id:90,first_name:"Romola",last_name:"Baldacchi",email:"rbaldacchi2h@reference.com",gender:"Female"},{id:91,first_name:"Dorine",last_name:"Allott",email:"dallott2i@cnbc.com",gender:"Female"},{id:92,first_name:"Barby",last_name:"Fronczak",email:"bfronczak2j@cmu.edu",gender:"Female"},{id:93,first_name:"Gerardo",last_name:"Kummerlowe",email:"gkummerlowe2k@mayoclinic.com",gender:"Male"},{id:94,first_name:"Alwyn",last_name:"Streatley",email:"astreatley2l@eepurl.com",gender:"Male"},{id:95,first_name:"Erek",last_name:"Kollach",email:"ekollach2m@addtoany.com",gender:"Male"},{id:96,first_name:"Melina",last_name:"Cotterill",email:"mcotterill2n@ted.com",gender:"Female"},{id:97,first_name:"Cheri",last_name:"Baytrop",email:"cbaytrop2o@irs.gov",gender:"Female"},{id:98,first_name:"Myca",last_name:"Cran",email:"mcran2p@omniture.com",gender:"Male"},{id:99,first_name:"Rodrique",last_name:"Sapsforde",email:"rsapsforde2q@bluehost.com",gender:"Male"},{id:100,first_name:"Jeannette",last_name:"Slucock",email:"jslucock2r@mozilla.com",gender:"Female"}]}}); 2 | //# sourceMappingURL=app.8bd56d8b.js.map -------------------------------------------------------------------------------- /docs/js/app.8bd56d8b.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/views/Home.vue?1a5c","webpack:///./src/components/Customer.vue?43ac","webpack:///./src/App.vue?dca2","webpack:///./src/App.vue?bff9","webpack:///./src/views/Home.vue?5ed1","webpack:///./src/components/Customer.vue?e3cd","webpack:///src/components/Customer.vue","webpack:///./src/components/Customer.vue?7e3e","webpack:///./src/components/Customer.vue?321b","webpack:///./src/components/ModuleDetail.vue?a9ae","webpack:///src/components/ModuleDetail.vue","webpack:///./src/components/ModuleDetail.vue?e516","webpack:///./src/components/ModuleDetail.vue","webpack:///src/views/Home.vue","webpack:///./src/views/Home.vue?658d","webpack:///./src/views/Home.vue?c853","webpack:///./src/router.js","webpack:///./src/api/index.js","webpack:///./src/store/Customer.js","webpack:///./src/store/index.js","webpack:///./src/main.js","webpack:///./src/App.vue?f46a"],"names":["webpackJsonpCallback","data","moduleId","chunkId","chunkIds","moreModules","executeModules","i","resolves","length","installedChunks","push","Object","prototype","hasOwnProperty","call","modules","parentJsonpFunction","shift","deferredModules","apply","checkDeferredModules","result","deferredModule","fulfilled","j","depId","splice","__webpack_require__","s","installedModules","0","exports","module","l","m","c","d","name","getter","o","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","p","jsonpArray","window","oldJsonpFunction","slice","_node_modules_mini_css_extract_plugin_dist_loader_js_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_lib_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_Home_vue_vue_type_style_index_0_lang_css__WEBPACK_IMPORTED_MODULE_0___default","_node_modules_mini_css_extract_plugin_dist_loader_js_node_modules_css_loader_index_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_lib_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_Customer_vue_vue_type_style_index_0_lang_css__WEBPACK_IMPORTED_MODULE_0___default","Appvue_type_template_id_0f613930_render","_vm","this","_h","$createElement","_c","_self","attrs","id","to","_v","staticRenderFns","script","component","componentNormalizer","App","Homevue_type_template_id_7da2d742_render","staticClass","Homevue_type_template_id_7da2d742_staticRenderFns","Customervue_type_template_id_42759c28_render","isLoaded","isLoading","_e","on","click","onClick","_s","cleanAndFetch","showErrorCase","Customer","list","errors","message","_l","customer","first_name","Customervue_type_template_id_42759c28_staticRenderFns","Customervue_type_script_lang_js","computed","objectSpread","vuex_esm","customerList","hasError","methods","cleanCustomers","fetchCustomers","components_Customervue_type_script_lang_js","Customer_component","ModuleDetailvue_type_template_id_337900d8_render","ModuleDetailvue_type_template_id_337900d8_staticRenderFns","ModuleDetailvue_type_script_lang_js","components_ModuleDetailvue_type_script_lang_js","ModuleDetail_component","ModuleDetail","Homevue_type_script_lang_js","components","views_Homevue_type_script_lang_js","Home_component","Home","vue_runtime_esm","use","vue_router_esm","router","routes","path","api_fetchCustomers","makeError","Promise","resolve","reject","setTimeout","Error","status","lodash_shuffle_default","meta","types","vue_module_factory_min","actions","store_Customer","state","mutations","_ref","commit","clean","_fetchCustomers2","asyncToGenerator","regeneratorRuntime","mark","_callee","_ref2","res","_args","arguments","wrap","_context","prev","next","undefined","index","request","sent","success","abrupt","t0","failure","stop","_x","store","Store","config","productionTip","render","h","$mount","_node_modules_mini_css_extract_plugin_dist_loader_js_node_modules_css_loader_index_js_ref_8_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_lib_index_js_ref_8_oneOf_1_2_node_modules_sass_loader_lib_loader_js_ref_8_oneOf_1_3_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_scss__WEBPACK_IMPORTED_MODULE_0___default"],"mappings":"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","file":"js/app.8bd56d8b.js","sourcesContent":[" \t// install a JSONP callback for chunk loading\n \tfunction webpackJsonpCallback(data) {\n \t\tvar chunkIds = data[0];\n \t\tvar moreModules = data[1];\n \t\tvar executeModules = data[2];\n\n \t\t// add \"moreModules\" to the modules object,\n \t\t// then flag all \"chunkIds\" as loaded and fire callback\n \t\tvar moduleId, chunkId, i = 0, resolves = [];\n \t\tfor(;i < chunkIds.length; i++) {\n \t\t\tchunkId = chunkIds[i];\n \t\t\tif(installedChunks[chunkId]) {\n \t\t\t\tresolves.push(installedChunks[chunkId][0]);\n \t\t\t}\n \t\t\tinstalledChunks[chunkId] = 0;\n \t\t}\n \t\tfor(moduleId in moreModules) {\n \t\t\tif(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {\n \t\t\t\tmodules[moduleId] = moreModules[moduleId];\n \t\t\t}\n \t\t}\n \t\tif(parentJsonpFunction) parentJsonpFunction(data);\n\n \t\twhile(resolves.length) {\n \t\t\tresolves.shift()();\n \t\t}\n\n \t\t// add entry modules from loaded chunk to deferred list\n \t\tdeferredModules.push.apply(deferredModules, executeModules || []);\n\n \t\t// run deferred modules when all chunks ready\n \t\treturn checkDeferredModules();\n \t};\n \tfunction checkDeferredModules() {\n \t\tvar result;\n \t\tfor(var i = 0; i < deferredModules.length; i++) {\n \t\t\tvar deferredModule = deferredModules[i];\n \t\t\tvar fulfilled = true;\n \t\t\tfor(var j = 1; j < deferredModule.length; j++) {\n \t\t\t\tvar depId = deferredModule[j];\n \t\t\t\tif(installedChunks[depId] !== 0) fulfilled = false;\n \t\t\t}\n \t\t\tif(fulfilled) {\n \t\t\t\tdeferredModules.splice(i--, 1);\n \t\t\t\tresult = __webpack_require__(__webpack_require__.s = deferredModule[0]);\n \t\t\t}\n \t\t}\n \t\treturn result;\n \t}\n\n \t// The module cache\n \tvar installedModules = {};\n\n \t// object to store loaded and loading chunks\n \t// undefined = chunk not loaded, null = chunk preloaded/prefetched\n \t// Promise = chunk loading, 0 = chunk loaded\n \tvar installedChunks = {\n \t\t0: 0\n \t};\n\n \tvar deferredModules = [];\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/vuex-module-generator/\";\n\n \tvar jsonpArray = window[\"webpackJsonp\"] = window[\"webpackJsonp\"] || [];\n \tvar oldJsonpFunction = jsonpArray.push.bind(jsonpArray);\n \tjsonpArray.push = webpackJsonpCallback;\n \tjsonpArray = jsonpArray.slice();\n \tfor(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);\n \tvar parentJsonpFunction = oldJsonpFunction;\n\n\n \t// add entry module to deferred list\n \tdeferredModules.push([0,1]);\n \t// run deferred modules when ready\n \treturn checkDeferredModules();\n","import mod from \"-!../../node_modules/mini-css-extract-plugin/dist/loader.js!../../node_modules/css-loader/index.js??ref--6-oneOf-1-1!../../node_modules/vue-loader/lib/loaders/stylePostLoader.js!../../node_modules/postcss-loader/lib/index.js??ref--6-oneOf-1-2!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./Home.vue?vue&type=style&index=0&lang=css\"; export default mod; export * from \"-!../../node_modules/mini-css-extract-plugin/dist/loader.js!../../node_modules/css-loader/index.js??ref--6-oneOf-1-1!../../node_modules/vue-loader/lib/loaders/stylePostLoader.js!../../node_modules/postcss-loader/lib/index.js??ref--6-oneOf-1-2!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./Home.vue?vue&type=style&index=0&lang=css\"","import mod from \"-!../../node_modules/mini-css-extract-plugin/dist/loader.js!../../node_modules/css-loader/index.js??ref--6-oneOf-1-1!../../node_modules/vue-loader/lib/loaders/stylePostLoader.js!../../node_modules/postcss-loader/lib/index.js??ref--6-oneOf-1-2!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./Customer.vue?vue&type=style&index=0&lang=css\"; export default mod; export * from \"-!../../node_modules/mini-css-extract-plugin/dist/loader.js!../../node_modules/css-loader/index.js??ref--6-oneOf-1-1!../../node_modules/vue-loader/lib/loaders/stylePostLoader.js!../../node_modules/postcss-loader/lib/index.js??ref--6-oneOf-1-2!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./Customer.vue?vue&type=style&index=0&lang=css\"","var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{attrs:{\"id\":\"app\"}},[_c('div',{attrs:{\"id\":\"nav\"}},[_c('router-link',{attrs:{\"to\":\"/\"}},[_vm._v(\"HOME\")])],1),_c('hr'),_c('router-view')],1)}\nvar staticRenderFns = []\n\nexport { render, staticRenderFns }","import { render, staticRenderFns } from \"./App.vue?vue&type=template&id=0f613930\"\nvar script = {}\nimport style0 from \"./App.vue?vue&type=style&index=0&lang=scss\"\n\n\n/* normalize component */\nimport normalizer from \"!../node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n null,\n null\n \n)\n\nexport default component.exports","var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:\"home\"},[_c('Customer'),_c('ModuleDetail')],1)}\nvar staticRenderFns = []\n\nexport { render, staticRenderFns }","var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:\"tails\"},[_c('h2',[_vm._v(\"Customer List\")]),(!_vm.isLoaded && !_vm.isLoading)?_c('p',[_c('small',[_vm._v(\"Click a button to fetch customer list or to see other cases\")])]):_vm._e(),_c('button',{on:{\"click\":_vm.onClick}},[_vm._v(_vm._s(_vm.isLoading ? 'Loading...': 'Fetch Customers'))]),_c('br'),_c('button',{on:{\"click\":_vm.cleanAndFetch}},[_vm._v(\"\\n \"+_vm._s(_vm.isLoading ? 'Loading...': 'Clean & Fetch Customers')+\"\\n \")]),_c('br'),_c('button',{on:{\"click\":_vm.showErrorCase}},[_vm._v(\"\\n \"+_vm._s(_vm.isLoading ? 'Loading...': 'Fetch Customers & Show error case')+\"\\n \")]),(_vm.hasError)?_c('p',[_vm._v(_vm._s(_vm.Customer.list.errors.message))]):_vm._e(),(_vm.isLoaded)?_c('ul',_vm._l((_vm.customerList),function(customer){return _c('li',{key:customer.id},[_vm._v(_vm._s(customer.first_name))])})):_vm._e()])}\nvar staticRenderFns = []\n\nexport { render, staticRenderFns }","\n\n\n\n\n","import mod from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./Customer.vue?vue&type=script&lang=js\"; export default mod; export * from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./Customer.vue?vue&type=script&lang=js\"","import { render, staticRenderFns } from \"./Customer.vue?vue&type=template&id=42759c28\"\nimport script from \"./Customer.vue?vue&type=script&lang=js\"\nexport * from \"./Customer.vue?vue&type=script&lang=js\"\nimport style0 from \"./Customer.vue?vue&type=style&index=0&lang=css\"\n\n\n/* normalize component */\nimport normalizer from \"!../../node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n null,\n null\n \n)\n\nexport default component.exports","var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:\"tails\"},[_c('h2',[_vm._v(\"Module Detail (just list)\")]),_c('small',[_vm._v(\"You can check vue devtools to see other states\")]),_c('h3',[_vm._v(\"List state\")]),_c('p',[_c('b',[_vm._v(\"isLoading\")]),_vm._v(\" \"+_vm._s(_vm.Customer.list.isLoading)+\" \")]),_c('p',[_c('b',[_vm._v(\"isLoaded\")]),_vm._v(\" \"+_vm._s(_vm.Customer.list.isLoaded)+\" \")]),_c('p',[_c('b',[_vm._v(\"errors\")]),_vm._v(\" \"+_vm._s(_vm.Customer.list.errors)+\" \")]),_c('p',[_c('b',[_vm._v(\"data\")]),_vm._v(\" \"+_vm._s(_vm.Customer.list.data)+\" \")])])}\nvar staticRenderFns = []\n\nexport { render, staticRenderFns }","\n\n\n","import mod from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./ModuleDetail.vue?vue&type=script&lang=js\"; export default mod; export * from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./ModuleDetail.vue?vue&type=script&lang=js\"","import { render, staticRenderFns } from \"./ModuleDetail.vue?vue&type=template&id=337900d8\"\nimport script from \"./ModuleDetail.vue?vue&type=script&lang=js\"\nexport * from \"./ModuleDetail.vue?vue&type=script&lang=js\"\n\n\n/* normalize component */\nimport normalizer from \"!../../node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n null,\n null\n \n)\n\nexport default component.exports","\n\n\n\n\n","import mod from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./Home.vue?vue&type=script&lang=js\"; export default mod; export * from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./Home.vue?vue&type=script&lang=js\"","import { render, staticRenderFns } from \"./Home.vue?vue&type=template&id=7da2d742\"\nimport script from \"./Home.vue?vue&type=script&lang=js\"\nexport * from \"./Home.vue?vue&type=script&lang=js\"\nimport style0 from \"./Home.vue?vue&type=style&index=0&lang=css\"\n\n\n/* normalize component */\nimport normalizer from \"!../../node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n null,\n null\n \n)\n\nexport default component.exports","import Vue from 'vue';\nimport Router from 'vue-router';\nimport Home from './views/Home.vue';\n\nVue.use(Router);\n\nexport default new Router({\n routes: [\n {\n path: '/',\n name: 'home',\n component: Home,\n },\n ],\n});\n","\nimport shuffle from 'lodash.shuffle';\nimport customers from '../mock/customer.json';\n\nexport const fetchCustomers = makeError => new Promise((resolve, reject) => {\n setTimeout(() => {\n if (makeError) {\n reject(new Error('Unexpected error has been occured'));\n } else {\n resolve({ status: 200, data: shuffle(customers), meta: { } });\n }\n }, 2000);\n});\n\nexport default {\n fetchCustomers,\n};\n","/* eslint-disable no-param-reassign */\nimport { fetchCustomers } from '@/api/index';\nimport { createCrudActions, createCrudActionTypes, createCrudMutation, createCrudState } from 'vuex-module-generator';\n\n\nexport const types = {\n ...createCrudActionTypes('CUSTOMER'),\n};\n\nexport const actions = createCrudActions(types);\n\nexport default {\n state: { ...createCrudState() },\n mutations: { ...createCrudMutation(types) },\n actions: {\n cleanCustomers({ commit }) {\n commit(actions.clean.list());\n },\n async fetchCustomers({ commit }, makeError = false) {\n commit(actions.index.request());\n try {\n const res = await fetchCustomers(makeError);\n const { data, meta } = res;\n commit(actions.index.success({ data, meta }));\n return { data, meta };\n } catch (error) {\n commit(actions.index.failure({ message: error.message }));\n return Promise.reject(error);\n }\n },\n },\n};\n","import Vue from 'vue';\nimport Vuex from 'vuex';\nimport Customer from './Customer';\n\nVue.use(Vuex);\n\nexport default new Vuex.Store({\n modules: {\n Customer,\n },\n});\n","import Vue from 'vue';\nimport App from './App.vue';\nimport router from './router';\nimport store from './store/index';\n\nVue.config.productionTip = false;\n\nnew Vue({\n router,\n store,\n render: h => h(App),\n}).$mount('#app');\n","import mod from \"-!../node_modules/mini-css-extract-plugin/dist/loader.js!../node_modules/css-loader/index.js??ref--8-oneOf-1-1!../node_modules/vue-loader/lib/loaders/stylePostLoader.js!../node_modules/postcss-loader/lib/index.js??ref--8-oneOf-1-2!../node_modules/sass-loader/lib/loader.js??ref--8-oneOf-1-3!../node_modules/cache-loader/dist/cjs.js??ref--0-0!../node_modules/vue-loader/lib/index.js??vue-loader-options!./App.vue?vue&type=style&index=0&lang=scss\"; export default mod; export * from \"-!../node_modules/mini-css-extract-plugin/dist/loader.js!../node_modules/css-loader/index.js??ref--8-oneOf-1-1!../node_modules/vue-loader/lib/loaders/stylePostLoader.js!../node_modules/postcss-loader/lib/index.js??ref--8-oneOf-1-2!../node_modules/sass-loader/lib/loader.js??ref--8-oneOf-1-3!../node_modules/cache-loader/dist/cjs.js??ref--0-0!../node_modules/vue-loader/lib/index.js??vue-loader-options!./App.vue?vue&type=style&index=0&lang=scss\""],"sourceRoot":""} -------------------------------------------------------------------------------- /example-module-patterns/example-module.js: -------------------------------------------------------------------------------- 1 | import { fetchCustomer } from '@/api'; 2 | 3 | export const types = { 4 | INDEX: { 5 | REQUEST: 'CUSTOMER_GROUPS/INDEX_REQUEST', 6 | SUCCESS: 'CUSTOMER_GROUPS/INDEX_SUCCESS', 7 | FAILURE: 'CUSTOMER_GROUPS/INDEX_FAILURE' 8 | } 9 | }; 10 | 11 | export const customerState = { 12 | list: { 13 | isLoading: false, 14 | isLoaded: false, 15 | data: [], 16 | errors: {} 17 | } 18 | }; 19 | 20 | export const mutations = { 21 | [types.INDEX.REQUEST](state) { 22 | state.list = { 23 | ...state.list, 24 | isLoading: true, 25 | errors: {} 26 | }; 27 | }, 28 | [types.INDEX.SUCCESS](state, payload) { 29 | state.list = { 30 | isLoading: false, 31 | isLoaded: true, 32 | data: payload.data, 33 | errors: {} 34 | }; 35 | }, 36 | [types.INDEX.FAILURE](state, payload) { 37 | state.list = { 38 | isLoading: false, 39 | isLoaded: false, 40 | data: [], 41 | errors: payload.error 42 | }; 43 | } 44 | }; 45 | 46 | export default { 47 | state: customerState, 48 | getters, 49 | mutations, 50 | actions: { 51 | async fetchCustomer({ commit }) { 52 | commit({ type: types.INDEX.REQUEST }); 53 | try { 54 | const res = await fetchCustomer(); 55 | commit({ type: types.INDEX.SUCCESS, payload: { data: res.data } }); 56 | } catch (error) { 57 | commit({ type: types.INDEX.FAILURE, payload: { error } }); 58 | } 59 | } 60 | } 61 | }; 62 | -------------------------------------------------------------------------------- /example-module-patterns/module.js: -------------------------------------------------------------------------------- 1 | import { 2 | createCrudActions, 3 | createCrudActionTypes, 4 | createCrudMutation, 5 | createCrudState 6 | } from 'vuex-module-generator'; 7 | 8 | export const types = { 9 | ...createCrudActionTypes('MODULE_NAME') 10 | }; 11 | 12 | export const actions = createCrudActions(types); 13 | 14 | export default { 15 | state: { ...createCrudState() }, 16 | mutations: { ...createCrudMutation(types) }, 17 | actions: { 18 | async fetchSomeResource({ commit }) { 19 | commit(actions.index.request()); 20 | try { 21 | const res = await asyncSomeResourceAction(); 22 | const { data } = res.data; 23 | commit(actions.index.success({ data })); 24 | 25 | return Promise.resolve(res.data); 26 | } catch (error) { 27 | commit(actions.index.failure(error)); 28 | 29 | return Promise.reject(error); 30 | } 31 | } 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /example-vmg-modules/async.js: -------------------------------------------------------------------------------- 1 | import { createAction, createAsyncActionTypes } from 'vuex-module-generator'; 2 | import { fetchRoles } from '../api'; 3 | 4 | export const types = { 5 | ROLE: createAsyncActionTypes('ROLE', 'INDEX') 6 | }; 7 | 8 | export const roleState = () => ({ 9 | isLoading: false, 10 | isLoaded: false, 11 | data: {}, 12 | errors: {} 13 | }); 14 | 15 | export const mutations = { 16 | [types.ROLE.REQUEST](state) { 17 | state.isLoading = true; 18 | state.isLoaded = false; 19 | state.errors = {}; 20 | state.data = {}; 21 | }, 22 | [types.ROLE.FAILURE](state, payload) { 23 | state.isLoading = false; 24 | state.isLoaded = true; 25 | state.errors = payload.error; 26 | state.data = {}; 27 | }, 28 | [types.ROLE.SUCCESS](state, payload) { 29 | state.isLoading = false; 30 | state.isLoaded = true; 31 | state.errors = {}; 32 | state.data = payload.data; 33 | } 34 | }; 35 | 36 | export default { 37 | state: roleState, 38 | mutations, 39 | actions: { 40 | async fetchRoles({ commit }) { 41 | commit(createAction(types.ROLE.REQUEST)); 42 | try { 43 | const res = await fetchRoles(); 44 | const { data } = res.data; 45 | commit(createAction(types.ROLE.SUCCESS, { data })); 46 | return res; 47 | } catch (error) { 48 | commit(createAction(types.ROLE.FAILURE, { error })); 49 | return Promise.reject(error); 50 | } 51 | } 52 | } 53 | }; 54 | -------------------------------------------------------------------------------- /example-vmg-modules/clone.js: -------------------------------------------------------------------------------- 1 | export { cloneResource } from './api'; 2 | 3 | // Helpers 4 | import { 5 | createCloneActions, 6 | createCloneActionTypes, 7 | createCloneMutation, 8 | createCloneState 9 | } from 'vuex-module-generator'; 10 | 11 | export const types = { 12 | ...createCloneActionTypes('SOME_RESOURCE') 13 | }; 14 | 15 | export const cloneState = () => ({ 16 | ...createCloneState() 17 | }); 18 | 19 | export const mutations = { 20 | ...createCloneMutation(types) 21 | }; 22 | 23 | export const actions = createCloneActions(types); 24 | 25 | export default { 26 | state: cloneState, 27 | mutations, 28 | actions: { 29 | async cloneResource({ commit }) { 30 | commit(actions.clone.request()); 31 | try { 32 | const res = await cloneResource(); 33 | commit(actions.clone.success({ data: res.data, meta: res.meta })); 34 | return res; 35 | } catch (error) { 36 | commit(actions.clone.failure(error)); 37 | return Promise.reject(error); 38 | } 39 | }, 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /example-vmg-modules/crud.js: -------------------------------------------------------------------------------- 1 | import { 2 | indexResource, 3 | updateResource, 4 | createResource, 5 | destoryResource, 6 | showResource 7 | } from './api'; 8 | 9 | // Helpers 10 | import { 11 | createCrudActions, 12 | createCrudActionTypes, 13 | createCrudMutation, 14 | createCrudState 15 | } from 'vuex-module-generator'; 16 | 17 | export const types = { 18 | ...createCrudActionTypes('SOME_RESOURCE') 19 | }; 20 | 21 | export const resourceState = () => ({ 22 | ...createCrudState() 23 | }); 24 | 25 | export const mutations = { 26 | ...createCrudMutation(types) 27 | }; 28 | 29 | export const actions = createCrudActions(types); 30 | 31 | export default { 32 | state: resourceState, 33 | mutations, 34 | actions: { 35 | // Clean List 36 | cleanActivityList({ commit }) { 37 | commit(actions.clean.list()); 38 | }, 39 | // Fetch all resources 40 | async indexResource({ commit }) { 41 | commit(actions.index.request()); 42 | try { 43 | const res = await indexResource(); 44 | commit(actions.index.success({ data: res.data, meta: res.meta })); 45 | return res; 46 | } catch (error) { 47 | commit(actions.index.failure(error)); 48 | return Promise.reject(error); 49 | } 50 | }, 51 | // Create a resource 52 | async createResource({ commit }) { 53 | commit(actions.create.request()); 54 | try { 55 | const res = await createResource(); 56 | commit(actions.create.success({ data: res.data, meta: res.meta })); 57 | return res; 58 | } catch (error) { 59 | commit(actions.create.failure(error)); 60 | return Promise.reject(error); 61 | } 62 | }, 63 | // Update a resource 64 | async updateResource({ commit }) { 65 | commit(actions.update.request()); 66 | try { 67 | const res = await updateResource(); 68 | commit(actions.update.success({ data: res.data, meta: res.meta })); 69 | return res; 70 | } catch (error) { 71 | commit(actions.update.failure(error)); 72 | return Promise.reject(error); 73 | } 74 | }, 75 | // Destroy a resource 76 | async destoryResource({ commit }) { 77 | commit(actions.destory.request()); 78 | try { 79 | const res = await destoryResource(); 80 | commit(actions.destory.success({ data: res.data, meta: res.meta })); 81 | return res; 82 | } catch (error) { 83 | commit(actions.destory.failure(error)); 84 | return Promise.reject(error); 85 | } 86 | }, 87 | // Show a resource 88 | async showResource({ commit }) { 89 | commit(actions.show.request()); 90 | try { 91 | const res = await showResource(); 92 | commit(actions.show.success({ data: res.data, meta: res.meta })); 93 | return res; 94 | } catch (error) { 95 | commit(actions.show.failure(error)); 96 | return Promise.reject(error); 97 | } 98 | }, 99 | } 100 | }; 101 | -------------------------------------------------------------------------------- /example-vmg-modules/export.js: -------------------------------------------------------------------------------- 1 | export { exportResource } from './api'; 2 | 3 | // Helpers 4 | import { 5 | createExportActions, 6 | createExportActionTypes, 7 | createExportMutation, 8 | createExportState 9 | } from 'vuex-module-generator'; 10 | 11 | export const types = { 12 | ...createExportActionTypes('SOME_RESOURCE') 13 | }; 14 | 15 | export const imporState = () => ({ 16 | ...createExportState() 17 | }); 18 | 19 | export const mutations = { 20 | ...createExportMutation(types) 21 | }; 22 | 23 | export const actions = createExportActions(types); 24 | 25 | export default { 26 | state: imporState, 27 | mutations, 28 | actions: { 29 | // Fetch all resources 30 | async exportResource({ commit }) { 31 | commit(actions.export.request()); 32 | try { 33 | const res = await exportResource(); 34 | commit(actions.export.success({ data: res.data, meta: res.meta })); 35 | return res; 36 | } catch (error) { 37 | commit(actions.export.failure(error)); 38 | return Promise.reject(error); 39 | } 40 | }, 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /example-vmg-modules/import.js: -------------------------------------------------------------------------------- 1 | import { importResource } from './api'; 2 | // Helpers 3 | import { 4 | createImportActions, 5 | createImportActionTypes, 6 | createImportMutation, 7 | createImportState 8 | } from 'vuex-module-generator'; 9 | 10 | export const types = { 11 | ...createImportActionTypes('SOME_RESOURCE') 12 | }; 13 | 14 | export const imporState = () => ({ 15 | ...createImportState() 16 | }); 17 | 18 | export const mutations = { 19 | ...createImportMutation(types) 20 | }; 21 | 22 | export const actions = createImportActions(types); 23 | 24 | export default { 25 | state: imporState, 26 | mutations, 27 | actions: { 28 | // Fetch all resources 29 | async importResource({ commit }) { 30 | commit(actions.import.request()); 31 | try { 32 | const res = await importResource(); 33 | commit(actions.import.success({ data: res.data, meta: res.meta })); 34 | return res; 35 | } catch (error) { 36 | commit(actions.import.failure(error)); 37 | return Promise.reject(error); 38 | } 39 | }, 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /example-vmg-modules/move.js: -------------------------------------------------------------------------------- 1 | export { moveResource } from './api'; 2 | // Helpers 3 | import { 4 | createMoveActions, 5 | createMoveActionTypes, 6 | createMoveMutation, 7 | createMoveState 8 | } from 'vuex-module-generator'; 9 | 10 | export const types = { 11 | ...createMoveActionTypes('SOME_RESOURCE') 12 | }; 13 | 14 | export const moveState = () => ({ 15 | ...createMoveState() 16 | }); 17 | 18 | export const mutations = { 19 | ...createMoveMutation(types) 20 | }; 21 | 22 | export const actions = createMoveActions(types); 23 | 24 | export default { 25 | state: moveState, 26 | mutations, 27 | actions: { 28 | // Fetch all resources 29 | async moveResource({ commit }) { 30 | commit(actions.move.request()); 31 | try { 32 | const res = await moveResource(); 33 | commit(actions.move.success({ data: res.data, meta: res.meta })); 34 | return res; 35 | } catch (error) { 36 | commit(actions.move.failure(error)); 37 | return Promise.reject(error); 38 | } 39 | }, 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /example-vmg-modules/sort.js: -------------------------------------------------------------------------------- 1 | export { sortResource } from './api'; 2 | // Helpers 3 | import { 4 | createSortActions, 5 | createSortActionTypes, 6 | createSortMutation, 7 | createSortState 8 | } from 'vuex-module-generator'; 9 | 10 | export const types = { 11 | ...createSortActionTypes('SOME_RESOURCE') 12 | }; 13 | 14 | export const sortState = () => ({ 15 | ...createSortState() 16 | }); 17 | 18 | export const mutations = { 19 | ...createSortMutation(types) 20 | }; 21 | 22 | export const actions = createSortActions(types); 23 | 24 | export default { 25 | state: sortState, 26 | mutations, 27 | actions: { 28 | // Fetch all resources 29 | async sortResource({ commit }) { 30 | commit(actions.sort.request()); 31 | try { 32 | const res = await sortResource(); 33 | commit(actions.sort.success({ data: res.data, meta: res.meta })); 34 | return res; 35 | } catch (error) { 36 | commit(actions.sort.failure(error)); 37 | return Promise.reject(error); 38 | } 39 | }, 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /example/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | 'extends': [ 7 | 'plugin:vue/essential', 8 | '@vue/airbnb' 9 | ], 10 | rules: { 11 | 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 12 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off' 13 | }, 14 | parserOptions: { 15 | parser: 'babel-eslint' 16 | } 17 | } -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw* 22 | -------------------------------------------------------------------------------- /example/.postcssrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {} 4 | } 5 | } -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app', 4 | ], 5 | }; 6 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vmg-example", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "lodash.shuffle": "^4.2.0", 12 | "vue": "^2.5.16", 13 | "vue-router": "^3.0.1", 14 | "vuex": "^3.0.1", 15 | "vuex-module-generator": "^1.0.6" 16 | }, 17 | "devDependencies": { 18 | "@vue/cli-plugin-babel": "^3.0.0-rc.5", 19 | "@vue/cli-plugin-eslint": "^3.0.0-rc.5", 20 | "@vue/cli-service": "^3.0.0-rc.5", 21 | "@vue/eslint-config-airbnb": "^3.0.0-rc.5", 22 | "lint-staged": "^7.2.0", 23 | "node-sass": "^4.9.0", 24 | "sass-loader": "^7.0.1", 25 | "vue-template-compiler": "^2.5.16" 26 | }, 27 | "browserslist": [ 28 | "> 1%", 29 | "last 2 versions", 30 | "not ie <= 8" 31 | ], 32 | "gitHooks": { 33 | "pre-commit": "lint-staged" 34 | }, 35 | "lint-staged": { 36 | "*.js": [ 37 | "vue-cli-service lint", 38 | "git add" 39 | ], 40 | "*.vue": [ 41 | "vue-cli-service lint", 42 | "git add" 43 | ] 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /example/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullah/vuex-module-generator/d4ba2509533924f989529bc8e6aad4d73e434438/example/public/favicon.ico -------------------------------------------------------------------------------- /example/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | vmg-example 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/src/App.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 31 | -------------------------------------------------------------------------------- /example/src/api/index.js: -------------------------------------------------------------------------------- 1 | 2 | import shuffle from 'lodash.shuffle'; 3 | import customers from '../mock/customer.json'; 4 | 5 | export const fetchCustomers = makeError => new Promise((resolve, reject) => { 6 | setTimeout(() => { 7 | if (makeError) { 8 | reject(new Error('Unexpected error has been occured')); 9 | } else { 10 | resolve({ status: 200, data: shuffle(customers), meta: { } }); 11 | } 12 | }, 2000); 13 | }); 14 | 15 | export default { 16 | fetchCustomers, 17 | }; 18 | -------------------------------------------------------------------------------- /example/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullah/vuex-module-generator/d4ba2509533924f989529bc8e6aad4d73e434438/example/src/assets/logo.png -------------------------------------------------------------------------------- /example/src/components/Customer.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 57 | 58 | 66 | -------------------------------------------------------------------------------- /example/src/components/ModuleDetail.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 23 | -------------------------------------------------------------------------------- /example/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import App from './App.vue'; 3 | import router from './router'; 4 | import store from './store/index'; 5 | 6 | Vue.config.productionTip = false; 7 | 8 | new Vue({ 9 | router, 10 | store, 11 | render: h => h(App), 12 | }).$mount('#app'); 13 | -------------------------------------------------------------------------------- /example/src/mock/customer.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "first_name": "Jeffie", 5 | "last_name": "Buckerfield", 6 | "email": "jbuckerfield0@gmpg.org", 7 | "gender": "Male" 8 | }, 9 | { 10 | "id": 2, 11 | "first_name": "Kelly", 12 | "last_name": "Abramin", 13 | "email": "kabramin1@g.co", 14 | "gender": "Female" 15 | }, 16 | { 17 | "id": 3, 18 | "first_name": "Arnie", 19 | "last_name": "Courtier", 20 | "email": "acourtier2@yahoo.co.jp", 21 | "gender": "Male" 22 | }, 23 | { 24 | "id": 4, 25 | "first_name": "Aurthur", 26 | "last_name": "Marusik", 27 | "email": "amarusik3@cbsnews.com", 28 | "gender": "Male" 29 | }, 30 | { 31 | "id": 5, 32 | "first_name": "Hubert", 33 | "last_name": "Corbitt", 34 | "email": "hcorbitt4@yahoo.com", 35 | "gender": "Male" 36 | }, 37 | { 38 | "id": 6, 39 | "first_name": "Finlay", 40 | "last_name": "Codman", 41 | "email": "fcodman5@bing.com", 42 | "gender": "Male" 43 | }, 44 | { 45 | "id": 7, 46 | "first_name": "Suzanna", 47 | "last_name": "Doniso", 48 | "email": "sdoniso6@dailymotion.com", 49 | "gender": "Female" 50 | }, 51 | { 52 | "id": 8, 53 | "first_name": "Gal", 54 | "last_name": "Oliver-Paull", 55 | "email": "goliverpaull7@macromedia.com", 56 | "gender": "Male" 57 | }, 58 | { 59 | "id": 9, 60 | "first_name": "Dalli", 61 | "last_name": "MacCome", 62 | "email": "dmaccome8@dmoz.org", 63 | "gender": "Male" 64 | }, 65 | { 66 | "id": 10, 67 | "first_name": "Dayle", 68 | "last_name": "Moyer", 69 | "email": "dmoyer9@bing.com", 70 | "gender": "Female" 71 | }, 72 | { 73 | "id": 11, 74 | "first_name": "Connie", 75 | "last_name": "McGilmartin", 76 | "email": "cmcgilmartina@oakley.com", 77 | "gender": "Female" 78 | }, 79 | { 80 | "id": 12, 81 | "first_name": "Aguistin", 82 | "last_name": "MacKowle", 83 | "email": "amackowleb@senate.gov", 84 | "gender": "Male" 85 | }, 86 | { 87 | "id": 13, 88 | "first_name": "Lindon", 89 | "last_name": "Bambury", 90 | "email": "lbamburyc@networkadvertising.org", 91 | "gender": "Male" 92 | }, 93 | { 94 | "id": 14, 95 | "first_name": "Trace", 96 | "last_name": "Clemenson", 97 | "email": "tclemensond@github.io", 98 | "gender": "Male" 99 | }, 100 | { 101 | "id": 15, 102 | "first_name": "Emlynn", 103 | "last_name": "Vauter", 104 | "email": "evautere@rambler.ru", 105 | "gender": "Female" 106 | }, 107 | { 108 | "id": 16, 109 | "first_name": "Coop", 110 | "last_name": "Bandy", 111 | "email": "cbandyf@skyrock.com", 112 | "gender": "Male" 113 | }, 114 | { 115 | "id": 17, 116 | "first_name": "Caresse", 117 | "last_name": "Le Brum", 118 | "email": "clebrumg@ed.gov", 119 | "gender": "Female" 120 | }, 121 | { 122 | "id": 18, 123 | "first_name": "Dolley", 124 | "last_name": "Gentzsch", 125 | "email": "dgentzschh@weebly.com", 126 | "gender": "Female" 127 | }, 128 | { 129 | "id": 19, 130 | "first_name": "Rebeka", 131 | "last_name": "Smallshaw", 132 | "email": "rsmallshawi@blogger.com", 133 | "gender": "Female" 134 | }, 135 | { 136 | "id": 20, 137 | "first_name": "Onfre", 138 | "last_name": "Corter", 139 | "email": "ocorterj@hatena.ne.jp", 140 | "gender": "Male" 141 | }, 142 | { 143 | "id": 21, 144 | "first_name": "Fonsie", 145 | "last_name": "Syrett", 146 | "email": "fsyrettk@over-blog.com", 147 | "gender": "Male" 148 | }, 149 | { 150 | "id": 22, 151 | "first_name": "Alfie", 152 | "last_name": "Lackey", 153 | "email": "alackeyl@csmonitor.com", 154 | "gender": "Male" 155 | }, 156 | { 157 | "id": 23, 158 | "first_name": "Katerine", 159 | "last_name": "Marritt", 160 | "email": "kmarrittm@buzzfeed.com", 161 | "gender": "Female" 162 | }, 163 | { 164 | "id": 24, 165 | "first_name": "Mohammed", 166 | "last_name": "Geal", 167 | "email": "mgealn@marketwatch.com", 168 | "gender": "Male" 169 | }, 170 | { 171 | "id": 25, 172 | "first_name": "Huntington", 173 | "last_name": "Pymer", 174 | "email": "hpymero@artisteer.com", 175 | "gender": "Male" 176 | }, 177 | { 178 | "id": 26, 179 | "first_name": "Meggy", 180 | "last_name": "Pelchat", 181 | "email": "mpelchatp@google.com.br", 182 | "gender": "Female" 183 | }, 184 | { 185 | "id": 27, 186 | "first_name": "Antonius", 187 | "last_name": "Castanone", 188 | "email": "acastanoneq@opera.com", 189 | "gender": "Male" 190 | }, 191 | { 192 | "id": 28, 193 | "first_name": "Mona", 194 | "last_name": "Dugood", 195 | "email": "mdugoodr@smugmug.com", 196 | "gender": "Female" 197 | }, 198 | { 199 | "id": 29, 200 | "first_name": "Waylen", 201 | "last_name": "Cosford", 202 | "email": "wcosfords@google.ca", 203 | "gender": "Male" 204 | }, 205 | { 206 | "id": 30, 207 | "first_name": "Carlye", 208 | "last_name": "Woosnam", 209 | "email": "cwoosnamt@cloudflare.com", 210 | "gender": "Female" 211 | }, 212 | { 213 | "id": 31, 214 | "first_name": "Marga", 215 | "last_name": "Ianno", 216 | "email": "miannou@drupal.org", 217 | "gender": "Female" 218 | }, 219 | { 220 | "id": 32, 221 | "first_name": "Rosabelle", 222 | "last_name": "Peck", 223 | "email": "rpeckv@irs.gov", 224 | "gender": "Female" 225 | }, 226 | { 227 | "id": 33, 228 | "first_name": "Burt", 229 | "last_name": "Aylen", 230 | "email": "baylenw@china.com.cn", 231 | "gender": "Male" 232 | }, 233 | { 234 | "id": 34, 235 | "first_name": "Gusella", 236 | "last_name": "Kyrkeman", 237 | "email": "gkyrkemanx@studiopress.com", 238 | "gender": "Female" 239 | }, 240 | { 241 | "id": 35, 242 | "first_name": "Gleda", 243 | "last_name": "Chapell", 244 | "email": "gchapelly@cbsnews.com", 245 | "gender": "Female" 246 | }, 247 | { 248 | "id": 36, 249 | "first_name": "Cordi", 250 | "last_name": "Venditti", 251 | "email": "cvendittiz@google.de", 252 | "gender": "Female" 253 | }, 254 | { 255 | "id": 37, 256 | "first_name": "Rodd", 257 | "last_name": "Hryniewicz", 258 | "email": "rhryniewicz10@nasa.gov", 259 | "gender": "Male" 260 | }, 261 | { 262 | "id": 38, 263 | "first_name": "Blondell", 264 | "last_name": "Divill", 265 | "email": "bdivill11@pbs.org", 266 | "gender": "Female" 267 | }, 268 | { 269 | "id": 39, 270 | "first_name": "Chrissy", 271 | "last_name": "Colby", 272 | "email": "ccolby12@reddit.com", 273 | "gender": "Male" 274 | }, 275 | { 276 | "id": 40, 277 | "first_name": "Tamqrah", 278 | "last_name": "Pund", 279 | "email": "tpund13@discovery.com", 280 | "gender": "Female" 281 | }, 282 | { 283 | "id": 41, 284 | "first_name": "Sherlocke", 285 | "last_name": "Woodnutt", 286 | "email": "swoodnutt14@360.cn", 287 | "gender": "Male" 288 | }, 289 | { 290 | "id": 42, 291 | "first_name": "Zea", 292 | "last_name": "Gorton", 293 | "email": "zgorton15@google.ca", 294 | "gender": "Female" 295 | }, 296 | { 297 | "id": 43, 298 | "first_name": "Biddie", 299 | "last_name": "Aukland", 300 | "email": "baukland16@wix.com", 301 | "gender": "Female" 302 | }, 303 | { 304 | "id": 44, 305 | "first_name": "Tawsha", 306 | "last_name": "Avrahamian", 307 | "email": "tavrahamian17@wikipedia.org", 308 | "gender": "Female" 309 | }, 310 | { 311 | "id": 45, 312 | "first_name": "Levy", 313 | "last_name": "Veregan", 314 | "email": "lveregan18@go.com", 315 | "gender": "Male" 316 | }, 317 | { 318 | "id": 46, 319 | "first_name": "Bari", 320 | "last_name": "Arlott", 321 | "email": "barlott19@google.it", 322 | "gender": "Female" 323 | }, 324 | { 325 | "id": 47, 326 | "first_name": "Horace", 327 | "last_name": "Junkin", 328 | "email": "hjunkin1a@histats.com", 329 | "gender": "Male" 330 | }, 331 | { 332 | "id": 48, 333 | "first_name": "Rafaela", 334 | "last_name": "Corteney", 335 | "email": "rcorteney1b@cbslocal.com", 336 | "gender": "Female" 337 | }, 338 | { 339 | "id": 49, 340 | "first_name": "Bronny", 341 | "last_name": "Wansbury", 342 | "email": "bwansbury1c@wp.com", 343 | "gender": "Male" 344 | }, 345 | { 346 | "id": 50, 347 | "first_name": "Gibby", 348 | "last_name": "Billinge", 349 | "email": "gbillinge1d@icio.us", 350 | "gender": "Male" 351 | }, 352 | { 353 | "id": 51, 354 | "first_name": "Maegan", 355 | "last_name": "Bollard", 356 | "email": "mbollard1e@ustream.tv", 357 | "gender": "Female" 358 | }, 359 | { 360 | "id": 52, 361 | "first_name": "Corny", 362 | "last_name": "Mellers", 363 | "email": "cmellers1f@ucoz.ru", 364 | "gender": "Female" 365 | }, 366 | { 367 | "id": 53, 368 | "first_name": "Zachary", 369 | "last_name": "Maclaine", 370 | "email": "zmaclaine1g@lulu.com", 371 | "gender": "Male" 372 | }, 373 | { 374 | "id": 54, 375 | "first_name": "Edgardo", 376 | "last_name": "McNamara", 377 | "email": "emcnamara1h@webs.com", 378 | "gender": "Male" 379 | }, 380 | { 381 | "id": 55, 382 | "first_name": "Rosalynd", 383 | "last_name": "Innwood", 384 | "email": "rinnwood1i@baidu.com", 385 | "gender": "Female" 386 | }, 387 | { 388 | "id": 56, 389 | "first_name": "Hill", 390 | "last_name": "Iohananof", 391 | "email": "hiohananof1j@cbc.ca", 392 | "gender": "Male" 393 | }, 394 | { 395 | "id": 57, 396 | "first_name": "Irita", 397 | "last_name": "Carson", 398 | "email": "icarson1k@quantcast.com", 399 | "gender": "Female" 400 | }, 401 | { 402 | "id": 58, 403 | "first_name": "Gisele", 404 | "last_name": "Paolino", 405 | "email": "gpaolino1l@nps.gov", 406 | "gender": "Female" 407 | }, 408 | { 409 | "id": 59, 410 | "first_name": "Judd", 411 | "last_name": "Croke", 412 | "email": "jcroke1m@addthis.com", 413 | "gender": "Male" 414 | }, 415 | { 416 | "id": 60, 417 | "first_name": "Eva", 418 | "last_name": "Davley", 419 | "email": "edavley1n@delicious.com", 420 | "gender": "Female" 421 | }, 422 | { 423 | "id": 61, 424 | "first_name": "Clair", 425 | "last_name": "Watting", 426 | "email": "cwatting1o@usgs.gov", 427 | "gender": "Male" 428 | }, 429 | { 430 | "id": 62, 431 | "first_name": "Franzen", 432 | "last_name": "Haselup", 433 | "email": "fhaselup1p@lulu.com", 434 | "gender": "Male" 435 | }, 436 | { 437 | "id": 63, 438 | "first_name": "Leese", 439 | "last_name": "Pordal", 440 | "email": "lpordal1q@salon.com", 441 | "gender": "Female" 442 | }, 443 | { 444 | "id": 64, 445 | "first_name": "Colleen", 446 | "last_name": "Yggo", 447 | "email": "cyggo1r@bandcamp.com", 448 | "gender": "Female" 449 | }, 450 | { 451 | "id": 65, 452 | "first_name": "Harp", 453 | "last_name": "Delgado", 454 | "email": "hdelgado1s@php.net", 455 | "gender": "Male" 456 | }, 457 | { 458 | "id": 66, 459 | "first_name": "Hyatt", 460 | "last_name": "Duffy", 461 | "email": "hduffy1t@mysql.com", 462 | "gender": "Male" 463 | }, 464 | { 465 | "id": 67, 466 | "first_name": "Barb", 467 | "last_name": "Cronk", 468 | "email": "bcronk1u@bravesites.com", 469 | "gender": "Female" 470 | }, 471 | { 472 | "id": 68, 473 | "first_name": "Karita", 474 | "last_name": "Apthorpe", 475 | "email": "kapthorpe1v@tiny.cc", 476 | "gender": "Female" 477 | }, 478 | { 479 | "id": 69, 480 | "first_name": "Gray", 481 | "last_name": "Corker", 482 | "email": "gcorker1w@odnoklassniki.ru", 483 | "gender": "Male" 484 | }, 485 | { 486 | "id": 70, 487 | "first_name": "Fenelia", 488 | "last_name": "Tregale", 489 | "email": "ftregale1x@behance.net", 490 | "gender": "Female" 491 | }, 492 | { 493 | "id": 71, 494 | "first_name": "Meredeth", 495 | "last_name": "Hoyles", 496 | "email": "mhoyles1y@flickr.com", 497 | "gender": "Male" 498 | }, 499 | { 500 | "id": 72, 501 | "first_name": "Lindie", 502 | "last_name": "Anger", 503 | "email": "langer1z@ebay.co.uk", 504 | "gender": "Female" 505 | }, 506 | { 507 | "id": 73, 508 | "first_name": "Gwenny", 509 | "last_name": "Ellen", 510 | "email": "gellen20@huffingtonpost.com", 511 | "gender": "Female" 512 | }, 513 | { 514 | "id": 74, 515 | "first_name": "Annalise", 516 | "last_name": "Cullerne", 517 | "email": "acullerne21@behance.net", 518 | "gender": "Female" 519 | }, 520 | { 521 | "id": 75, 522 | "first_name": "Ewan", 523 | "last_name": "Artus", 524 | "email": "eartus22@elpais.com", 525 | "gender": "Male" 526 | }, 527 | { 528 | "id": 76, 529 | "first_name": "Kit", 530 | "last_name": "Rankling", 531 | "email": "krankling23@intel.com", 532 | "gender": "Male" 533 | }, 534 | { 535 | "id": 77, 536 | "first_name": "Price", 537 | "last_name": "Walkingshaw", 538 | "email": "pwalkingshaw24@craigslist.org", 539 | "gender": "Male" 540 | }, 541 | { 542 | "id": 78, 543 | "first_name": "Dorena", 544 | "last_name": "Ainslie", 545 | "email": "dainslie25@github.com", 546 | "gender": "Female" 547 | }, 548 | { 549 | "id": 79, 550 | "first_name": "Isidora", 551 | "last_name": "Bleddon", 552 | "email": "ibleddon26@angelfire.com", 553 | "gender": "Female" 554 | }, 555 | { 556 | "id": 80, 557 | "first_name": "Margette", 558 | "last_name": "Lamble", 559 | "email": "mlamble27@skype.com", 560 | "gender": "Female" 561 | }, 562 | { 563 | "id": 81, 564 | "first_name": "Burt", 565 | "last_name": "Minihan", 566 | "email": "bminihan28@google.com", 567 | "gender": "Male" 568 | }, 569 | { 570 | "id": 82, 571 | "first_name": "Dre", 572 | "last_name": "Bome", 573 | "email": "dbome29@sciencedaily.com", 574 | "gender": "Female" 575 | }, 576 | { 577 | "id": 83, 578 | "first_name": "Elroy", 579 | "last_name": "Hanscome", 580 | "email": "ehanscome2a@indiatimes.com", 581 | "gender": "Male" 582 | }, 583 | { 584 | "id": 84, 585 | "first_name": "Ella", 586 | "last_name": "Taunton.", 587 | "email": "etaunton2b@ihg.com", 588 | "gender": "Female" 589 | }, 590 | { 591 | "id": 85, 592 | "first_name": "Mirelle", 593 | "last_name": "Attwater", 594 | "email": "mattwater2c@dagondesign.com", 595 | "gender": "Female" 596 | }, 597 | { 598 | "id": 86, 599 | "first_name": "Sandro", 600 | "last_name": "Wiggin", 601 | "email": "swiggin2d@washington.edu", 602 | "gender": "Male" 603 | }, 604 | { 605 | "id": 87, 606 | "first_name": "Cort", 607 | "last_name": "Randlesome", 608 | "email": "crandlesome2e@nytimes.com", 609 | "gender": "Male" 610 | }, 611 | { 612 | "id": 88, 613 | "first_name": "Ira", 614 | "last_name": "Legister", 615 | "email": "ilegister2f@ifeng.com", 616 | "gender": "Female" 617 | }, 618 | { 619 | "id": 89, 620 | "first_name": "Lincoln", 621 | "last_name": "Pickthorn", 622 | "email": "lpickthorn2g@ifeng.com", 623 | "gender": "Male" 624 | }, 625 | { 626 | "id": 90, 627 | "first_name": "Romola", 628 | "last_name": "Baldacchi", 629 | "email": "rbaldacchi2h@reference.com", 630 | "gender": "Female" 631 | }, 632 | { 633 | "id": 91, 634 | "first_name": "Dorine", 635 | "last_name": "Allott", 636 | "email": "dallott2i@cnbc.com", 637 | "gender": "Female" 638 | }, 639 | { 640 | "id": 92, 641 | "first_name": "Barby", 642 | "last_name": "Fronczak", 643 | "email": "bfronczak2j@cmu.edu", 644 | "gender": "Female" 645 | }, 646 | { 647 | "id": 93, 648 | "first_name": "Gerardo", 649 | "last_name": "Kummerlowe", 650 | "email": "gkummerlowe2k@mayoclinic.com", 651 | "gender": "Male" 652 | }, 653 | { 654 | "id": 94, 655 | "first_name": "Alwyn", 656 | "last_name": "Streatley", 657 | "email": "astreatley2l@eepurl.com", 658 | "gender": "Male" 659 | }, 660 | { 661 | "id": 95, 662 | "first_name": "Erek", 663 | "last_name": "Kollach", 664 | "email": "ekollach2m@addtoany.com", 665 | "gender": "Male" 666 | }, 667 | { 668 | "id": 96, 669 | "first_name": "Melina", 670 | "last_name": "Cotterill", 671 | "email": "mcotterill2n@ted.com", 672 | "gender": "Female" 673 | }, 674 | { 675 | "id": 97, 676 | "first_name": "Cheri", 677 | "last_name": "Baytrop", 678 | "email": "cbaytrop2o@irs.gov", 679 | "gender": "Female" 680 | }, 681 | { 682 | "id": 98, 683 | "first_name": "Myca", 684 | "last_name": "Cran", 685 | "email": "mcran2p@omniture.com", 686 | "gender": "Male" 687 | }, 688 | { 689 | "id": 99, 690 | "first_name": "Rodrique", 691 | "last_name": "Sapsforde", 692 | "email": "rsapsforde2q@bluehost.com", 693 | "gender": "Male" 694 | }, 695 | { 696 | "id": 100, 697 | "first_name": "Jeannette", 698 | "last_name": "Slucock", 699 | "email": "jslucock2r@mozilla.com", 700 | "gender": "Female" 701 | } 702 | ] 703 | -------------------------------------------------------------------------------- /example/src/router.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Router from 'vue-router'; 3 | import Home from './views/Home.vue'; 4 | 5 | Vue.use(Router); 6 | 7 | export default new Router({ 8 | routes: [ 9 | { 10 | path: '/', 11 | name: 'home', 12 | component: Home, 13 | }, 14 | ], 15 | }); 16 | -------------------------------------------------------------------------------- /example/src/store/Customer.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-param-reassign */ 2 | import { fetchCustomers } from '@/api/index'; 3 | import { createCrudActions, createCrudActionTypes, createCrudMutation, createCrudState } from 'vuex-module-generator'; 4 | 5 | 6 | export const types = { 7 | ...createCrudActionTypes('CUSTOMER'), 8 | }; 9 | 10 | export const actions = createCrudActions(types); 11 | 12 | export default { 13 | state: { ...createCrudState() }, 14 | mutations: { ...createCrudMutation(types) }, 15 | actions: { 16 | cleanCustomers({ commit }) { 17 | commit(actions.clean.list()); 18 | }, 19 | async fetchCustomers({ commit }, makeError = false) { 20 | commit(actions.index.request()); 21 | try { 22 | const res = await fetchCustomers(makeError); 23 | const { data, meta } = res; 24 | commit(actions.index.success({ data, meta })); 25 | return { data, meta }; 26 | } catch (error) { 27 | commit(actions.index.failure({ message: error.message })); 28 | return Promise.reject(error); 29 | } 30 | }, 31 | }, 32 | }; 33 | -------------------------------------------------------------------------------- /example/src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Vuex from 'vuex'; 3 | import Customer from './Customer'; 4 | 5 | Vue.use(Vuex); 6 | 7 | export default new Vuex.Store({ 8 | modules: { 9 | Customer, 10 | }, 11 | }); 12 | -------------------------------------------------------------------------------- /example/src/views/Home.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 21 | 22 | 31 | -------------------------------------------------------------------------------- /example/vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | baseUrl: process.env.NODE_ENV === 'production' 3 | ? '/vuex-module-generator/' 4 | : '/', 5 | }; 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vuex-module-generator", 3 | "version": "1.0.8", 4 | "main": "dist/vue-module-factory.min.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "build": "webpack-cli", 8 | "unit": "jest --config test/jest.conf.js --coverage" 9 | }, 10 | "dependencies": {}, 11 | "devDependencies": { 12 | "babel-core": "^6.26.3", 13 | "babel-jest": "^23.4.0", 14 | "babel-loader": "^7.1.5", 15 | "babel-preset-env": "^1.7.0", 16 | "babel-preset-stage-2": "^6.24.1", 17 | "jest": "^23.4.0", 18 | "webpack": "^4.36.1", 19 | "webpack-cli": "^3.3.6" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/action/__tests__/clone.actions.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createCloneActionTypes, 3 | createCloneActions 4 | } from '../../'; 5 | 6 | 7 | describe('CRUD ACTIONS', () => { 8 | let actions; 9 | 10 | beforeEach(() => { 11 | actions = createCloneActions(createCloneActionTypes('TEST')); 12 | }); 13 | 14 | it('should work with clone request, success, failure', () => { 15 | const { id, data } = actions.clone.request(1, { test: 1 }); 16 | expect(id).toEqual(1); 17 | expect(data.test).toEqual(1); 18 | const { data: dataSuccess } = actions.clone.success({ cloneSuccess: 1 }); 19 | expect(dataSuccess.cloneSuccess).toEqual(1); 20 | const { error } = actions.clone.failure({ test: 1 }); 21 | expect(error.test).toEqual(1); 22 | }); 23 | 24 | it('should work with clone request, success, failure without prop', () => { 25 | const { id, data } = actions.clone.request(1); 26 | expect(id).toEqual(1); 27 | expect(data).toEqual({}); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /src/action/__tests__/crud.actions.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createCrudActionTypes, 3 | createCrudActions 4 | } from '../../'; 5 | 6 | 7 | describe('CRUD ACTIONS', () => { 8 | let actions; 9 | 10 | beforeEach(() => { 11 | actions = createCrudActions(createCrudActionTypes('TEST')); 12 | }); 13 | 14 | it('should work with index request, success, failure', () => { 15 | const { data } = actions.index.success({ data: 1 }); 16 | expect(data).toEqual(1); 17 | const { error } = actions.index.failure({ test: 1 }); 18 | expect(error.test).toEqual(1); 19 | }); 20 | 21 | it('should work with show request, success, failure', () => { 22 | const { id } = actions.show.request(1); 23 | expect(id).toEqual(1); 24 | const { data } = actions.show.success({ data: 1 }); 25 | expect(data).toEqual(1); 26 | const { error } = actions.show.failure({ test: 1 }); 27 | expect(error.test).toEqual(1); 28 | }); 29 | 30 | it('should work with create request, success, failure', () => { 31 | const { formData } = actions.create.request({ test: 1 }); 32 | expect(formData.test).toEqual(1); 33 | const { data } = actions.create.success({ test: 1 }); 34 | expect(data.test).toEqual(1); 35 | const { error } = actions.create.failure({ test: 1 }); 36 | expect(error.test).toEqual(1); 37 | }); 38 | 39 | 40 | it('should work with update request, success, failure', () => { 41 | const { id, formData } = actions.update.request(1, { test: 1 }); 42 | expect(formData.test).toEqual(1); 43 | expect(id).toEqual(1); 44 | const { error } = actions.update.failure({ test: 1 }); 45 | expect(error.test).toEqual(1); 46 | }); 47 | 48 | 49 | it('should work with destroy request, success, failure', () => { 50 | const { data } = actions.destroy.request({ test: 1 }); 51 | expect(data.test).toEqual(1); 52 | expect(actions.destroy.success().payload).toBeUndefined(); 53 | const { error } = actions.destroy.failure({ test: 1 }); 54 | expect(error.test).toEqual(1); 55 | }); 56 | 57 | it('should work with active request, success, failure', () => { 58 | const { id } = actions.active.select(1); 59 | expect(id).toEqual(1); 60 | const { data } = actions.active.update(1); 61 | expect(data).toEqual(1); 62 | expect(actions.active.clear().payload).toBeUndefined(); 63 | }); 64 | }); 65 | -------------------------------------------------------------------------------- /src/action/__tests__/export.actions.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createExportActionTypes, 3 | createExportActions 4 | } from '../../'; 5 | 6 | 7 | describe('CRUD ACTIONS', () => { 8 | let actions; 9 | 10 | beforeEach(() => { 11 | actions = createExportActions(createExportActionTypes('TEST')); 12 | }); 13 | 14 | it('should work with export request, success, failure', () => { 15 | const { exportData } = actions.export.request({ test: 1 }); 16 | expect(exportData.test).toEqual(1); 17 | const { data: dataSuccess } = actions.export.success({ exportSuccess: 1 }); 18 | expect(dataSuccess.exportSuccess).toEqual(1); 19 | const { error } = actions.export.failure({ test: 1 }); 20 | expect(error.test).toEqual(1); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /src/action/__tests__/import.actions.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createImportActionTypes, 3 | createImportActions 4 | } from '../../'; 5 | 6 | 7 | describe('CRUD ACTIONS', () => { 8 | let actions; 9 | 10 | beforeEach(() => { 11 | actions = createImportActions(createImportActionTypes('TEST')); 12 | }); 13 | 14 | it('should work with import request, success, failure', () => { 15 | const { data } = actions.import.request({ test: 1 }); 16 | expect(data.test).toEqual(1); 17 | const { data: dataSuccess } = actions.import.success({ importSuccess: 1 }); 18 | expect(dataSuccess.importSuccess).toEqual(1); 19 | const { error } = actions.import.failure({ test: 1 }); 20 | expect(error.test).toEqual(1); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /src/action/__tests__/move.actions.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createMoveActionTypes, 3 | createMoveActions 4 | } from '../../'; 5 | 6 | 7 | describe('CRUD ACTIONS', () => { 8 | let actions; 9 | 10 | beforeEach(() => { 11 | actions = createMoveActions(createMoveActionTypes('TEST')); 12 | }); 13 | 14 | it('should work with move request, success, failure', () => { 15 | const { moveData } = actions.move.request({ test: 1 }); 16 | expect(moveData.test).toEqual(1); 17 | const { data: dataSuccess } = actions.move.success({ moveSuccess: 1 }); 18 | expect(dataSuccess.moveSuccess).toEqual(1); 19 | const { error } = actions.move.failure({ test: 1 }); 20 | expect(error.test).toEqual(1); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /src/action/__tests__/sort.actions.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createSortActionTypes, 3 | createSortActions 4 | } from '../../'; 5 | 6 | 7 | describe('CRUD ACTIONS', () => { 8 | let actions; 9 | 10 | beforeEach(() => { 11 | actions = createSortActions(createSortActionTypes('TEST')); 12 | }); 13 | 14 | it('should work with sort request, success, failure', () => { 15 | const { sortData } = actions.sort.request({ test: 1 }); 16 | expect(sortData.test).toEqual(1); 17 | const { data: dataSuccess } = actions.sort.success({ sortSuccess: 1 }); 18 | expect(dataSuccess.sortSuccess).toEqual(1); 19 | const { error } = actions.sort.failure({ test: 1 }); 20 | expect(error.test).toEqual(1); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /src/action/clone.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates Clone Action Creators 3 | * @param {object} TYPES 4 | * @return {object} 5 | */ 6 | import createAction from './plain'; 7 | 8 | export default function createCloneActions(TYPES) { 9 | const { CLONE } = TYPES; 10 | 11 | return { 12 | clone: { 13 | request: (id, data = {}) => createAction(CLONE.REQUEST, { id, data }), 14 | success: data => createAction(CLONE.SUCCESS, { data }), 15 | failure: error => createAction(CLONE.FAILURE, { error }) 16 | } 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /src/action/crud.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates CRUD Action Creators 3 | * @param {object} TYPES 4 | * @return {object} 5 | */ 6 | import createAction from './plain'; 7 | 8 | export default function createCrudActions(TYPES) { 9 | const { 10 | INDEX, SHOW, CREATE, UPDATE, DESTROY, ACTIVE, CLEAN 11 | } = TYPES; 12 | 13 | return { 14 | clean: { 15 | list: () => createAction(CLEAN.LIST), 16 | active: () => createAction(CLEAN.ACTIVE), 17 | destroy: () => createAction(CLEAN.DESTROY) 18 | }, 19 | index: { 20 | request: () => createAction(INDEX.REQUEST), 21 | success: ({ data, meta }) => createAction(INDEX.SUCCESS, { data, meta }), 22 | failure: error => createAction(INDEX.FAILURE, { error }) 23 | }, 24 | 25 | show: { 26 | request: id => createAction(SHOW.REQUEST, { id }), 27 | success: ({ data, meta }) => createAction(SHOW.SUCCESS, { data, meta }), 28 | failure: error => createAction(SHOW.FAILURE, { error }) 29 | }, 30 | 31 | create: { 32 | request: formData => createAction(CREATE.REQUEST, { formData }), 33 | success: data => createAction(CREATE.SUCCESS, { data }), 34 | failure: error => createAction(CREATE.FAILURE, { error }) 35 | }, 36 | 37 | update: { 38 | request: (id, formData) => createAction(UPDATE.REQUEST, { id, formData }), 39 | success: ({ data, meta }) => createAction(UPDATE.SUCCESS, { data, meta }), 40 | failure: error => createAction(UPDATE.FAILURE, { error }) 41 | }, 42 | 43 | destroy: { 44 | request: data => createAction(DESTROY.REQUEST, { data }), 45 | success: data => createAction(DESTROY.SUCCESS, { data }), 46 | failure: error => createAction(DESTROY.FAILURE, { error }) 47 | }, 48 | 49 | active: { 50 | select: id => createAction(ACTIVE.SELECT, { id }), 51 | update: data => createAction(ACTIVE.UPDATE, { data }), 52 | clear: () => createAction(ACTIVE.CLEAR) 53 | } 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /src/action/export.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates Export Action Creators 3 | * @param {object} TYPES 4 | * @return {object} 5 | */ 6 | import createAction from './plain'; 7 | 8 | export default function createExportActions(TYPES) { 9 | const { EXPORT } = TYPES; 10 | 11 | return { 12 | export: { 13 | request: exportData => createAction(EXPORT.REQUEST, { exportData }), 14 | success: data => createAction(EXPORT.SUCCESS, { data }), 15 | failure: error => createAction(EXPORT.FAILURE, { error }) 16 | } 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /src/action/import.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates Import Action Creators 3 | * @param {object} TYPES 4 | * @return {object} 5 | */ 6 | import createAction from './plain'; 7 | 8 | export default function createImportActions(TYPES) { 9 | const { IMPORT } = TYPES; 10 | 11 | return { 12 | import: { 13 | request: data => createAction(IMPORT.REQUEST, { data }), 14 | success: data => createAction(IMPORT.SUCCESS, { data }), 15 | failure: error => createAction(IMPORT.FAILURE, { error }) 16 | } 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /src/action/move.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates Move Action Creators 3 | * @param {object} TYPES 4 | * @return {object} 5 | */ 6 | import createAction from './plain'; 7 | 8 | export default function createMoveActions(TYPES) { 9 | const { MOVE } = TYPES; 10 | 11 | return { 12 | move: { 13 | request: moveData => createAction(MOVE.REQUEST, { moveData }), 14 | success: data => createAction(MOVE.SUCCESS, { data }), 15 | failure: error => createAction(MOVE.FAILURE, { error }) 16 | } 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /src/action/plain.js: -------------------------------------------------------------------------------- 1 | const createAction = (type, payload = {}) => ({ 2 | type, 3 | ...payload 4 | }); 5 | 6 | export default createAction; 7 | -------------------------------------------------------------------------------- /src/action/sort.js: -------------------------------------------------------------------------------- 1 | import createAction from './plain'; 2 | 3 | export default function createSortActions(TYPES) { 4 | const { SORT } = TYPES; 5 | 6 | return { 7 | sort: { 8 | request: sortData => createAction(SORT.REQUEST, { sortData }), 9 | success: data => createAction(SORT.SUCCESS, { data }), 10 | failure: error => createAction(SORT.FAILURE, { error }) 11 | } 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | // CRUD Factories 2 | export { default as createCrudActions } from './action/crud'; 3 | export { default as createCrudActionTypes } from './type/crud'; 4 | export { default as createCrudMutation } from './mutations/crud'; 5 | export { default as createCrudState } from './state/crud'; 6 | 7 | // Sort Factories 8 | export { default as createSortActions } from './action/sort'; 9 | export { default as createSortActionTypes } from './type/sort'; 10 | export { default as createSortMutation } from './mutations/sort'; 11 | export { default as createSortState } from './state/sort'; 12 | 13 | // Clone Factories 14 | export { default as createCloneActions } from './action/clone'; 15 | export { default as createCloneActionTypes } from './type/clone'; 16 | export { default as createCloneMutation } from './mutations/clone'; 17 | export { default as createCloneState } from './state/clone'; 18 | 19 | // Move Factories 20 | export { default as createMoveActions } from './action/move'; 21 | export { default as createMoveActionTypes } from './type/move'; 22 | export { default as createMoveMutation } from './mutations/move'; 23 | export { default as createMoveState } from './state/move'; 24 | 25 | // Import Factories 26 | export { default as createImportActions } from './action/import'; 27 | export { default as createImportActionTypes } from './type/import'; 28 | export { default as createImportMutation } from './mutations/import'; 29 | export { default as createImportState } from './state/import'; 30 | 31 | // Export Factories 32 | export { default as createExportActions } from './action/export'; 33 | export { default as createExportActionTypes } from './type/export'; 34 | export { default as createExportMutation } from './mutations/export'; 35 | export { default as createExportState } from './state/export'; 36 | 37 | // Generic Factories 38 | export { default as createAsyncActionTypes } from './type/async'; 39 | export { default as createAction } from './action/plain'; 40 | -------------------------------------------------------------------------------- /src/mutations/__tests__/clone.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createCloneActions, 3 | createCloneActionTypes, 4 | createCloneMutation, 5 | createCloneState 6 | } from '../../'; 7 | 8 | 9 | describe('CRUD ACTIONS', () => { 10 | let actions; 11 | let types; 12 | let mutations; 13 | let state; 14 | 15 | beforeEach(() => { 16 | types = createCloneActionTypes('TEST'); 17 | actions = createCloneActions(types); 18 | mutations = createCloneMutation(types); 19 | state = createCloneState(); 20 | }); 21 | 22 | it('should work clone request mutation with recived params', () => { 23 | const payload = actions.clone.request(1, { test: 1 }); 24 | mutations[types.CLONE.REQUEST](state, payload); 25 | expect(state.cloning.id).toEqual(1); 26 | expect(state.cloning.data.test).toEqual(1); 27 | expect(state.cloning.isLoading).toEqual(true); 28 | expect(state.cloning.errors).toEqual({}); 29 | }); 30 | 31 | it('should work clone success mutation with recived params', () => { 32 | const payload = actions.clone.success({ test: 1 }); 33 | mutations[types.CLONE.SUCCESS](state, payload); 34 | expect(state.cloning.id).toEqual(''); 35 | expect(state.cloning.data.test).toEqual(1); 36 | expect(state.cloning.isLoading).toEqual(false); 37 | expect(state.cloning.errors).toEqual({}); 38 | }); 39 | 40 | it('should work clone failure mutation with recived params', () => { 41 | const payload = actions.clone.failure({ test: 1 }); 42 | mutations[types.CLONE.FAILURE](state, payload); 43 | expect(state.cloning.id).toEqual(''); 44 | expect(state.cloning.data).toEqual({}); 45 | expect(state.cloning.isLoading).toEqual(false); 46 | expect(state.cloning.errors.test).toEqual(1); 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /src/mutations/__tests__/crud.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createCrudActions, 3 | createCrudActionTypes, 4 | createCrudMutation, 5 | createCrudState 6 | } from '../../'; 7 | 8 | 9 | describe('CRUD MUTATIONS', () => { 10 | let actions; 11 | let types; 12 | let mutations; 13 | let state; 14 | 15 | beforeEach(() => { 16 | types = createCrudActionTypes('TEST'); 17 | actions = createCrudActions(types); 18 | mutations = createCrudMutation(types); 19 | state = createCrudState(); 20 | }); 21 | 22 | it('should work crud index request and mutations', () => { 23 | const payload = actions.index.request(); 24 | mutations[types.INDEX.REQUEST](state, payload); 25 | expect(state.list.isLoading).toEqual(true); 26 | expect(state.list.isLoaded).toEqual(false); 27 | expect(state.list.errors).toEqual({}); 28 | }); 29 | 30 | it('should work crud index request and mutations without params', () => { 31 | mutations[types.INDEX.REQUEST](state); 32 | expect(state.list.isLoading).toEqual(true); 33 | expect(state.list.isLoaded).toEqual(false); 34 | expect(state.list.errors).toEqual({}); 35 | }); 36 | 37 | it('should work crud index success and mutations', () => { 38 | const payload = actions.index.success({ data: 1 }); 39 | mutations[types.INDEX.SUCCESS](state, payload); 40 | expect(state.list.isLoading).toEqual(false); 41 | expect(state.list.isLoaded).toEqual(true); 42 | expect(state.list.errors).toEqual({}); 43 | expect(state.list.data).toEqual(1); 44 | }); 45 | 46 | it('should work crud index failure and mutations', () => { 47 | const payload = actions.index.failure({ data: 1 }); 48 | mutations[types.INDEX.FAILURE](state, payload); 49 | expect(state.list.isLoading).toEqual(false); 50 | expect(state.list.isLoaded).toEqual(false); 51 | expect(state.list.errors.data).toEqual(1); 52 | expect(state.list.data).toEqual([]); 53 | }); 54 | 55 | 56 | it('should work crud show request and mutations', () => { 57 | const payload = actions.show.request(1); 58 | mutations[types.SHOW.REQUEST](state, payload); 59 | expect(state.active.isLoading).toEqual(true); 60 | expect(state.active.isLoaded).toEqual(false); 61 | expect(state.active.errors).toEqual({}); 62 | expect(state.active.data).toEqual({}); 63 | }); 64 | 65 | it('should work crud show success and mutations', () => { 66 | const payload = actions.show.success({ data: 1 }); 67 | mutations[types.SHOW.SUCCESS](state, payload); 68 | expect(state.active.isLoading).toEqual(false); 69 | expect(state.active.isLoaded).toEqual(true); 70 | expect(state.active.errors).toEqual({}); 71 | expect(state.active.data).toEqual(1); 72 | }); 73 | 74 | it('should work crud show failure and mutations', () => { 75 | const payload = actions.show.failure({ data: 1 }); 76 | mutations[types.SHOW.FAILURE](state, payload); 77 | expect(state.active.isLoading).toEqual(false); 78 | expect(state.active.isLoaded).toEqual(true); 79 | expect(state.active.errors.data).toEqual(1); 80 | expect(state.active.data).toEqual({}); 81 | }); 82 | 83 | it('should work crud create request and mutations', () => { 84 | const payload = actions.create.request({ data: 1 }); 85 | mutations[types.CREATE.REQUEST](state, payload); 86 | expect(state.creating.isLoading).toEqual(true); 87 | expect(state.creating.errors).toEqual({}); 88 | expect(state.creating.formData.data).toEqual(1); 89 | }); 90 | 91 | it('should work crud create success and mutations', () => { 92 | const requestPayload = actions.create.request({ data: 1 }); 93 | const payload = actions.create.success({ data: 1 }); 94 | mutations[types.CREATE.REQUEST](state, requestPayload); 95 | mutations[types.CREATE.SUCCESS](state, payload); 96 | expect(state.creating.isLoading).toEqual(false); 97 | expect(state.creating.errors).toEqual({}); 98 | expect(state.creating.data.data).toEqual(1); 99 | expect(state.creating.formData.data).toEqual(1); 100 | }); 101 | 102 | it('should work crud create failure and mutations', () => { 103 | const requestPayload = actions.create.request({ data: 1 }); 104 | const payload = actions.create.failure({ data: 1 }); 105 | mutations[types.CREATE.REQUEST](state, requestPayload); 106 | mutations[types.CREATE.FAILURE](state, payload); 107 | expect(state.creating.isLoading).toEqual(false); 108 | expect(state.creating.errors.data).toEqual(1); 109 | expect(state.creating.data).toEqual({}); 110 | expect(state.creating.formData.data).toEqual(1); 111 | }); 112 | 113 | 114 | it('should work crud update request and mutations', () => { 115 | const requestPayload = actions.update.request(1, { data: 1 }); 116 | mutations[types.UPDATE.REQUEST](state, requestPayload); 117 | expect(state.updating.isLoading).toEqual(true); 118 | expect(state.updating.errors).toEqual({}); 119 | expect(state.updating.data).toEqual({}); 120 | expect(state.updating.formData.data).toEqual(1); 121 | }); 122 | 123 | it('should work crud update success and mutations', () => { 124 | const requestPayload = actions.update.request({ id: 1, formData: 1 }); 125 | const payload = actions.update.success({ data: 1 }); 126 | mutations[types.UPDATE.REQUEST](state, requestPayload); 127 | mutations[types.UPDATE.SUCCESS](state, payload); 128 | expect(state.updating.isLoading).toEqual(false); 129 | expect(state.updating.errors).toEqual({}); 130 | }); 131 | 132 | it('should work crud update failure and mutations', () => { 133 | const payload = actions.update.failure({ data: 1 }); 134 | mutations[types.UPDATE.FAILURE](state, payload); 135 | expect(state.updating.isLoading).toEqual(false); 136 | expect(state.updating.errors.data).toEqual(1); 137 | expect(state.updating.data).toEqual({}); 138 | expect(state.updating.formData).toEqual({}); 139 | }); 140 | 141 | it('should work crud destroy request and mutations', () => { 142 | const payload = actions.destroy.request({ data: 1 }); 143 | mutations[types.DESTROY.REQUEST](state, payload); 144 | expect(state.destroying.isLoading).toEqual(true); 145 | expect(state.destroying.errors).toEqual({}); 146 | expect(state.destroying.data.data).toEqual(1); 147 | }); 148 | 149 | it('should work crud destroy success and mutations', () => { 150 | const payload = actions.destroy.success({ data: 1 }); 151 | mutations[types.DESTROY.SUCCESS](state, payload); 152 | expect(state.destroying.isLoading).toEqual(false); 153 | expect(state.destroying.errors).toEqual({}); 154 | expect(state.destroying.data.data).toEqual(1); 155 | }); 156 | 157 | it('should work crud destroy failure and mutations', () => { 158 | const payload = actions.destroy.failure({ data: 1 }); 159 | mutations[types.DESTROY.FAILURE](state, payload); 160 | expect(state.destroying.isLoading).toEqual(false); 161 | expect(state.destroying.errors.data).toEqual(1); 162 | expect(state.destroying.data).toEqual({}); 163 | }); 164 | 165 | it('should work crud active select and mutations with empty param', () => { 166 | const payload = actions.active.select(); 167 | mutations[types.DESTROY.FAILURE](state, payload); 168 | expect(state.active.data).toEqual({}); 169 | }); 170 | 171 | it('should work crud active select and mutations with id', () => { 172 | state.list.data = [{ id: 1, name: 'data' }]; 173 | const payload = actions.active.select(1); 174 | mutations[types.ACTIVE.SELECT](state, payload); 175 | expect(state.active.data.name).toEqual('data'); 176 | }); 177 | 178 | it('should work crud active select and mutations without id', () => { 179 | state.list.data = [{ id: 1, name: 'data' }]; 180 | const payload = actions.active.select(); 181 | mutations[types.ACTIVE.SELECT](state, payload); 182 | expect(state.active.data).toEqual({}); 183 | }); 184 | 185 | it('should work crud active clear and mutations', () => { 186 | state.list.data = [{ id: 1, name: 'data' }]; 187 | const payload = actions.active.select(1); 188 | mutations[types.ACTIVE.SELECT](state, payload); 189 | expect(state.active.data.name).toEqual('data'); 190 | const clearPayload = actions.active.clear(); 191 | mutations[types.ACTIVE.CLEAR](state, clearPayload); 192 | expect(state.active.data).toEqual({}); 193 | }); 194 | 195 | it('should work crud active update and mutations', () => { 196 | state.list.data = [{ id: 1, name: 'data' }]; 197 | const payload = actions.active.select(1); 198 | mutations[types.ACTIVE.SELECT](state, payload); 199 | expect(state.active.data.name).toEqual('data'); 200 | const clearPayload = actions.active.update({ name: 'name2' }); 201 | mutations[types.ACTIVE.UPDATE](state, clearPayload); 202 | expect(state.active.data.name).toEqual('name2'); 203 | }); 204 | }); 205 | -------------------------------------------------------------------------------- /src/mutations/__tests__/export.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createExportActions, 3 | createExportActionTypes, 4 | createExportMutation, 5 | createExportState 6 | } from '../../'; 7 | 8 | 9 | describe('EXPORT MUTATIOn', () => { 10 | let actions; 11 | let types; 12 | let mutations; 13 | let state; 14 | 15 | beforeEach(() => { 16 | types = createExportActionTypes('TEST'); 17 | actions = createExportActions(types); 18 | mutations = createExportMutation(types); 19 | state = createExportState(); 20 | }); 21 | 22 | it('should work export request and mutation', () => { 23 | const payload = actions.export.request({ test: 1 }); 24 | mutations[types.EXPORT.REQUEST](state, payload); 25 | expect(state.exporting.exportData.test).toEqual(1); 26 | expect(state.exporting.data).toEqual({}); 27 | expect(state.exporting.isLoading).toEqual(true); 28 | expect(state.exporting.errors).toEqual({}); 29 | }); 30 | 31 | 32 | it('should work export success and mutation', () => { 33 | const payload = actions.export.success({ test: 1 }); 34 | mutations[types.EXPORT.SUCCESS](state, payload); 35 | expect(state.exporting.exportData).toEqual({}); 36 | expect(state.exporting.data.test).toEqual(1); 37 | expect(state.exporting.isLoading).toEqual(false); 38 | expect(state.exporting.errors).toEqual({}); 39 | }); 40 | 41 | it('should work export failure and mutation', () => { 42 | const payload = actions.export.failure({ test: 1 }); 43 | mutations[types.EXPORT.FAILURE](state, payload); 44 | expect(state.exporting.exportData).toEqual({}); 45 | expect(state.exporting.data).toEqual({}); 46 | expect(state.exporting.isLoading).toEqual(false); 47 | expect(state.exporting.errors.test).toEqual(1); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /src/mutations/__tests__/import.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createImportActions, 3 | createImportActionTypes, 4 | createImportMutation, 5 | createImportState 6 | } from '../../'; 7 | 8 | 9 | describe('IMPORT MUTATION', () => { 10 | let actions; 11 | let types; 12 | let mutations; 13 | let state; 14 | 15 | beforeEach(() => { 16 | types = createImportActionTypes('TEST'); 17 | actions = createImportActions(types); 18 | mutations = createImportMutation(types); 19 | state = createImportState(); 20 | }); 21 | 22 | it('should work import request and mutation', () => { 23 | const payload = actions.import.request({ test: 1 }); 24 | mutations[types.IMPORT.REQUEST](state, payload); 25 | expect(state.importing.importData.test).toEqual(1); 26 | expect(state.importing.data).toEqual({}); 27 | expect(state.importing.isLoading).toEqual(true); 28 | expect(state.importing.errors).toEqual({}); 29 | }); 30 | 31 | 32 | it('should work import success and mutation', () => { 33 | const payload = actions.import.success({ test: 1 }); 34 | mutations[types.IMPORT.SUCCESS](state, payload); 35 | expect(state.importing.importData).toEqual({}); 36 | expect(state.importing.data.test).toEqual(1); 37 | expect(state.importing.isLoading).toEqual(false); 38 | expect(state.importing.errors).toEqual({}); 39 | }); 40 | 41 | it('should work import failure and mutation', () => { 42 | const payload = actions.import.failure({ test: 1 }); 43 | mutations[types.IMPORT.FAILURE](state, payload); 44 | expect(state.importing.importData).toEqual({}); 45 | expect(state.importing.data).toEqual({}); 46 | expect(state.importing.isLoading).toEqual(false); 47 | expect(state.importing.errors.test).toEqual(1); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /src/mutations/__tests__/move.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createMoveActions, 3 | createMoveActionTypes, 4 | createMoveMutation, 5 | createMoveState 6 | } from '../../'; 7 | 8 | 9 | describe('MOVE MUTATION', () => { 10 | let actions; 11 | let types; 12 | let mutations; 13 | let state; 14 | 15 | beforeEach(() => { 16 | types = createMoveActionTypes('TEST'); 17 | actions = createMoveActions(types); 18 | mutations = createMoveMutation(types); 19 | state = createMoveState(); 20 | }); 21 | 22 | it('should work move request and mutation', () => { 23 | const payload = actions.move.request({ test: 1 }); 24 | mutations[types.MOVE.REQUEST](state, payload); 25 | expect(state.moving.moveData.test).toEqual(1); 26 | expect(state.moving.data).toEqual({}); 27 | expect(state.moving.isLoading).toEqual(true); 28 | expect(state.moving.errors).toEqual({}); 29 | }); 30 | 31 | 32 | it('should work move success and mutation', () => { 33 | const payload = actions.move.success({ test: 1 }); 34 | mutations[types.MOVE.SUCCESS](state, payload); 35 | expect(state.moving.moveData).toEqual({}); 36 | expect(state.moving.data.test).toEqual(1); 37 | expect(state.moving.isLoading).toEqual(false); 38 | expect(state.moving.errors).toEqual({}); 39 | }); 40 | 41 | it('should work move failure and mutation', () => { 42 | const payload = actions.move.failure({ test: 1 }); 43 | mutations[types.MOVE.FAILURE](state, payload); 44 | expect(state.moving.moveData).toEqual({}); 45 | expect(state.moving.data).toEqual({}); 46 | expect(state.moving.isLoading).toEqual(false); 47 | expect(state.moving.errors.test).toEqual(1); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /src/mutations/__tests__/sort.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createSortActions, 3 | createSortActionTypes, 4 | createSortMutation, 5 | createSortState 6 | } from '../../'; 7 | 8 | 9 | describe('SORT MUTATION', () => { 10 | let actions; 11 | let types; 12 | let mutations; 13 | let state; 14 | 15 | beforeEach(() => { 16 | types = createSortActionTypes('TEST'); 17 | actions = createSortActions(types); 18 | mutations = createSortMutation(types); 19 | state = createSortState(); 20 | }); 21 | 22 | it('should work sort request and mutation', () => { 23 | const payload = actions.sort.request({ test: 1 }); 24 | mutations[types.SORT.REQUEST](state, payload); 25 | expect(state.sorting.sortData.test).toEqual(1); 26 | expect(state.sorting.data).toEqual({}); 27 | expect(state.sorting.isLoading).toEqual(true); 28 | expect(state.sorting.errors).toEqual({}); 29 | }); 30 | 31 | 32 | it('should work sort success and mutation', () => { 33 | const payload = actions.sort.success({ test: 1 }); 34 | mutations[types.SORT.SUCCESS](state, payload); 35 | expect(state.sorting.sortData).toEqual({}); 36 | expect(state.sorting.data.test).toEqual(1); 37 | expect(state.sorting.isLoading).toEqual(false); 38 | expect(state.sorting.errors).toEqual({}); 39 | }); 40 | 41 | it('should work sort failure and mutation', () => { 42 | const payload = actions.sort.failure({ test: 1 }); 43 | mutations[types.SORT.FAILURE](state, payload); 44 | expect(state.sorting.sortData).toEqual({}); 45 | expect(state.sorting.data).toEqual({}); 46 | expect(state.sorting.isLoading).toEqual(false); 47 | expect(state.sorting.errors.test).toEqual(1); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /src/mutations/clone.js: -------------------------------------------------------------------------------- 1 | 2 | function createCloneMutation(ACTION_TYPES) { 3 | return { 4 | [ACTION_TYPES.CLONE.REQUEST](state, payload) { 5 | state.cloning = { 6 | id: payload.id, 7 | data: payload.data, 8 | isLoading: true, 9 | hasError: false, 10 | errors: {} 11 | }; 12 | }, 13 | 14 | [ACTION_TYPES.CLONE.SUCCESS](state, payload) { 15 | state.cloning = { 16 | ...state.cloning, 17 | isLoading: false, 18 | hasError: false, 19 | data: payload.data, 20 | errors: {} 21 | }; 22 | }, 23 | 24 | [ACTION_TYPES.CLONE.FAILURE](state, payload) { 25 | state.cloning = { 26 | ...state.cloning, 27 | isLoading: false, 28 | hasError: true, 29 | errors: payload.error 30 | }; 31 | } 32 | }; 33 | } 34 | 35 | export default createCloneMutation; 36 | -------------------------------------------------------------------------------- /src/mutations/crud.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-param-reassign */ 2 | import crudState from '../state/crud'; 3 | 4 | function createCrudMutation(ACTION_TYPES) { 5 | return { 6 | // CLEAN 7 | [ACTION_TYPES.CLEAN.LIST](state) { 8 | state.list = { ...crudState().list }; 9 | }, 10 | [ACTION_TYPES.CLEAN.ACTIVE](state) { 11 | state.active = { ...crudState().active }; 12 | }, 13 | [ACTION_TYPES.CLEAN.DESTROY](state) { 14 | state.destroying = { ...crudState().destroying }; 15 | }, 16 | // INDEX 17 | [ACTION_TYPES.INDEX.REQUEST](state) { 18 | state.list.isLoading = true; 19 | state.list.hasError = false; 20 | state.list.errors = {}; 21 | }, 22 | [ACTION_TYPES.INDEX.SUCCESS](state, payload) { 23 | state.list.isLoading = false; 24 | state.list.isLoaded = true; 25 | state.list.hasError = false; 26 | state.list.data = payload.data; 27 | state.list.meta = payload.meta; 28 | state.list.errors = {}; 29 | }, 30 | [ACTION_TYPES.INDEX.FAILURE](state, payload) { 31 | state.list.isLoading = false; 32 | state.list.isLoaded = false; 33 | state.list.hasError = true; 34 | state.list.data = []; 35 | state.list.meta = {}; 36 | state.list.errors = payload.error; 37 | }, 38 | 39 | // SHOW 40 | [ACTION_TYPES.SHOW.REQUEST](state) { 41 | state.active = { 42 | ...state.active, 43 | isLoading: true, 44 | hasError: false, 45 | errors: {} 46 | }; 47 | }, 48 | [ACTION_TYPES.SHOW.SUCCESS](state, payload) { 49 | state.active = { 50 | ...state.active, 51 | isLoading: false, 52 | hasError: false, 53 | isLoaded: true, 54 | data: payload.data, 55 | meta: payload.meta, 56 | errors: {} 57 | }; 58 | }, 59 | [ACTION_TYPES.SHOW.FAILURE](state, payload) { 60 | state.active = { 61 | ...state.active, 62 | isLoading: false, 63 | hasError: true, 64 | isLoaded: true, 65 | errors: payload.error 66 | }; 67 | }, 68 | // CREATE 69 | [ACTION_TYPES.CREATE.REQUEST](state, payload) { 70 | state.creating = { 71 | ...state.creating, 72 | formData: payload.formData, 73 | isLoading: true, 74 | hasError: false, 75 | errors: {} 76 | }; 77 | }, 78 | [ACTION_TYPES.CREATE.SUCCESS](state, payload) { 79 | state.creating = { 80 | ...state.creating, 81 | data: payload.data, 82 | isLoading: false, 83 | hasError: false, 84 | errors: {} 85 | }; 86 | }, 87 | [ACTION_TYPES.CREATE.FAILURE](state, payload) { 88 | state.creating = { 89 | ...state.creating, 90 | isLoading: false, 91 | hasError: true, 92 | isLoaded: true, 93 | errors: payload.error 94 | }; 95 | }, 96 | // UPDATE 97 | [ACTION_TYPES.UPDATE.REQUEST](state, payload) { 98 | state.updating = { 99 | ...state.updating, 100 | id: payload.id, 101 | formData: payload.formData, 102 | isLoading: true, 103 | hasError: false, 104 | errors: {} 105 | }; 106 | }, 107 | [ACTION_TYPES.UPDATE.SUCCESS](state, payload) { 108 | state.active = { 109 | isLoading: false, 110 | hasError: false, 111 | isLoaded: true, 112 | data: payload.data, 113 | errors: {} 114 | }; 115 | state.updating = { 116 | ...state.updating, 117 | data: payload.data, 118 | isLoading: false, 119 | hasError: false, 120 | errors: {} 121 | }; 122 | }, 123 | [ACTION_TYPES.UPDATE.FAILURE](state, payload) { 124 | state.updating = { 125 | ...state.updating, 126 | isLoading: false, 127 | hasError: true, 128 | errors: payload.error 129 | }; 130 | }, 131 | // DESTROY 132 | [ACTION_TYPES.DESTROY.REQUEST](state, payload) { 133 | state.destroying = { 134 | ...state.destroying, 135 | data: payload.data, 136 | isLoading: true, 137 | hasError: false, 138 | errors: {} 139 | }; 140 | }, 141 | [ACTION_TYPES.DESTROY.SUCCESS](state, payload) { 142 | state.active = { 143 | ...state.active, 144 | isLoaded: false, 145 | data: {} 146 | }; 147 | state.destroying = { 148 | isLoading: false, 149 | hasError: false, 150 | data: payload.data, 151 | errors: {} 152 | }; 153 | }, 154 | [ACTION_TYPES.DESTROY.FAILURE](state, payload) { 155 | state.destroying = { 156 | ...state.destroying, 157 | isLoading: false, 158 | hasError: true, 159 | errors: payload.error 160 | }; 161 | }, 162 | // ACTIVE 163 | [ACTION_TYPES.ACTIVE.SELECT](state, payload) { 164 | state.active = { 165 | isLoading: false, 166 | hasError: false, 167 | isLoaded: true, 168 | data: state.list.data 169 | .find(item => parseInt(item.id, 10) === parseInt(payload.id, 10)) || {}, 170 | errors: {} 171 | }; 172 | }, 173 | [ACTION_TYPES.ACTIVE.UPDATE](state, payload) { 174 | state.active = { 175 | isLoading: false, 176 | isLoaded: true, 177 | hasError: false, 178 | data: payload.data, 179 | errors: {} 180 | }; 181 | }, 182 | [ACTION_TYPES.ACTIVE.CLEAR](state) { 183 | state.active = { 184 | isLoading: false, 185 | isLoaded: false, 186 | hasError: false, 187 | data: {}, 188 | errors: {} 189 | }; 190 | } 191 | }; 192 | } 193 | 194 | export default createCrudMutation; 195 | -------------------------------------------------------------------------------- /src/mutations/export.js: -------------------------------------------------------------------------------- 1 | 2 | function createImportMutation(ACTION_TYPES) { 3 | return { 4 | [ACTION_TYPES.EXPORT.REQUEST](state, payload) { 5 | state.exporting = { 6 | data: {}, 7 | exportData: payload.exportData, 8 | errors: {}, 9 | isLoading: true, 10 | hasError: false, 11 | }; 12 | }, 13 | 14 | [ACTION_TYPES.EXPORT.SUCCESS](state, payload) { 15 | state.exporting = { 16 | ...state.exporting, 17 | data: payload.data, 18 | isLoading: false, 19 | hasError: false, 20 | errors: {} 21 | }; 22 | }, 23 | 24 | [ACTION_TYPES.EXPORT.FAILURE](state, payload) { 25 | state.exporting = { 26 | ...state.exporting, 27 | isLoading: false, 28 | hasError: true, 29 | errors: payload.error 30 | }; 31 | } 32 | }; 33 | } 34 | 35 | export default createImportMutation; 36 | -------------------------------------------------------------------------------- /src/mutations/import.js: -------------------------------------------------------------------------------- 1 | 2 | function createImportMutation(ACTION_TYPES) { 3 | return { 4 | [ACTION_TYPES.IMPORT.REQUEST](state, payload) { 5 | state.importing = { 6 | data: {}, 7 | importData: payload.data, 8 | errors: {}, 9 | isLoading: true, 10 | hasError: false, 11 | }; 12 | }, 13 | 14 | [ACTION_TYPES.IMPORT.SUCCESS](state, payload) { 15 | state.importing = { 16 | ...state.importing, 17 | data: payload.data, 18 | isLoading: false, 19 | hasError: false, 20 | errors: {} 21 | }; 22 | }, 23 | 24 | [ACTION_TYPES.IMPORT.FAILURE](state, payload) { 25 | state.importing = { 26 | ...state.importing, 27 | isLoading: false, 28 | hasError: true, 29 | errors: payload.error 30 | }; 31 | } 32 | }; 33 | } 34 | 35 | export default createImportMutation; 36 | -------------------------------------------------------------------------------- /src/mutations/move.js: -------------------------------------------------------------------------------- 1 | 2 | function createMoveMutation(ACTION_TYPES) { 3 | return { 4 | [ACTION_TYPES.MOVE.REQUEST](state, payload) { 5 | state.moving = { 6 | ...state.moving, 7 | moveData: payload.moveData, 8 | isLoading: true, 9 | hasError: false, 10 | }; 11 | }, 12 | 13 | [ACTION_TYPES.MOVE.SUCCESS](state, payload) { 14 | state.moving = { 15 | ...state.moving, 16 | isLoading: false, 17 | hasError: false, 18 | data: payload.data, 19 | errors: {} 20 | }; 21 | }, 22 | 23 | [ACTION_TYPES.MOVE.FAILURE](state, payload) { 24 | state.moving = { 25 | ...state.moving, 26 | isLoading: false, 27 | hasError: true, 28 | errors: payload.error 29 | }; 30 | } 31 | }; 32 | } 33 | 34 | export default createMoveMutation; 35 | -------------------------------------------------------------------------------- /src/mutations/sort.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-param-reassign */ 2 | 3 | function createSortMutation(ACTION_TYPES) { 4 | return { 5 | [ACTION_TYPES.SORT.REQUEST](state, payload) { 6 | state.sorting = { 7 | ...state.sorting, 8 | sortData: payload.sortData || {}, 9 | isLoading: true, 10 | hasError: false, 11 | }; 12 | }, 13 | 14 | [ACTION_TYPES.SORT.SUCCESS](state, payload) { 15 | state.sorting = { 16 | ...state.sorting, 17 | isLoading: false, 18 | hasError: false, 19 | data: payload.data || {}, 20 | errors: {} 21 | }; 22 | }, 23 | 24 | [ACTION_TYPES.SORT.FAILURE](state, payload) { 25 | state.sorting = { 26 | ...state.sorting, 27 | isLoading: false, 28 | hasError: true, 29 | errors: payload.error 30 | }; 31 | } 32 | }; 33 | } 34 | 35 | export default createSortMutation; 36 | -------------------------------------------------------------------------------- /src/state/clone.js: -------------------------------------------------------------------------------- 1 | export default function createCloneState() { 2 | return { 3 | cloning: { 4 | id: '', 5 | isLoading: false, 6 | hasError: false, 7 | data: {}, 8 | errors: {} 9 | } 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /src/state/crud.js: -------------------------------------------------------------------------------- 1 | export default function createCrudState(extraState = {}) { 2 | return { 3 | list: { 4 | isLoading: false, 5 | hasError: false, 6 | isLoaded: false, 7 | meta: {}, 8 | data: [], 9 | errors: {} 10 | }, 11 | 12 | active: { 13 | isLoading: false, 14 | hasError: false, 15 | isLoaded: false, 16 | data: {}, 17 | meta: {}, 18 | errors: {} 19 | }, 20 | 21 | creating: { 22 | isLoading: false, 23 | hasError: false, 24 | formData: {}, 25 | data: {}, 26 | errors: {} 27 | }, 28 | 29 | updating: { 30 | isLoading: false, 31 | hasError: false, 32 | id: '', 33 | formData: {}, 34 | data: {}, 35 | errors: {} 36 | }, 37 | 38 | destroying: { 39 | isLoading: false, 40 | hasError: false, 41 | data: {}, 42 | errors: {} 43 | }, 44 | ...extraState 45 | }; 46 | } 47 | -------------------------------------------------------------------------------- /src/state/export.js: -------------------------------------------------------------------------------- 1 | export default function createExportState() { 2 | return { 3 | exporting: { 4 | isLoading: false, 5 | hasError: false, 6 | data: {}, 7 | exportData: {}, 8 | errors: {} 9 | } 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /src/state/import.js: -------------------------------------------------------------------------------- 1 | export default function createImportState() { 2 | return { 3 | importing: { 4 | isLoading: false, 5 | hasError: false, 6 | data: {}, 7 | importData: {}, 8 | errors: {} 9 | } 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /src/state/move.js: -------------------------------------------------------------------------------- 1 | export default function createMoveState() { 2 | return { 3 | moving: { 4 | isLoading: false, 5 | hasError: false, 6 | moveData: {}, 7 | data: {}, 8 | errors: {} 9 | } 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /src/state/sort.js: -------------------------------------------------------------------------------- 1 | export default function createSortState() { 2 | return { 3 | sorting: { 4 | isLoading: false, 5 | hasError: false, 6 | sortData: {}, 7 | data: {}, 8 | errors: {} 9 | } 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /src/type/__tests__/types.test.js: -------------------------------------------------------------------------------- 1 | import { 2 | createCrudActionTypes, 3 | createSortActionTypes, 4 | createCloneActionTypes, 5 | createMoveActionTypes, 6 | createImportActionTypes, 7 | createExportActionTypes, 8 | createAsyncActionTypes 9 | } from '../../'; 10 | 11 | 12 | describe('ACTION TYPES', () => { 13 | it('should generate correct crud action name', () => { 14 | const types = createCrudActionTypes('TEST'); 15 | expect(types.INDEX.REQUEST).toEqual('TEST/INDEX_REQUEST'); 16 | expect(types.INDEX.SUCCESS).toEqual('TEST/INDEX_SUCCESS'); 17 | }); 18 | 19 | it('should generate correct sort action name', () => { 20 | const types = createSortActionTypes('TEST'); 21 | expect(types.SORT.REQUEST).toEqual('TEST/SORT_REQUEST'); 22 | expect(types.SORT.SUCCESS).toEqual('TEST/SORT_SUCCESS'); 23 | }); 24 | 25 | it('should generate correct clone action name', () => { 26 | const types = createCloneActionTypes('TEST'); 27 | expect(types.CLONE.REQUEST).toEqual('TEST/CLONE_REQUEST'); 28 | expect(types.CLONE.SUCCESS).toEqual('TEST/CLONE_SUCCESS'); 29 | }); 30 | 31 | it('should generate correct move action name', () => { 32 | const types = createMoveActionTypes('TEST'); 33 | expect(types.MOVE.REQUEST).toEqual('TEST/MOVE_REQUEST'); 34 | expect(types.MOVE.SUCCESS).toEqual('TEST/MOVE_SUCCESS'); 35 | }); 36 | 37 | it('should generate correct import action name', () => { 38 | const types = createImportActionTypes('TEST'); 39 | expect(types.IMPORT.REQUEST).toEqual('TEST/IMPORT_REQUEST'); 40 | expect(types.IMPORT.SUCCESS).toEqual('TEST/IMPORT_SUCCESS'); 41 | }); 42 | 43 | 44 | it('should generate correct export action name', () => { 45 | const types = createExportActionTypes('TEST'); 46 | expect(types.EXPORT.REQUEST).toEqual('TEST/EXPORT_REQUEST'); 47 | expect(types.EXPORT.SUCCESS).toEqual('TEST/EXPORT_SUCCESS'); 48 | }); 49 | 50 | it('should generate correct async action name', () => { 51 | const types = createAsyncActionTypes('TEST', 'BOMB'); 52 | expect(types.REQUEST).toEqual('TEST/BOMB_REQUEST'); 53 | expect(types.SUCCESS).toEqual('TEST/BOMB_SUCCESS'); 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /src/type/active.js: -------------------------------------------------------------------------------- 1 | function createActiveActionType(moduleName) { 2 | return { 3 | SELECT: `${moduleName}/SELECT_ACTIVE`, 4 | UPDATE: `${moduleName}/UPDATE_ACTIVE`, 5 | CLEAR: `${moduleName}/CLEAR_ACTIVE` 6 | }; 7 | } 8 | 9 | export default createActiveActionType; 10 | -------------------------------------------------------------------------------- /src/type/async.js: -------------------------------------------------------------------------------- 1 | function createAsyncActionType(moduleName, actionName) { 2 | return { 3 | REQUEST: `${moduleName}/${actionName}_REQUEST`, 4 | SUCCESS: `${moduleName}/${actionName}_SUCCESS`, 5 | FAILURE: `${moduleName}/${actionName}_FAILURE` 6 | }; 7 | } 8 | 9 | export default createAsyncActionType; 10 | -------------------------------------------------------------------------------- /src/type/clone.js: -------------------------------------------------------------------------------- 1 | import createAsyncActionType from './async'; 2 | 3 | export default function createCloneActionTypes(moduleName) { 4 | return { 5 | CLONE: createAsyncActionType(moduleName, 'CLONE') 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /src/type/crud.js: -------------------------------------------------------------------------------- 1 | import createAsyncActionType from './async'; 2 | import createActiveActionType from './active'; 3 | 4 | export default function createCrudActionTypes(moduleName) { 5 | return { 6 | CLEAN: { 7 | LIST: `${moduleName}/LIST_CLEAN`, 8 | ACTIVE: `${moduleName}/ACTIVE_CLEAN`, 9 | DESTROY: `${moduleName}/DESTROY_CLEAN` 10 | }, 11 | INDEX: createAsyncActionType(moduleName, 'INDEX'), 12 | SHOW: createAsyncActionType(moduleName, 'SHOW'), 13 | CREATE: createAsyncActionType(moduleName, 'CREATE'), 14 | UPDATE: createAsyncActionType(moduleName, 'UPDATE'), 15 | DESTROY: createAsyncActionType(moduleName, 'DESTROY'), 16 | ACTIVE: createActiveActionType(moduleName) 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /src/type/export.js: -------------------------------------------------------------------------------- 1 | import createAsyncActionType from './async'; 2 | 3 | export default function createExportActionTypes(moduleName) { 4 | return { 5 | EXPORT: createAsyncActionType(moduleName, 'EXPORT') 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /src/type/import.js: -------------------------------------------------------------------------------- 1 | import createAsyncActionType from './async'; 2 | 3 | export default function createImportActionTypes(moduleName) { 4 | return { 5 | IMPORT: createAsyncActionType(moduleName, 'IMPORT') 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /src/type/move.js: -------------------------------------------------------------------------------- 1 | import createAsyncActionType from './async'; 2 | 3 | export default function createMoveActionTypes(moduleName) { 4 | return { 5 | MOVE: createAsyncActionType(moduleName, 'MOVE') 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /src/type/sort.js: -------------------------------------------------------------------------------- 1 | import createAsyncActionType from './async'; 2 | 3 | export default function createSortActionTypes(moduleName) { 4 | return { 5 | SORT: createAsyncActionType(moduleName, 'SORT') 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /test/jest.conf.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | rootDir: path.resolve(__dirname, '../'), 5 | moduleFileExtensions: [ 6 | 'js', 7 | ], 8 | moduleNameMapper: { 9 | '^@/(.*)$': '/src/$1' 10 | }, 11 | transform: { 12 | '^.+\\.js$': '/node_modules/babel-jest', 13 | }, 14 | coverageDirectory: '/test/unit/coverage', 15 | collectCoverageFrom: [ 16 | 'src/**/*.{js}', 17 | '!test/**', 18 | ] 19 | }; 20 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | mode: "production", 5 | entry: "./src/index.js", 6 | output: { 7 | path: path.resolve(__dirname, "dist"), 8 | filename: "vue-module-factory.min.js", 9 | library: "VuexModuleFactory", 10 | libraryTarget: "umd", 11 | }, 12 | module: { 13 | rules: [ 14 | { 15 | test: /\.jsx?$/, 16 | loader: "babel-loader", 17 | }, 18 | ], 19 | }, 20 | resolve: { 21 | extensions: [".js"], 22 | }, 23 | devtool: "source-map", 24 | target: "web", 25 | } 26 | --------------------------------------------------------------------------------