Skip to content

Commit

Permalink
Prep v3.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcrowl committed Feb 17, 2021
1 parent d9627c3 commit c805255
Show file tree
Hide file tree
Showing 6 changed files with 493 additions and 206 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ coverage/**/*
npm-debug.log
src/**/*.js
src/**/*.js.map
dist/**
81 changes: 81 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Module, Plugin, Store, StoreOptions } from "vuex";
export declare type MutationHandler<S, P> = (state: S, payload: P) => void;
export declare type ActionHandler<S, R, G, P, T> = (context: BareActionContext<S, R, G>, payload: P) => Promise<T> | T;
export declare type GetterHandler<S, R, G, T> = (state: S, getters: G, rootState: R) => T;
export interface BareActionContext<S, R, G = any> {
state: S;
rootState: R;
getters: G;
}
export interface ModuleBuilder<S, R = {}, G = any> {
/** The namespace of this ModuleBuilder */
readonly namespace: string;
/** Creates a strongly-typed nested module within this module */
module<M>(namespace: string, initialState: M): ModuleBuilder<M, R>;
/** Gets an existing nested module within this module */
module<M>(namespace: string): ModuleBuilder<M, R>;
/** Set the initial state for an existing module */
setInitialState(initialState: S): void;
/** Creates a strongly-typed commit function for the provided mutation handler */
commit<P>(handler: MutationHandler<S, void>): () => void;
commit<P>(handler: MutationHandler<S, P>): (payload: P) => void;
commit<P>(handler: MutationHandler<S, void>, name: string): () => void;
commit<P>(handler: MutationHandler<S, P>, name: string): (payload: P) => void;
/** Creates a strongly-typed dispatch function for the provided action handler */
dispatch<P, T>(handler: ActionHandler<S, R, G, void, void>): () => Promise<void>;
dispatch<P, T>(handler: ActionHandler<S, R, G, P, void>): (payload: P) => Promise<void>;
dispatch<P, T>(handler: ActionHandler<S, R, G, void, T>): () => Promise<T>;
dispatch<P, T>(handler: ActionHandler<S, R, G, P, T>): (payload: P) => Promise<T>;
dispatch<P, T>(handler: ActionHandler<S, R, G, void, void>, name: string): () => Promise<void>;
dispatch<P, T>(handler: ActionHandler<S, R, G, P, void>, name: string): (payload: P) => Promise<void>;
dispatch<P, T>(handler: ActionHandler<S, R, G, void, T>, name: string): () => Promise<T>;
dispatch<P, T>(handler: ActionHandler<S, R, G, P, T>, name: string): (payload: P) => Promise<T>;
/** Creates a strongly-typed read function for the provided getter function */
read<T>(handler: GetterHandler<S, R, G, T>): () => T;
read<T>(handler: GetterHandler<S, R, G, T>, name: string): () => T;
/** Creates a method to return this module's state */
state(): () => S;
/** Output a Vuex Module definition. Called after all strongly-typed functions have been obtained */
vuexModule(): Module<S, R>;
_provideStore(store: Store<R>): void;
}
export interface VuexStoreOptions<R> {
plugins?: Plugin<R>[];
}
export interface StoreBuilder<R> {
/** Creates a ModuleBuilder for the namespace provided */
module<S>(namespace: string, state: S): ModuleBuilder<S, R>;
/** Gets an existing ModuleBuilder for the namespace provided */
module<S>(namespace: string): ModuleBuilder<S, R>;
/** Output a Vuex Store after all modules have been built */
vuexStore(): Store<R>;
/** Output a Vuex Store and provide options, e.g. plugins -- these take precedence over any auto-generated options */
vuexStore(overrideOptions: StoreOptions<R>): Store<R>;
/** Creates a strongly-typed commit function for the provided mutation handler */
commit<P>(handler: MutationHandler<R, void>): () => void;
commit<P>(handler: MutationHandler<R, P>): (payload: P) => void;
commit<P>(handler: MutationHandler<R, void>, name: string): () => void;
commit<P>(handler: MutationHandler<R, P>, name: string): (payload: P) => void;
/** Creates a strongly-typed dispatch function for the provided action handler */
dispatch<P, T>(handler: ActionHandler<R, R, void, void, void>): () => Promise<void>;
dispatch<P, T>(handler: ActionHandler<R, R, void, P, void>): (payload: P) => Promise<void>;
dispatch<P, T>(handler: ActionHandler<R, R, void, void, T>): () => Promise<T>;
dispatch<P, T>(handler: ActionHandler<R, R, void, P, T>): (payload: P) => Promise<T>;
dispatch<P, T>(handler: ActionHandler<R, R, void, void, void>, name: string): () => Promise<void>;
dispatch<P, T>(handler: ActionHandler<R, R, void, P, void>, name: string): (payload: P) => Promise<void>;
dispatch<P, T>(handler: ActionHandler<R, R, void, void, T>, name: string): () => Promise<T>;
dispatch<P, T>(handler: ActionHandler<R, R, void, P, T>, name: string): (payload: P) => Promise<T>;
/** Creates a strongly-typed read function for the provided getter function */
read<T>(handler: GetterHandler<R, R, void, T>): () => T;
read<T>(handler: GetterHandler<R, R, void, T>, name: string): () => T;
/** Creates a method to return the root state */
state(): () => R;
/** Dynamically register module */
registerModule(namespace: string): void;
/** WARNING: Discards vuex store and reset modules (non intended for end-user use) */
reset(): void;
}
/** Get a reference to the default store builder */
export declare function getStoreBuilder<R>(): StoreBuilder<R>;
/** Get a reference to a named store builder */
export declare function getStoreBuilder<R>(name: string): StoreBuilder<R>;
216 changes: 216 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vuex-typex",
"version": "3.1.6",
"version": "3.1.7",
"description": "A TypeScript pattern for strongly-typed access to Vuex Store modules",
"files": [
"dist/index.js",
Expand Down
Loading

0 comments on commit c805255

Please sign in to comment.