{"id":22879321,"url":"https://github.com/anthinkingcoder/vuex-loading","last_synced_at":"2025-03-31T14:33:41.916Z","repository":{"id":96074889,"uuid":"144676415","full_name":"anthinkingcoder/vuex-loading","owner":"anthinkingcoder","description":"Simplify vuex loading state management","archived":false,"fork":false,"pushed_at":"2019-04-24T12:32:04.000Z","size":22,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-07T19:16:29.316Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anthinkingcoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-08-14T06:12:48.000Z","updated_at":"2020-07-30T17:22:51.000Z","dependencies_parsed_at":"2024-01-02T23:39:11.375Z","dependency_job_id":"cfd6e160-6ccb-4e27-886f-b929bd43c605","html_url":"https://github.com/anthinkingcoder/vuex-loading","commit_stats":{"total_commits":17,"total_committers":2,"mean_commits":8.5,"dds":"0.11764705882352944","last_synced_commit":"4188a84d5ef7657a4063d23c0611badee459c24c"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthinkingcoder%2Fvuex-loading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthinkingcoder%2Fvuex-loading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthinkingcoder%2Fvuex-loading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthinkingcoder%2Fvuex-loading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anthinkingcoder","download_url":"https://codeload.github.com/anthinkingcoder/vuex-loading/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246483554,"owners_count":20784912,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-13T16:38:54.251Z","updated_at":"2025-03-31T14:33:41.893Z","avatar_url":"https://github.com/anthinkingcoder.png","language":"JavaScript","funding_links":[],"categories":["Components \u0026 Libraries","Utilities","Utilities [🔝](#readme)"],"sub_categories":["Utilities","State Management"],"readme":"# vuex-loading\nSimplify vuex loading state management\n\n## Installing\n\nUsing npm:\n\n```bash\n$ npm install vuex-loadings -s\n```\n## Know\nSimplify vuex loading state management need two step:\n\n1.use ```vxl.aopLoading(commit,loadingName,fn,isPromise)``` to proxy fn, simplify loading state change                    \n          \n2.use ```vxl.mixin({state,getters,mutations},stateObj)``` to automatic set loading state,loading getter,loading mutation for stateObj\n\n## Example\n```js\n//product.js\nimport vxl from 'vuex-loadings'\nconst api = {\n  //callback\n  listProduct (cb,errorCb) {\n    fetch('/api/listProduct').then((result) =\u003e {\n      cb(result)\n    }).catch(error =\u003e {\n      errorCb(error)\n    })\n  },\n  //promise\n  productDetail (id) {\n    return fetch(`/api/productDetail?id=${id}`)\n  }\n}\nconst state = {\n  products: [],\n  productDetail: {}\n}\n\nconst getters = {\n  products (state) {\n    return state.products\n  }\n}\n\n//vxl.aopLoading(commit, loadingName, fn, isPromise)\n//isPromise = true, fn must be a promise\n// isPromise = false, fn must be receiver two argument, cb and errorCb function\nconst actions = {\n  listProduct ({{commit}}) {\n    //proxy callback\n    let request = vxl.aopLoading(commit, 'productsLoading',api.listProduct)\n    request((result) =\u003e {\n      commit('setProducts', result)\n    }, error =\u003e {\n    })\n    //it equal\n    //commit('setProductsLoading',true)\n    //api.listProduct((result) =\u003e {\n    //        commit('setProductsLoading',false)\n    //        commit('setProducts', result)\n    //      }, error =\u003e {\n    //        commit('setProductsLoading',false)\n    //      })\n  },\n  productDetail ({{commit}}) {\n    //proxy promise\n    let request = vxl.aopLoading(commit, 'productDetail', api.productDetail,true)\n    request(1).then((result) =\u003e {\n         commit('setProducts', result)\n    }).catch(error =\u003e {\n      console.info(error)\n    })\n    \n    //it equal\n    //commit('setProductDetailLoading',true)\n    //api.productDetail(1)\n    //      .then(result =\u003e {\n    //            commit('setProductDetailLoading',false)\n    //            commit('setProducts', result)})    \n    //      .catch(error =\u003e {\n    //            commit('setProductDetailLoading',false)\n    //            console.info(error)\n    //            })\n  }\n}\n\nconst mutations = {\n  setProducts (state, item) {\n    state.products = item\n  },\n  setProductDetail(state, item) {\n    state.productDetail = item\n  }\n}\n\n//it will be set loading state,loading getter,loading mutation for products,productDetail\n//default loading name is productsLoading,productDetailLoading\nvxl.mixin({state,getters,mutations}, ['products','productDetail'])\n\n//or custom loading state name\nvxl.mixin({state,getters,mutations}, [{'products':'productsLoading'},'productDetail'])\n\nexport default {\n  namespaced: true,\n  state,\n  getters,\n  actions,\n  mutations\n}\n```\n### other way\n\n```js\nimport {aopLoading, mapLoadingMutations, mapLoadingState, mapLoadingGetters} from '../vuex-loading'\nconst api = {\n  listProduct (cb,errorCb) {\n    fetch('/api/listProduct').then((result) =\u003e {\n      cb(result)\n    }).catch(error =\u003e {\n      errorCb(error)\n    })\n  }\n}\nconst state = {\n  ...mapLoadingState({\n    clues: {},\n  })\n  //it will be -\u003e {\n  // clues: {}\n  // cluesLoading: {}\n  //}\n}\n\n\nconst getters = {\n  clues(state) {\n    return state.clues\n  },\n  \n  // set getter function for cluesLoading\n  ...mapLoadingGetters(['cluesLoading'])\n  //or custom getter function name\n  ...mapLoadingGetters({'cluesLoading': 'getCluesLoading'})\n}\n\nconst actions = {\n  listClue({commit}) {\n    //the same\n    let request = aopLoading(commit, 'cluesLoading', marketApi.listClue)\n    request(items =\u003e {\n          commit('setClues', {items})\n        },\n        error =\u003e {\n        })\n  },\n}\n\nconst mutations = {\n  setClues(state, {items}) {\n    state.clues = items\n  },\n  //set mutation function for cluesLoading\n  ...mapLoadingMutations(['cluesLoading'])\n}\n\n\nexport default {\n  namespaced: true,\n  state,\n  getters,\n  actions,\n  mutations\n}\n```\n\n```vue\n//product.vue\n\u003ctemplate\u003e\n    \u003cdiv\u003e{{productsLoading}}\u003c/div\u003e\n\u003c/template\u003e\nimport {mapGetters} from 'vuex'\n\u003cscript\u003e\n    export default {\n      computed: {\n        ...mapGetters ('product', ['productsLoading'])\n      }\n      data () {\n        return {\n          \n        }\n      },\n      \n    }\n\u003c/script\u003e\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthinkingcoder%2Fvuex-loading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanthinkingcoder%2Fvuex-loading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthinkingcoder%2Fvuex-loading/lists"}