TypeScript vuex-typex getStoreBuilder示例

说明

typescript vuex-typex getstorebuilder示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: TypeScript

命名空间/包名称: vuex-typex

示例#1
文件: index.ts 项目: dmnevius/HangoutsTools

import { getStoreBuilder } from 'vuex-typex';
import Channel from '../../classes/channel';
import ProjectState from './state';
import RootState from '../state';
import Timeline from '../../classes/timeline';
import User from '../../classes/user';

const initialState: ProjectState = {
  channels: {},
  users: {},
  messages: 0,
  timeline: new Timeline(),
  myID: '',
};

const store = getStoreBuilder<RootState>().module('project', initialState);

function addChannel(state: ProjectState, channel: Channel) {
  state.channels[channel.id] = channel;
}

function addUser(state: ProjectState, user: User) {
  if (state.users[user.id] && (typeof state.users[user.id].name !== 'string') && (typeof user.name === 'string')) {
    state.users[user.id].name = user.name;
  } else if (!state.users[user.id]) {
    state.users[user.id] = user;
  }
}

function addMessage(state: ProjectState, payload: {
  sender: User,

示例#2
文件: index.ts 项目: dmnevius/HangoutsTools

import Vue from 'vue';
import Vuex, { Store } from 'vuex';
import { getStoreBuilder } from 'vuex-typex';
import RootState from './state';
import './project';

Vue.use(Vuex);

const store: Store<RootState> = getStoreBuilder<RootState>().vuexStore();

export default store;

展开阅读全文