npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vuex-mapper-typed

v0.2.6

Published

library that allows you to use typed vuex helpers

Downloads

8

Readme

Vuex Typed Mapper

Vuex の mapXXXX をモジュール定義から動的に利用できるようにするツール

The Helper Tools allows you to use mapXXXX methods in Vuex with the mapped types derives from module definition.

Note

Vuex Typed Mapper は mapXXXX のすべての記法をサポートしているわけではありません。 サポートしているのは下記の記法のみです。

function mapXXXX(map: string[]);
function mapXXXX(namespace: string, map: string[]);

オブジェクト形式のマッピングをオミットしたのには、下記の理由があります:

  • 単純に実装コストが高かった
  • 一度型情報さえつけてしまえば、別のオブジェクトに再マッピングするのはそう難しいことではない

なので、現状オブジェクト形式のマッピングをサポートする予定はありません。

Vuex Typed Mapper does not support all of signature of mapXXXX. it only supports below signature:

function mapXXXX(map: string[]);
function mapXXXX(namespace: string, map: string[]);

The reasons I omit Object-based mapping:

  • It might be too difficult to support.
  • Once the mapped properties typed, it is easy to re-map them with new keys.

For these reasons, there're no plans about supporting Object-based mapping.

Usage

// Vuex Module
import { buildModule, makeMappers } from "vuex-typed-mapper";

export const hogeModule = buildModule({
  namespaced: true,
  state: {
    id: 1,
    name: "Jhon Doe"
  },
  actions: {
    rename({ commit }, name: string) {
      commit("rename", name);
    }
  },
  mutations: {
    updateName(state, name: string) {
      state.name = name;
    }
  }
});
export const hogeMappers = makeMappers(hogeModule);
// Vuex Store
import Vue from "vue";
import Vuex from "vuex";
import { hogeModule } from "./path/to/module-definition";

Vue.use(Vuex);

export default new Vuex.Store({
  module: {
    hoge: hogeModule
  }
});
// Vue Component
<script lang="ts">
import Vue from 'vue';
import { hogeMapper } from './path/to/module-definition';

const hogeMappedState = hogeMapper.mapStateWithType(
  'hoge',
  ['id', 'name']
);

export default Vue.extend({
  computed: {
    ...hogeMappedState
  },
  methods: {
    hogehoge() {
      this.id   // (property) this.id: number;
      this.name // (property) this.name: string;
    }
  }
});
</script>

Methods

buildModule

Defines fully-typed Vuex module.

signature
function buildModule<
  S,
  R,
  A extends ActionTree<S, R> = {},
  M extends MutationTree<S> = {},
  G extends GetterTree<S, R> = {}
>(
  mod: FullyTypedModuleDefinition<S, R, A, M, G>
): FullyTypeModule<S, R, A, M, G>;

makeMappers

Returns fully-typed mappers:

  • mapStateWithType<S>
  • mapActionsWithType<A>
  • mapMutationsWithType<M>
  • mapGettersWithType<G>
signature
function makeMappers<
  S,
  R,
  A extends ActionTree<S, R>,
  M extends MutationTree<S>,
  G extends GetterTree<S, R>
>(
  _module: FullyTypedModule<S, R, A, M, G>
): {
  mapStateWithType();
  mapActionsWithType();
  mapMutationsWithType();
  mapGettersWithType();
};
mapXXXXWithType
// maps all of properties in XXXX.
function mapXXXXWithType();
function mapXXXXWithType(namespace: string);
// maps properties with the defined names in XXXX. (`X` in Generics means `typeof XXXX`.)
function mapXXXXWithType<K extends keyof X>(map: K[]);
function mapXXXXWithType<K extends keyof X>(namespace: string, map: K[]);

Interfaces

FullyTypedModule

Extended Vuex.Module<S, R>, it can be used as Vuex.Store.module.

interface FullyTypedModule<
  S,
  R,
  A extends ActionTree<S, R>,
  M extends MutationTree<S>,
  G extends GetterTree<S, R>
> extends Vuex.Module<S, R> {
  actions: A;
  mutations: M;
  getters: G;
}

FullyTypedModuleDefinition

Module definition for FullyTypedModule

interface FullyTypedModuleDefinition<
  S,
  R,
  A extends ActionTree<S, R>,
  M extends MutationTree<S>,
  G extends GetterTree<S, R>
> extends Vuex.Module<S, R> {
  actions?: A;
  mutations?: M;
  getters?: G;
}

LICENSE

MIT