Skip to content

Commit 91b9307

Browse files
committed
reseting merge errors
1 parent 1caa5d3 commit 91b9307

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/module.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
12
import { getMutatedActions as getProxiedActions, ActionRegister } from "./actions";
2-
import { _state, _mutations, _getters, _proxy, _map, _store, _namespacedPath, _actions_register, _actions, MutationFunction, GetterFunction, ActionFunction, VuexMap, _submodule, SubModuleObject, _module } from "./symbols";
3+
import { _state, _mutations, _getters, _proxy, _map, _store, _namespacedPath, _actions_register, _actions, MutationFunction, GetterFunction, ActionFunction, VuexMap, _submodule, SubModuleObject, _module, _target } from "./symbols";
34
//@ts-ignore
45
import { Store } from "vuex";
56

67
export type VuexClassConstructor<T> = new () => T
78

8-
export type VuexModuleTarget = "core" | "nuxt";
9-
109
export class VuexModule {
1110

1211
static CreateSubModule<V extends typeof VuexModule>(SubModule: V) {
@@ -132,44 +131,51 @@ export interface VuexModule {
132131
[_module]: Record<string, any>;
133132
}
134133

134+
export type VuexModuleTarget = "core" | "nuxt";
135+
136+
interface ModuleOptions {
137+
namespacedPath? :string;
138+
target? :VuexModuleTarget
139+
}
140+
135141

136-
export function Module({ namespacedPath = "" }) {
142+
export function Module({ namespacedPath = "", target = "core" } :ModuleOptions ) {
137143

138-
return function( target :typeof VuexModule ) :void {
139-
const targetInstance = new target();
144+
return function( _module :typeof VuexModule ) :void {
145+
const targetInstance = new _module();
140146

141147
const states = Object.getOwnPropertyNames( targetInstance );
142148
const stateObj: Record<string, any> = {}
143-
if( target.prototype[ _map ] === undefined ) target.prototype[ _map ] = [];
149+
if( _module.prototype[ _map ] === undefined ) _module.prototype[ _map ] = [];
144150

145151
for( let stateField of states ) {
146152
const stateValue = targetInstance[ stateField ];
147153
if ( stateValue === undefined ) continue;
148154

149155
if ( subModuleObjectIsFound( stateValue )) {
150-
handleSubModule( target, stateField, stateValue )
156+
handleSubModule( _module, stateField, stateValue )
151157
continue;
152158
}
153159
stateObj[ stateField ] = stateValue;
154-
target.prototype[ _map ].push({ value: stateField, type: "state" });
160+
_module.prototype[ _map ].push({ value: stateField, type: "state" });
155161
}
156162

157-
target.prototype[ _state ] = stateObj;
163+
_module.prototype[ _state ] = stateObj;
158164

159-
const fields = Object.getOwnPropertyDescriptors( target.prototype );
160-
if ( target.prototype[ _getters ] === undefined ) target.prototype[ _getters ] = {}
165+
const fields = Object.getOwnPropertyDescriptors( _module.prototype );
166+
if ( _module.prototype[ _getters ] === undefined ) _module.prototype[ _getters ] = {}
161167
for (let field in fields) {
162168
const getterField = fields[ field ].get;
163169
if ( getterField ) {
164170
const func = function (state: any) {
165171
return getterField.call(state);
166172
}
167-
target.prototype[_getters][field] = func;
173+
_module.prototype[_getters][field] = func;
168174
}
169175
}
170176

171-
if ( namespacedPath.length > 0 ) target.prototype[ _namespacedPath ] = namespacedPath;
172-
177+
if ( namespacedPath.length > 0 ) _module.prototype[ _namespacedPath ] = namespacedPath;
178+
_module[ _target ] = target;
173179
}
174180
}
175181

src/symbols.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const _proxy = "__proxy_prototype__";
1010
export const _contextProxy = "__context_proxy__";
1111
export const _store = "__store__";
1212
export const _namespacedPath = "__namespacedPath__";
13+
export const _target = "__module_target__";
1314
export const _submodule = "__submodule__";
1415
export const _module = "__module__";
1516

0 commit comments

Comments
 (0)