Skip to content

Commit

Permalink
Added FieryBindingOptions to fieryBinding(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClickerMonkey committed May 3, 2019
1 parent 90aad8f commit d012dbe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/fiery-vuex.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions dist/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export declare type FieryBinding = (context: any, payload: any, fiery: FieryBind
export declare type FieryBindings = {
[action: string]: FieryBinding;
};
export declare type FieryBindingOptions = {
commitInitial: boolean;
};
export declare type FieryState = <S>(fiery: FieryInstance) => S;
export declare type FieryCommit = <T extends FieryTarget>(mutation: string, target: T) => T;
declare const plugin: {
Expand All @@ -32,5 +35,5 @@ export declare function fieryMutations<S = any>(mutations: FieryMutations): Muta
export declare function fieryMutation<S = any>(mutationFactory: FieryMutation): Mutation<S>;
export declare function fieryActions<S = any>(actions: FieryActions): ActionTree<S, S>;
export declare function fieryAction<S = any>(action: FieryAction): Action<S, S>;
export declare function fieryBindings<S = any>(actions: FieryBindings): ActionTree<S, S>;
export declare function fieryBinding<S = any>(action: string, actionFactory: FieryBinding): Action<S, S>;
export declare function fieryBindings<S = any>(actions: FieryBindings, options?: Partial<FieryBindingOptions>): ActionTree<S, S>;
export declare function fieryBinding<S = any>(action: string, actionFactory: FieryBinding, options?: Partial<FieryBindingOptions>): Action<S, S>;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fiery-vuex",
"version": "0.10.1",
"version": "0.11.0",
"author": "Philip Diffenderfer",
"description": "A Typescript/JS library for Vuex and Google Firebase Firestore",
"license": "MIT",
Expand Down
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type FieryBinding = (context: any, payload: any, fiery: FieryBindingFacto

export type FieryBindings = { [action: string]: FieryBinding }

export type FieryBindingOptions = { commitInitial: boolean };

export type FieryState = <S>(fiery: FieryInstance) => S

export type FieryCommit = <T extends FieryTarget>(mutation: string, target: T) => T
Expand Down Expand Up @@ -178,19 +180,19 @@ export function fieryAction <S = any>(action: FieryAction): Action<S, S>
}
}

export function fieryBindings <S = any>(actions: FieryBindings): ActionTree<S, S>
export function fieryBindings <S = any>(actions: FieryBindings, options?: Partial<FieryBindingOptions>): ActionTree<S, S>
{
const out = {}

for (let action in actions)
{
out[action] = fieryBinding(action, actions[action])
out[action] = fieryBinding(action, actions[action], options)
}

return out
}

export function fieryBinding <S = any>(action: string, actionFactory: FieryBinding): Action<S, S>
export function fieryBinding <S = any>(action: string, actionFactory: FieryBinding, options?: Partial<FieryBindingOptions>): Action<S, S>
{
assertString(action, 'fieryBinding must be passed the action name as the first argument')
assertFunction(actionFactory, 'fieryBinding can only be passed a function which accepts (context, payload, $fiery)')
Expand Down Expand Up @@ -237,7 +239,7 @@ export function fieryBinding <S = any>(action: string, actionFactory: FieryBindi

assertString(actionMutation, 'fieryBinding must be passed the mutation through $fiery or commit')

if (!initialized)
if (!initialized && (!options || options.commitInitial != false))
{
context.commit(actionMutation, () => initial)
}
Expand Down

0 comments on commit d012dbe

Please sign in to comment.