Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Vuex, { Store } from 'vuex';
import Application from '@/store/Application';
import { RootActions } from '@/store/actions';
import { RootGetters } from '@/store/getters';
import { RootMutations } from '@/store/mutations';
import { BaseState } from '@/store/state';
import { createStore as smartCreateStore, Module } from 'vuex-smart-module';
import ServiceContainer from '@/services/ServiceContainer';
import { NS_ENTITY, NS_STATEMENTS } from '@/store/namespaces';
import { entityModule } from './entity';
import { statementModule } from '@/store/statements';
import mutationsTrackerPlugin from '@/tracking/mutationsTrackerPlugin';
Vue.use( Vuex );
export const rootModule = new Module( {
state: BaseState,
getters: RootGetters,
mutations: RootMutations,
actions: RootActions,
modules: {
[ NS_ENTITY ]: entityModule,
[ NS_STATEMENTS ]: statementModule,
},
} );
export function createStore( services: ServiceContainer ): Store {
const store = smartCreateStore( rootModule, {
strict: process.env.NODE_ENV !== 'production',
plugins: [ mutationsTrackerPlugin( services.get( 'tracker' ) ) ],
} );
import { EntityMutations } from '@/store/entity/mutations';
import { EntityActions } from '@/store/entity/actions';
import { Module } from 'vuex-smart-module';
import EntityId from '@/datamodel/EntityId';
export class EntityState {
public id: EntityId = '';
public baseRevision = 0;
}
export const entityModule = new Module( {
state: EntityState,
mutations: EntityMutations,
actions: EntityActions,
} );
import { StatementMap } from '@wmde/wikibase-datamodel-types';
import { Module } from 'vuex-smart-module';
import { StatementMutations } from '@/store/statements/mutations';
import { StatementActions } from '@/store/statements/actions';
import { StatementGetters } from '@/store/statements/getters';
export class StatementState {
[ entityId: string ]: StatementMap;
}
export const statementModule = new Module( {
state: StatementState,
mutations: StatementMutations,
actions: StatementActions,
getters: StatementGetters,
} );
export function createStore( services: ServiceContainer ): Store {
const store = smartCreateStore( rootModule, {
strict: process.env.NODE_ENV !== 'production',
plugins: [ mutationsTrackerPlugin( services.get( 'tracker' ) ) ],
} );
store.$services = services;
return store;
}
return () => {
Vue.use( Vuex );
rootModule.options.state = class {
constructor() {
Object.assign( this, state );
}
};
const store = smartCreateStore( rootModule );
return {
store,
template: '',
};
};
}