Skip to content

Commit 62458d4

Browse files
committed
Added support for nuxtjs and javascript
1 parent 91b9307 commit 62458d4

31 files changed

+569
-102
lines changed

README.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# Vuex Class Component
2-
32
A Type Safe Solution for Vuex Modules using ES6 Classes and ES7 Decorators that works out of the box for TypeScript and JavaScript.
43

54
## Goals
65
* Ensure your Codebase is type safe when writing Vuex Modules.
76
* Provide proxies for getters, mutations and actions in a type safe way
87
* Create a Vuex Manager for handling all vuex calls throughout your codebase.
98

10-
## Dependencies
11-
This module has no external dependencies.
12-
13-
## Changelog
9+
## Changelog
10+
- `v.1.1.0` - Sub Modules support.
1411
- `v.1.4.0` - async/await now works with actions in mutatate mode.
12+
- `v.1.5.0` - JavaScript Support
13+
- `v.1.6.0` - NuxtJS Support.
1514

1615
## Installation
1716
```
@@ -22,19 +21,6 @@ $ npm install --save vuex-class-component
2221
- Vuex Class Component Simple: https://github.com/michaelolof/vuex-class-component-simple
2322
- Vuex Class Component Test: https://github.com/michaelolof/vuex-class-component-test
2423

25-
## JavaScript Support
26-
From version `1.5.0` JavaScript is now supported fully.
27-
To use vuex-class-component in your JavaScript files, ensure your babel.config.js file has the following plugins:
28-
```js
29-
module.exports = {
30-
...
31-
plugins: [
32-
["@babel/plugin-proposal-decorators", { "legacy": true }],
33-
["@babel/plugin-proposal-class-properties", { "loose" : true }]
34-
]
35-
}
36-
```
37-
3824
## How to use
3925
Consider this example.
4026
```js
@@ -128,6 +114,7 @@ export const store = new Vuex.Store({
128114
}
129115
})
130116
```
117+
131118
## Ok. So What About Vue Components?
132119
Ensuring type safety in Vuex Modules is just one half of the problem solved. We still need to use them in our Vue Components.\
133120
\
@@ -204,6 +191,34 @@ Now you can easily use in your Vue Components like:
204191
vxm.vehicle.car.drive() // driving on 4 wheels
205192
```
206193

194+
## JavaScript Support
195+
From version `1.5.0` JavaScript is now supported fully.
196+
To use vuex-class-component in your JavaScript files, ensure your babel.config.js file has the following plugins:
197+
```js
198+
module.exports = {
199+
...
200+
plugins: [
201+
["@babel/plugin-proposal-decorators", { "legacy": true }],
202+
["@babel/plugin-proposal-class-properties", { "loose" : true }]
203+
]
204+
}
205+
```
206+
And then use as follows
207+
```js
208+
import { Module, VuexModule, getter, action } from "vuex-class-component/js";
209+
```
210+
211+
## NuxtJS Support
212+
From verison `1.6.0` Nuxt is also supported.
213+
To use `vuex-class-component` with Nuxt, You add a `target` property to the @Module decorator and set it to `"nuxt"`.
214+
```js
215+
@Module({ namespacedPath: "user/", target: "nuxt" })
216+
217+
export class UserStore {
218+
...
219+
}
220+
```
221+
207222
## A note on Vuex Actions?
208223
Vuex Actions comes in two modes. A `mutate` mode and a `raw` mode. Both can be very useful.\
209224
For most of your use cases the `mutate` mode is all you'll need. The `raw` mode can be especially useful when you need access to `rootState` and `rootGetters`.\

base.tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"lib": ["esnext", "dom" ],
6+
"declaration": true,
7+
"sourceMap": true,
8+
"rootDir": "./src",
9+
"strict": true,
10+
"noImplicitAny": false,
11+
"moduleResolution": "node",
12+
"esModuleInterop": true,
13+
"experimentalDecorators": true,
14+
"emitDecoratorMetadata": true
15+
},
16+
"exclude": [
17+
"test-ts/",
18+
"test-js/",
19+
"dist/",
20+
"test/",
21+
"node_modules"
22+
]
23+
}

dist/module.d.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { ActionRegister } from "./actions";
2-
import { _state, _mutations, _getters, _proxy, _map, _store, _namespacedPath, _actions_register, _actions, MutationFunction, GetterFunction, ActionFunction, VuexMap, _submodule, _module } from "./symbols";
2+
import { _state, _mutations, _getters, _proxy, _map, _store, _namespacedPath, _actions_register, _actions, MutationFunction, GetterFunction, ActionFunction, VuexMap, _submodule, _module, _target } from "./symbols";
33
import { Store } from "vuex";
44
export declare type VuexClassConstructor<T> = new () => T;
5-
export declare type VuexModuleTarget = "core" | "nuxt";
65
export declare class VuexModule {
76
static CreateSubModule<V extends typeof VuexModule>(SubModule: V): InstanceType<V>;
87
static CreateProxy<V extends typeof VuexModule>($store: Store<any>, cls: V): InstanceType<V>;
9-
static ExtractVuexModule(cls: typeof VuexModule, target?: VuexModuleTarget): {
8+
static ExtractVuexModule(cls: typeof VuexModule): {
109
namespaced: boolean;
1110
state: any;
1211
mutations: Record<string, MutationFunction>;
@@ -25,12 +24,17 @@ export interface VuexModule {
2524
[_actions_register]: ActionRegister[];
2625
[_actions]: Record<string, ActionFunction>;
2726
[_map]: VuexMap[];
27+
[_target]: VuexModuleTarget;
2828
[_proxy]: Record<string, any>;
2929
[_store]: Record<string, any>;
3030
[_namespacedPath]: string;
3131
[_submodule]: Record<string, typeof VuexModule>;
3232
[_module]: Record<string, any>;
3333
}
34-
export declare function Module(options?: {
35-
namespacedPath: string;
36-
}): (target: typeof VuexModule) => void;
34+
export declare type VuexModuleTarget = "core" | "nuxt";
35+
interface ModuleOptions {
36+
namespacedPath?: string;
37+
target?: VuexModuleTarget;
38+
}
39+
export declare function Module({ namespacedPath, target }?: ModuleOptions): (_module: typeof VuexModule) => void;
40+
export {};

dist/module.js

Lines changed: 28 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)