{"id":13511377,"url":"https://github.com/herculesJS/herculex","last_synced_at":"2025-03-30T20:33:09.217Z","repository":{"id":73025745,"uuid":"151963302","full_name":"herculesJS/herculex","owner":"herculesJS","description":"Predictable state container for alipay mini-program inspired by vuex, redux, immutableJS,elm,rxjs","archived":false,"fork":false,"pushed_at":"2021-05-29T08:53:06.000Z","size":151,"stargazers_count":69,"open_issues_count":27,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-08-02T03:07:56.349Z","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/herculesJS.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2018-10-07T16:51:54.000Z","updated_at":"2024-07-02T01:37:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"bcefd225-c304-46bc-a862-6ded6456de6d","html_url":"https://github.com/herculesJS/herculex","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herculesJS%2Fherculex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herculesJS%2Fherculex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herculesJS%2Fherculex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herculesJS%2Fherculex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/herculesJS","download_url":"https://codeload.github.com/herculesJS/herculex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222581265,"owners_count":17006322,"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-08-01T03:00:48.718Z","updated_at":"2024-11-01T13:30:54.135Z","avatar_url":"https://github.com/herculesJS.png","language":"JavaScript","funding_links":[],"categories":["mini-programe"],"sub_categories":[],"readme":"# herculeX\nSimple, predictable, lightweight, high performance, developer friendly state management for alipay mini-program\n\n![setData (1).png](https://cdn.nlark.com/lark/0/2018/png/82549/1537904366328-49a7e2e5-5aeb-4326-be5f-8cf0eb603181.png) \n\n## Feature\n\n- [x] Component, Page, global wrapper\n- [x] vuex-like apis and concept: actions, mutations, getters, plugins\n- [x] strengthen mutation, getters: add immutable helper, global power to getters.and improve mutation usecase, add some common innerMutation\n- [x] plugins support, add logger as inner plugin\n- [x] cross page communication: message channel, auto router dispatcher(manage router ), get ready-only State by namespace\n- [x] cross components communication: support centralized ref management\n- [x] connect: connect Page to Component, add mapStateToProps, mapGettersToProps, use more developer friendly way.\n- [x] mapHelpers: connect actions and mutations to Page, Componnet methods\n- [x] global store support: manage all store, component instance and global state, global message bus ,event bus\n- [x] event bus support\n- [x] router: improve router usecase, auto router dispatcher, add resume lifecycle\n- [x] utils: immutable heplers, common functional tools, urlParser, promiseWrapper... \n- [x] use immer and immutable helper to promise immutable\n- [x] magic memoization: add special memoization feature to mapHelpersToProps\n\n## Installation\n\n* Installation: `npm install herculex --save`.\n* basic usage:\n  * index.js\n  ``` \n  import store from './store';\n  const app = getApp();\n  Page(store.register({\n    mapActionsToMethod: ['getUserInfo'],\n    mapMutationsToMethod: ['helperWay'],\n    onLoad() {\n     const message = this.$message.pop('card-home');\n     // get message from last page as you like\n    },\n    onReady() {\n      const componentInstance = this.$getRef('card-input');\n      // get component ref, then get data when you need ,specially in form condition\n    },\n    onResume(ctx) {\n     // get ctx here, \n    },\n    ...\n    onTap() {\n    }\n  })\n  ```\n  * store.js\n  ```\n   export default new Store({\n   connectGlobal: true,\n   state: {\n       userInfo: {},\n       bannerList: [],\n       UI,\n    },\n   getters: {\n    // functional promgraming, add some helpers\n    cardCount: (state, getters, global) =\u003e global.getIn(['entity', 'cardList', 'length'], 0),\n    avatar: state =\u003e state.getIn(['userInfo', 'iconUrl'], ASSETS.DEFAULT_AVATAR),\n    nickName: state =\u003e state.getIn(['userInfo', 'nick']),\n    cardList: (state, getters, global) =\u003e global.getIn(['entity', 'cardList'], []).map(mapCardItemToData),\n   },\n   mutations: {\n     mutableWay(state, payload) {\n     // use immer promise immutable\n      state.a = payload.a\n     },\n     helperWay(state, payload) {\n       // use inner helper: setIn, deleteIn, update\n      return state.setIn(['userInfo', 'name'], payload.name)\n     }\n   },\n   plugins: [ 'logger' ], // inner plugin logger\n   actions: {\n     async getUserInfo({ commit, state, dispatch, global, getters, }, payload) {\n       // get router and context in global store, all state are binded immutable helper\n       const routerCtx = global.getIn(['router', 'currentRouter']);\n       const avatar = getters.getIn('avatar');\n       const userInfo = await cardListService.getUserInfo();\n       commit('getUserInfo', { userInfo });\n     },\n   },\n  });\n  ```\n  * index.axml\n  ```\n  \u003cview a:if=\"{{!!$global.entity.cardList}}\"\u003e\n    {{userInfo.name}}\n     \u003cnavigator a:if=\"{{$getters.cardCount \u003e 0}}\" class=\"link\" url=\"/pages/card-create/index\"\u003e\n        \u003cbutton type=\"primary\"\u003e{{UI.TEST}}\u003c/button\u003e\n     \u003c/navigator\u003e\n  \u003c/view\u003e\n  ```\n\n## Examples\n* appx (alipay mini program)\n  * quick start\n    * [Counter](https://github.com/herculesJS/herculex-appx-examples/tree/master/quick-start/pages/counter) : show basic usage as commit \u0026 dispatch\n    * [TODOS](https://github.com/herculesJS/herculex-appx-examples/tree/master/quick-start/pages/todos): show how components and modules work\n\n## Turtoral\n  \n## TODO\n- [ ] add pageBeforeRender Action to do something before instance created\n- [ ] add travis ci\n- [ ] add middleware support, take over api middleware\n- [ ] doc \u0026 gitbook,github.io\n- [ ] examples \u0026 boilerplate\n- [ ] cli for static code check, and generate snipets\n- [ ] ide plugin\n- [ ] model based api middleware\n- [ ] test-utils \u0026 mock helper\n- [ ] dev-tools for ide \u0026 standalone\n- [ ] modules (need deeply design)\n- [ ] error catcher plugin\n- [ ] refactory and tests, separate appx data setter as independent repo\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FherculesJS%2Fherculex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FherculesJS%2Fherculex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FherculesJS%2Fherculex/lists"}