├── .commitlintrc.js ├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .github ├── ISSUE_TEMPLATE │ ├── ---bug-report.md │ ├── ---documentation.md │ └── ---feature-suggestion.md └── workflows │ ├── codeql-analysis.yml │ └── test.yml ├── .gitignore ├── .npmrc ├── .release-it.json ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── LICENCE ├── README.md ├── babel.config.js ├── docs ├── .gitignore ├── docus.config.js ├── nuxt.config.js ├── package.json ├── pages │ └── en │ │ ├── 1.getting-started │ │ ├── 1.getting-started-nuxt.md │ │ └── 2.getting-started-vue.md │ │ ├── 1.index.md │ │ ├── 2.accessor │ │ ├── 1.accessor-introduction.md │ │ ├── 2.dynamic-modules.md │ │ └── 3.customisation.md │ │ ├── 3.store │ │ ├── 1.state.md │ │ ├── 2.getters.md │ │ ├── 3.mutations.md │ │ └── 4.actions.md │ │ └── 4.examples │ │ ├── 1.build.md │ │ ├── 2.runtime.md │ │ └── 3.vue.md └── static │ └── images │ ├── screenshot1.png │ └── screenshot2.png ├── examples ├── .gitignore ├── nuxt-ts │ ├── .editorconfig │ ├── components │ │ └── Logo.vue │ ├── index.d.ts │ ├── layouts │ │ └── default.vue │ ├── nuxt.config.ts │ ├── package.json │ ├── pages │ │ └── index.vue │ ├── static │ │ └── favicon.ico │ ├── store │ │ ├── index.ts │ │ └── submodule.ts │ └── tsconfig.json ├── nuxt │ ├── .editorconfig │ ├── components │ │ └── Logo.vue │ ├── index.d.ts │ ├── layouts │ │ └── default.vue │ ├── nuxt.config.js │ ├── package.json │ ├── pages │ │ ├── composition.vue │ │ └── index.vue │ ├── plugins │ │ └── composition-api.ts │ ├── prettier.config.js │ ├── static │ │ └── favicon.ico │ ├── store │ │ ├── index.ts │ │ └── submodule.ts │ └── tsconfig.json └── vue │ ├── .browserslistrc │ ├── .eslintrc.js │ ├── babel.config.js │ ├── package.json │ ├── postcss.config.js │ ├── public │ ├── favicon.ico │ └── index.html │ ├── src │ ├── App.vue │ ├── assets │ │ └── logo.png │ ├── components │ │ └── HelloWorld.vue │ ├── index.d.ts │ ├── main.ts │ ├── shims-tsx.d.ts │ ├── shims-vue.d.ts │ └── store │ │ ├── index.ts │ │ └── submodule.ts │ └── tsconfig.json ├── jest.config.js ├── lerna.json ├── package.json ├── packages ├── nuxt-typed-vuex │ ├── .babelrc.js │ ├── jest.config.js │ ├── package.json │ ├── src │ │ └── index.ts │ ├── template │ │ └── plugin.js │ ├── test │ │ ├── fixture │ │ │ ├── index.d.ts │ │ │ ├── layouts │ │ │ │ └── default.vue │ │ │ ├── nuxt.config.js │ │ │ ├── pages │ │ │ │ └── index.vue │ │ │ ├── store │ │ │ │ ├── index.ts │ │ │ │ ├── nuxt.ts │ │ │ │ └── submodule.ts │ │ │ └── tsconfig.json │ │ ├── index.test.ts │ │ └── module.test.ts │ └── tsconfig.json └── typed-vuex │ ├── .babelrc.js │ ├── jest.config.js │ ├── package.json │ ├── src │ ├── accessor.ts │ ├── index.ts │ ├── types │ │ ├── actions.ts │ │ ├── getters.ts │ │ ├── modules.ts │ │ ├── mutations.ts │ │ ├── state.ts │ │ ├── store.ts │ │ ├── utilities.ts │ │ └── utils.ts │ └── utils.ts │ ├── test │ ├── __snapshots__ │ │ ├── accessor.test.ts.snap │ │ └── utils.test.ts.snap │ ├── accessor.test.ts │ ├── fixture │ │ ├── index.ts │ │ └── submodule.ts │ ├── tsd │ │ ├── accessor.test-d.ts │ │ └── map-state.test-d.ts │ └── utils.test.ts │ └── tsconfig.json ├── pnpm-lock.yaml ├── pnpm-workspace.yaml ├── prettier.config.js ├── renovate.json ├── tsconfig.json └── vercel.json /.commitlintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | '@commitlint/config-conventional' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_size = 2 6 | indent_style = space 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | **/templates 2 | **/node_modules 3 | **/dist 4 | 5 | examples 6 | 7 | # Contains Lodash templates 8 | **/plugin.js 9 | 10 | **/lib 11 | **/test 12 | 13 | sw.js 14 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["plugin:@typescript-eslint/recommended"], 3 | "plugins": ["@typescript-eslint"], 4 | "rules": { 5 | "@typescript-eslint/ban-types": "off", 6 | "@typescript-eslint/explicit-function-return-type": "off", 7 | "@typescript-eslint/member-delimiter-style": "off", 8 | "@typescript-eslint/no-explicit-any": "off" 9 | }, 10 | "parserOptions": { 11 | "parser": "@typescript-eslint/parser", 12 | "tsconfigRootDir": "./src", 13 | "ecmaVersion": 11, 14 | "sourceType": "module" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/---bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41B Bug report" 3 | about: Something's not working 4 | title: 'fix: ' 5 | labels: bug 6 | assignees: danielroe 7 | 8 | --- 9 | 10 | **🐛 The bug** 11 | What isn't working? Describe what the bug is. 12 | 13 | **🛠️ To reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **🌈 Expected behaviour** 21 | What did you expect to happen? Is there a section in the docs about this? 22 | 23 | **ℹ️ Additional context** 24 | Add any other context about the problem here. 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/---documentation.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F4DA Documentation" 3 | about: How do I ... ? 4 | title: 'docs: ' 5 | labels: documentation 6 | assignees: danielroe 7 | 8 | --- 9 | 10 | **📚 Is your documentation request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I feel I should be able to [...] but I can't see how to do it from the docs. 12 | 13 | **🔍 Where should you find it?** 14 | What page of the docs do you expect this information to be found on? 15 | 16 | **ℹ️ Additional context** 17 | Add any other context or information. 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/---feature-suggestion.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F195 Feature suggestion" 3 | about: Suggest an idea 4 | title: 'feat: ' 5 | labels: enhancement 6 | assignees: danielroe 7 | 8 | --- 9 | 10 | **🆒 Your use case** 11 | Add a description of your use case, and how this feature would help you. 12 | > Ex. When I do [...] I would expect to be able to do [...] 13 | 14 | **🆕 The solution you'd like** 15 | Describe what you want to happen. 16 | 17 | **🔍 Alternatives you've considered** 18 | Have you considered any alternative solutions or features? 19 | 20 | **ℹ️ Additional info** 21 | Is there any other context you think would be helpful to know? 22 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: "codeql" 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | schedule: 9 | - cron: '16 4 * * 4' 10 | 11 | jobs: 12 | analyze: 13 | name: Analyze 14 | runs-on: ubuntu-latest 15 | permissions: 16 | actions: read 17 | contents: read 18 | security-events: write 19 | 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | language: [ 'javascript' ] 24 | 25 | steps: 26 | - name: Checkout repository 27 | uses: actions/checkout@v2 28 | 29 | # Initializes the CodeQL tools for scanning. 30 | - name: Initialize CodeQL 31 | uses: github/codeql-action/init@v2 32 | with: 33 | languages: ${{ matrix.language }} 34 | # If you wish to specify custom queries, you can do so here or in a config file. 35 | # By default, queries listed here will override any specified in a config file. 36 | # Prefix the list here with "+" to use these queries and those in the config file. 37 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 38 | 39 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 40 | # If this step fails, then you should remove it and run the build manually (see below) 41 | - name: Autobuild 42 | uses: github/codeql-action/autobuild@v2 43 | 44 | # ℹ️ Command-line programs to run using the OS shell. 45 | # 📚 https://git.io/JvXDl 46 | 47 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 48 | # and modify them (or add more) to build your code if your project 49 | # uses a compiled language 50 | 51 | #- run: | 52 | # make bootstrap 53 | # make release 54 | 55 | - name: Perform CodeQL Analysis 56 | uses: github/codeql-action/analyze@v2 57 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - renovate/* 8 | pull_request: 9 | branches: 10 | - main 11 | 12 | jobs: 13 | latest: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v3 18 | 19 | - run: npm i -g --force corepack && corepack enable 20 | 21 | - uses: actions/setup-node@v3 22 | with: 23 | node-version: 20 24 | cache: "pnpm" 25 | 26 | - name: Install dependencies 27 | run: pnpm install --frozen-lockfile 28 | 29 | - name: Build 30 | run: pnpm build 31 | 32 | - name: Test 33 | run: pnpm test 34 | 35 | - name: Coverage 36 | uses: codecov/codecov-action@v3 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Node template 2 | # Logs 3 | logs 4 | *.log 5 | npm-debug.log* 6 | yarn-debug.log* 7 | yarn-error.log* 8 | 9 | # Runtime data 10 | pids 11 | *.pid 12 | *.seed 13 | *.pid.lock 14 | 15 | # Directory for instrumented libs generated by jscoverage/JSCover 16 | lib-cov 17 | 18 | # Coverage directory used by tools like istanbul 19 | coverage 20 | 21 | # nyc test coverage 22 | .nyc_output 23 | 24 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 25 | .grunt 26 | 27 | # Bower dependency directory (https://bower.io/) 28 | bower_components 29 | 30 | # node-waf configuration 31 | .lock-wscript 32 | 33 | # Compiled binary addons (https://nodejs.org/api/addons.html) 34 | build/Release 35 | 36 | # Dependency directories 37 | node_modules/ 38 | jspm_packages/ 39 | 40 | # TypeScript v1 declaration files 41 | typings/ 42 | 43 | # Optional npm cache directory 44 | .npm 45 | 46 | # Optional eslint cache 47 | .eslintcache 48 | 49 | # Optional REPL history 50 | .node_repl_history 51 | 52 | # Output of 'npm pack' 53 | *.tgz 54 | 55 | # Yarn Integrity file 56 | .yarn-integrity 57 | 58 | # dotenv environment variables file 59 | .env 60 | 61 | # parcel-bundler cache (https://parceljs.org/) 62 | .cache 63 | 64 | # next.js build output 65 | .next 66 | 67 | # nuxt.js build output 68 | .nuxt 69 | 70 | # Nuxt generate 71 | dist 72 | 73 | # vuepress build output 74 | .vuepress/dist 75 | 76 | # Serverless directories 77 | .serverless 78 | 79 | # IDE 80 | .idea 81 | 82 | # Service worker 83 | sw.* 84 | 85 | packages/*/dist/* 86 | !packages/*/dist/.gitkeep 87 | .now 88 | 89 | # https://yarnpkg.com/advanced/qa#which-files-should-be-gitignored 90 | .yarn/* 91 | !.yarn/releases 92 | !.yarn/plugins 93 | !.yarn/sdks 94 | !.yarn/versions 95 | .pnp.* 96 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | -------------------------------------------------------------------------------- /.release-it.json: -------------------------------------------------------------------------------- 1 | { 2 | "git": { 3 | "commitMessage": "chore: release v${version}" 4 | }, 5 | "github": { 6 | "release": true, 7 | "releaseName": "v${version}" 8 | }, 9 | "plugins": { 10 | "@release-it/conventional-changelog": { 11 | "preset": "conventionalcommits", 12 | "infile": "CHANGELOG.md" 13 | }, 14 | "release-it-yarn-workspaces": true 15 | }, 16 | "npm": false 17 | } 18 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## [0.3.1](https://github.com/danielroe/typed-vuex/compare/0.3.0...0.3.1) (2022-06-08) 4 | 5 | 6 | ### Bug Fixes 7 | 8 | * add `namespaced` and `strict` properties to store interfaces ([#272](https://github.com/danielroe/typed-vuex/issues/272)) ([bb5ff8d](https://github.com/danielroe/typed-vuex/commit/bb5ff8d373bd8d7ef7c543bddf338dd6ecb8ff28)) 9 | * update `vuex` peer dependency and bump dev-dependencies ([#308](https://github.com/danielroe/typed-vuex/issues/308)) ([2ee9967](https://github.com/danielroe/typed-vuex/commit/2ee996709f2758730707bf34d49a5aa3e8de5a16)) 10 | 11 | ## [0.3.0](https://github.com/danielroe/typed-vuex/compare/0.2.0...0.3.0) (2022-02-19) 12 | 13 | 14 | ### Features 15 | 16 | * add `createMapper` convenience utility ([#264](https://github.com/danielroe/typed-vuex/issues/264)) ([a26d2da](https://github.com/danielroe/typed-vuex/commit/a26d2da67c51beb0733e44c1da05482eaeca1d90)) 17 | 18 | 19 | ### Bug Fixes 20 | 21 | * check Function instance for store state rather than typeof ([4363a56](https://github.com/danielroe/typed-vuex/commit/4363a5602d1031944d226117f04970785f14b5c8)) 22 | 23 | ## [0.2.0](https://github.com/danielroe/typed-vuex/compare/0.1.22...0.2.0) (2021-04-29) 24 | 25 | 26 | ### ⚠ BREAKING CHANGES 27 | 28 | * all imports are now from `typed-vuex` rather than `nuxt-typed-vuex`, which is *exclusively* the module in your `nuxt.config` 29 | 30 | **Migration path**: Search/replace through your project `nuxt-typed-vuex` for `typed-vuex`, with the sole exception of your `nuxt.config.js`. 😊 31 | 32 | ### Bug Fixes 33 | 34 | * expose all typed-vuex types ([#231](https://github.com/danielroe/typed-vuex/issues/231)) ([9d6c479](https://github.com/danielroe/typed-vuex/commit/9d6c479b0d0781916596fd27e5f5e5e32f8579c9)) 35 | 36 | 37 | ### Code Refactoring 38 | 39 | * separate module from runtime ([#219](https://github.com/danielroe/typed-vuex/issues/219)) ([b8d556b](https://github.com/danielroe/typed-vuex/commit/b8d556b041e162c66de3e8dbd11c8f1dd5461c2a)) 40 | 41 | ### [0.1.22](https://github.com/danielroe/nuxt-typed-vuex/compare/0.1.21...0.1.22) (2020-09-30) 42 | 43 | 44 | ### Performance Improvements 45 | 46 | * increase tree-shakeability of module ([8b98e33](https://github.com/danielroe/nuxt-typed-vuex/commit/8b98e330c560c70468e536592773f2f2ada5555f)) 47 | 48 | ### [0.1.21](https://github.com/danielroe/nuxt-typed-vuex/compare/0.1.20...0.1.21) (2020-08-30) 49 | 50 | 51 | ### Features 52 | 53 | * **nuxt-typed-vuex:** automatically transpile module ([35eb0a0](https://github.com/danielroe/nuxt-typed-vuex/commit/35eb0a0f221718e9f29e1f100a574f7c1e88bf1d)) 54 | 55 | ### [0.1.20](https://github.com/danielroe/nuxt-typed-vuex/compare/nuxt-typed-vuex@0.1.19...0.1.20) (2020-08-02) 56 | 57 | ### Bug Fixes 58 | 59 | - move @nuxt/types and vuex to peerDeps ([4d6029e](https://github.com/danielroe/nuxt-typed-vuex/commit/4d6029ea582cc055010612b8427b4ae12fcd4fac)) 60 | - state lazy evaluation in accessor ([#75](https://github.com/danielroe/nuxt-typed-vuex/issues/75)) ([bae68f5](https://github.com/danielroe/nuxt-typed-vuex/commit/bae68f59dfd7f05511469569943a56a15583b9b9)) 61 | 62 | ## [0.1.19](https://github.com/danielroe/nuxt-typed-vuex/compare/typed-vuex@0.1.18...typed-vuex@0.1.19) (2020-06-13) 63 | 64 | **Note:** Version bump only 65 | 66 | ## [0.1.18](https://github.com/danielroe/nuxt-typed-vuex/compare/typed-vuex@0.1.17...typed-vuex@0.1.18) (2020-04-20) 67 | 68 | **Note:** Version bump only 69 | 70 | ## [0.1.17](https://github.com/danielroe/nuxt-typed-vuex/compare/typed-vuex@0.1.16...typed-vuex@0.1.17) (2020-03-05) 71 | 72 | ### Bug Fixes 73 | 74 | - move @nuxt/types and vuex to peerDeps ([4d6029e](https://github.com/danielroe/nuxt-typed-vuex/commit/4d6029ea582cc055010612b8427b4ae12fcd4fac)) 75 | 76 | ## [0.1.16](https://github.com/danielroe/nuxt-typed-vuex/compare/typed-vuex@0.1.15...typed-vuex@0.1.16) (2020-02-08) 77 | 78 | ### Bug Fixes 79 | 80 | - state lazy evaluation in accessor ([#75](https://github.com/danielroe/nuxt-typed-vuex/issues/75)) ([bae68f5](https://github.com/danielroe/nuxt-typed-vuex/commit/bae68f59dfd7f05511469569943a56a15583b9b9)) 81 | 82 | ## [0.1.15](https://github.com/danielroe/nuxt-typed-vuex/compare/typed-vuex@0.1.14...typed-vuex@0.1.15) (2019-12-12) 83 | 84 | **Note:** Version bump only 85 | 86 | ## 0.1.14 (2019-12-12) 87 | 88 | **Note:** Version bump only 89 | 90 | ## [0.1.14-alpha.2](https://github.com/danielroe/nuxt-typed-vuex/compare/typed-vuex@0.1.14-alpha.0...typed-vuex@0.1.14-alpha.2) (2019-12-12) 91 | 92 | ### Performance Improvements 93 | 94 | - exclude source maps ([e638b97](https://github.com/danielroe/nuxt-typed-vuex/commit/e638b977d971636f59cd58886fe69a0d008175b3)) 95 | 96 | ## [0.1.14-alpha.1](https://github.com/danielroe/nuxt-typed-vuex/compare/typed-vuex@0.1.14-alpha.0...typed-vuex@0.1.14-alpha.1) (2019-12-12) 97 | 98 | ### Performance Improvements 99 | 100 | - exclude source maps ([e638b97](https://github.com/danielroe/nuxt-typed-vuex/commit/e638b977d971636f59cd58886fe69a0d008175b3)) 101 | 102 | ## 0.1.14-alpha.0 (2019-12-08) 103 | 104 | **Note:** Version bump only for package typed-vuex 105 | 106 | ### [0.1.13](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.13-beta.0...v0.1.13) (2019-11-26) 107 | 108 | ### [0.1.12](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.11...v0.1.12) (2019-11-22) 109 | 110 | ### Bug Fixes 111 | 112 | - allow any kind of dispatch ([75f4637](https://github.com/danielroe/nuxt-typed-vuex/commit/75f463723d54949a98100c21481e5bae5f6d7a87)) 113 | 114 | ### [0.1.11](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.10...v0.1.11) (2019-11-22) 115 | 116 | ### Bug Fixes 117 | 118 | - restore dispatch to action context ([019f1bb](https://github.com/danielroe/nuxt-typed-vuex/commit/019f1bb53ddac38fcde81c195a4df3c9afc49f57)), closes [#43](https://github.com/danielroe/nuxt-typed-vuex/issues/43) 119 | 120 | ### [0.1.10](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.10-beta.2...v0.1.10) (2019-11-06) 121 | 122 | ### [0.1.9](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.8...v0.1.9) (2019-11-03) 123 | 124 | ### Bug Fixes 125 | 126 | - require @nuxt/types and vuex as peer deps ([c1ebc33](https://github.com/danielroe/nuxt-typed-vuex/commit/c1ebc33)) 127 | 128 | ### Features 129 | 130 | - add example codesandbox ([a6b89b1](https://github.com/danielroe/nuxt-typed-vuex/commit/a6b89b1)) 131 | - allow simpler usage of useAccessor ([9cb8cd2](https://github.com/danielroe/nuxt-typed-vuex/commit/9cb8cd2)), closes [#13](https://github.com/danielroe/nuxt-typed-vuex/issues/13) 132 | 133 | ### [0.1.8](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.7...v0.1.8) (2019-10-13) 134 | 135 | ### [0.1.7](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.6...v0.1.7) (2019-10-13) 136 | 137 | ### Bug Fixes 138 | 139 | - use correct paths on Windows machines ([56b714a](https://github.com/danielroe/nuxt-typed-vuex/commit/56b714a)) 140 | 141 | ### [0.1.6](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.5...v0.1.6) (2019-10-11) 142 | 143 | ### Features 144 | 145 | - add rootState and rootGetters type helpers ([2661017](https://github.com/danielroe/nuxt-typed-vuex/commit/2661017)) 146 | 147 | ### [0.1.5](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.4...v0.1.5) (2019-10-06) 148 | 149 | ### Bug Fixes 150 | 151 | - allow defining rootState & rootGetters ([fe484b2](https://github.com/danielroe/nuxt-typed-vuex/commit/fe484b2)) 152 | 153 | ### Features 154 | 155 | - add helper functions for use within store ([59bed72](https://github.com/danielroe/nuxt-typed-vuex/commit/59bed72)) 156 | 157 | ### [0.1.4](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.3...v0.1.4) (2019-10-05) 158 | 159 | ### Bug Fixes 160 | 161 | - state is still required ([91ae3d7](https://github.com/danielroe/nuxt-typed-vuex/commit/91ae3d7)) 162 | 163 | ### Features 164 | 165 | - support state objects ([97ed828](https://github.com/danielroe/nuxt-typed-vuex/commit/97ed828)) 166 | 167 | ### [0.1.3](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.2...v0.1.3) (2019-10-05) 168 | 169 | ### Bug Fixes 170 | 171 | - allow partial submodules ([d27bea0](https://github.com/danielroe/nuxt-typed-vuex/commit/d27bea0)) 172 | - allow specifying different rootState ([a837a24](https://github.com/danielroe/nuxt-typed-vuex/commit/a837a24)) 173 | - convert plugin to ts ([ae240eb](https://github.com/danielroe/nuxt-typed-vuex/commit/ae240eb)) 174 | 175 | ### [0.1.2](https://github.com/danielroe/nuxt-typed-vuex/compare/v0.1.1...v0.1.2) (2019-10-04) 176 | 177 | ### Features 178 | 179 | - add commit and dispatch options ([ef320e7](https://github.com/danielroe/nuxt-typed-vuex/commit/ef320e7)) 180 | 181 | ### 0.1.1 (2019-10-04) 182 | 183 | ### Features 184 | 185 | - initial commit ([b3eed9a](https://github.com/danielroe/nuxt-typed-vuex/commit/b3eed9a)) -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | - Using welcoming and inclusive language 18 | - Being respectful of differing viewpoints and experiences 19 | - Gracefully accepting constructive criticism 20 | - Focusing on what is best for the community 21 | - Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | - The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | - Trolling, insulting/derogatory comments, and personal or political attacks 28 | - Public or private harassment 29 | - Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | - Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies within all project spaces, and it also applies when 49 | an individual is representing the project or its community in public spaces. 50 | Examples of representing a project or community include using an official 51 | project e-mail address, posting via an official social media account, or acting 52 | as an appointed representative at an online or offline event. Representation of 53 | a project may be further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at daniel@danielcroe.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Daniel Roe 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 |
A strongly-typed store accessor for vanilla Vuex
3 | 4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
31 | Read documentation 32 |
33 | 34 | ## Summary 35 | 36 | This module provides a store accessor and helper type methods so you can access your vanilla Vuex store in a strongly typed way. 37 | 38 |  39 | 40 |  41 | 42 | **Note**: This has been developed to suit my needs but additional use cases and contributions are very welcome. 43 | 44 | [MIT License](./LICENSE) - Copyright © Daniel Roe 45 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | babelrcRoots: ['packages/*'], 4 | } 5 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | # https://yarnpkg.com/advanced/qa#which-files-should-be-gitignored 2 | .yarn/* 3 | !.yarn/releases 4 | !.yarn/plugins 5 | !.yarn/sdks 6 | !.yarn/versions 7 | .pnp.* 8 | -------------------------------------------------------------------------------- /docs/docus.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | title: 'Typed Vuex', 3 | url: 'https://typed-vuex.roe.dev/', 4 | twitter: 'danielcroe', 5 | github: { 6 | repo: 'danielroe/typed-vuex', 7 | }, 8 | } 9 | -------------------------------------------------------------------------------- /docs/nuxt.config.js: -------------------------------------------------------------------------------- 1 | import { withDocus } from 'docus' 2 | 3 | export default withDocus({ 4 | rootDir: __dirname, 5 | image: { 6 | provider: 'static', 7 | }, 8 | }) 9 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "nuxt dev", 5 | "now-build": "nuxt generate" 6 | }, 7 | "devDependencies": { 8 | "docus": "0.5.6", 9 | "nuxt-i18n": "6.28.1" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/pages/en/1.getting-started/1.getting-started-nuxt.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Getting started (Nuxt) 3 | description: 'Vanilla, strongly-typed store accessor.' 4 | --- 5 | 6 | ## Install module 7 | 8 | 1. Install Nuxt module: 9 | 10 | :::::code-group 11 | ::::code-block{label="Yarn" active} 12 | 13 | ```bash 14 | yarn add nuxt-typed-vuex 15 | ``` 16 | 17 | :::: 18 | ::::code-block{label="NPM"} 19 | 20 | ```bash 21 | npm install nuxt-typed-vuex --save 22 | ``` 23 | 24 | :::: 25 | ::::: 26 | 27 | :::alert{type="info"} 28 | This will also install `typed-vuex` in your project, which is where the store accessor lives. All the helper functions are imported from `typed-vuex`. 29 | ::: 30 | 31 | 2. Add module to your `nuxt.config`: 32 | 33 | ```ts 34 | buildModules: [ 35 | 'nuxt-typed-vuex', 36 | ], 37 | ``` 38 | 39 | :::alert{type="info"} 40 | `buildModules` require Nuxt 2.10+. If you are using an older version, add `nuxt-typed-vuex` to `modules` instead. 41 | ::: 42 | 43 | ## Add type definitions 44 | 45 | The module will inject a store accessor throughout your project (`$accessor`). It is not typed by default, so you will need to add types. 46 | 47 | ### Defining the accessor type 48 | 49 | In your root store module, add the following code: 50 | 51 | ```ts{}[store/index.ts] 52 | import { getAccessorType } from 'typed-vuex' 53 | 54 | // Import all your submodules 55 | import * as submodule from '~/store/submodule' 56 | 57 | // Keep your existing vanilla Vuex code for state, getters, mutations, actions, plugins, etc. 58 | // ... 59 | 60 | // This compiles to nothing and only serves to return the correct type of the accessor 61 | export const accessorType = getAccessorType({ 62 | state, 63 | getters, 64 | mutations, 65 | actions, 66 | modules: { 67 | // The key (submodule) needs to match the Nuxt namespace (e.g. ~/store/submodule.ts) 68 | submodule, 69 | }, 70 | }) 71 | ``` 72 | 73 | :::alert{type="info"} 74 | This may look different if you split your modules into separate files for `state`, `actions`, `mutations` and `getters`. 75 | ::: 76 | 77 | ### Creating type definitions 78 | 79 | Add the following type definitions to your project: 80 | 81 | ```ts{}[index.d.ts] 82 | import { accessorType } from '~/store' 83 | 84 | declare module 'vue/types/vue' { 85 | interface Vue { 86 | $accessor: typeof accessorType 87 | } 88 | } 89 | 90 | declare module '@nuxt/types' { 91 | interface NuxtAppOptions { 92 | $accessor: typeof accessorType 93 | } 94 | 95 | interface Context { 96 | $accessor: typeof accessorType, 97 | } 98 | } 99 | ``` 100 | -------------------------------------------------------------------------------- /docs/pages/en/1.getting-started/2.getting-started-vue.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Getting started (Vue) 3 | description: 'Vanilla, strongly-typed store accessor.' 4 | --- 5 | 6 | If you would like to benefit from a typed accessor to your store, but you're not using Nuxt, you can still use `typed-vuex`. 7 | 8 | :::alert 9 | Many of this project's default settings are based on Nuxt, so please file an issue if you experience any problems. 10 | ::: 11 | 12 | ## Setup 13 | 14 | 1. Install package: 15 | 16 | :::::code-group 17 | ::::code-block{label="Yarn" active} 18 | 19 | ```bash 20 | yarn add typed-vuex 21 | ``` 22 | 23 | :::: 24 | ::::code-block{label="NPM"} 25 | 26 | ```bash 27 | npm install typed-vuex --save 28 | ``` 29 | 30 | :::: 31 | ::::: 32 | 33 | 2. Instantiate your accessor 34 | 35 | ```ts{}[src/store/index.ts] 36 | import Vue from 'vue' 37 | import Vuex from 'vuex' 38 | 39 | import { 40 | useAccessor, 41 | getterTree, 42 | mutationTree, 43 | actionTree, 44 | } from 'typed-vuex' 45 | 46 | Vue.use(Vuex) 47 | 48 | const state = () => ({ 49 | email: '', 50 | }) 51 | 52 | const getters = getterTree(state, { 53 | email: state => state.email, 54 | fullEmail: state => state.email, 55 | }) 56 | 57 | const mutations = mutationTree(state, { 58 | setEmail(state, newValue: string) { 59 | state.email = newValue 60 | }, 61 | 62 | initialiseStore() { 63 | console.log('initialised') 64 | }, 65 | }) 66 | 67 | const actions = actionTree( 68 | { state, getters, mutations }, 69 | { 70 | async resetEmail({ commit }) { 71 | commit('setEmail', 'a@a.com') 72 | }, 73 | } 74 | ) 75 | 76 | const storePattern = { 77 | state, 78 | mutations, 79 | actions, 80 | } 81 | 82 | const store = new Vuex.Store(storePattern) 83 | 84 | export const accessor = useAccessor(store, storePattern) 85 | 86 | // Optionally, inject accessor globally 87 | Vue.prototype.$accessor = accessor 88 | 89 | export default store 90 | ``` 91 | 92 | 3. Define types. 93 | 94 | If you've injected the accessor globally, you'll want to define its type: 95 | 96 | ```ts{}[index.d.ts] 97 | import Vue from 'vue' 98 | import { accessor } from './src/store' 99 | 100 | declare module 'vue/types/vue' { 101 | interface Vue { 102 | $accessor: typeof accessor 103 | } 104 | } 105 | ``` 106 | 107 | ## Usage within a component 108 | 109 | ```ts 110 | import { Component, Vue } from 'vue-property-decorator' 111 | import { accessor } from '../store' 112 | 113 | @Component 114 | export default class SampleComponent extends Vue { 115 | get email() { 116 | // This (behind the scenes) returns getters['email'] 117 | return accessor.email 118 | 119 | // Or, with a globally injected accessor 120 | return this.$accessor.email 121 | } 122 | 123 | resetEmail() { 124 | // Executes dispatch('submodule/resetEmail', 'new@email.com') 125 | accessor.submodule.resetEmail('new@email.com') 126 | 127 | // Or, with a globally injected accessor 128 | this.$accessor.submodule.resetEmail('new@email.com') 129 | } 130 | } 131 | ``` 132 | 133 | ## Usage within the store 134 | 135 | You can use the accessor within the store or a store module. 136 | 137 | ```ts 138 | import { actionTree } from 'typed-vuex' 139 | import { accessor } from '.' 140 | 141 | const actions = actionTree( 142 | { state, getters, mutations }, 143 | { 144 | async resetEmail({ commit }) { 145 | accessor.submodule.initialise() 146 | commit('setEmail', 'a@a.com') 147 | }, 148 | } 149 | ) 150 | ``` 151 | -------------------------------------------------------------------------------- /docs/pages/en/1.index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Introduction 3 | description: 'Vanilla, strongly-typed store accessor.' 4 | --- 5 | 6 | Nuxt Typed Vuex is made up of two packages: 7 | 8 | 1. `typed-vuex` - a typed store accessor with helper functions, with no Nuxt dependencies 9 | 2. `nuxt-typed-vuex` - a Nuxt module that auto-injects this accessor throughout your project 10 | 11 | ## Why another package? 12 | 13 | Typing vanilla Vuex is complicated. Many people choose a class-based approach with Typescript decorators, but this can cause issues. Although Vuex provides limited type definitions for the store itself, it's complicated to access it in a type-safe way. 14 | 15 | `nuxt-typed-vuex` was developed to address this problem. It features: 16 | 17 | :::list 18 | 19 | - store definition with vanilla Vuex code 20 | - strongly typed accessor 21 | - fast performance 22 | - small footprint 23 | - compatible with Nuxt 24 | - access this.\$axios and the app/store instance from within actions 25 | - minimal setup/boilerplate 26 | 27 | ::: 28 | 29 |  30 | 31 |  32 | 33 | ## Alternatives 34 | 35 | If you would prefer a class-based approach, good options include [`vuex-module-decorators`](https://github.com/championswimmer/vuex-module-decorators) and [`vuex-class-component`](https://github.com/michaelolof/vuex-class-component). 36 | -------------------------------------------------------------------------------- /docs/pages/en/2.accessor/1.accessor-introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Introduction 3 | description: 'Vanilla, strongly-typed store accessor.' 4 | --- 5 | 6 | The accessor serves two purposes: 7 | 8 | - It wraps the store so that it can be typed without conflicting with the default types for `$store` in a Nuxt project. 9 | - It allows us to avoid creating impossible type definitions for namespaced magic strings, like `commit('mysubmodule/mutation')`. 10 | 11 | ## Structure 12 | 13 | 1. Getters, state, mutations and actions are flattened. 14 | 2. Getters take priority over state (so state is not included if a getter of the same name exists). 15 | 3. Modules are namespaced. 16 | 17 | :::alert{type="warning"} 18 | Because the accessor is flattened, you should avoid using the same name more than once between your getters, state, mutations and actions or you may receive the following error: `Cannot set property