Methods
addArrayElementFactory(settings) → {function}
Factory function that can be adapted to your Vuex state and that returns a mutation function. The mutation adds an element to an array.
Assumes that you have on your state an array container and an index object holding id/array index pairs.
Assumes that the element provided to the mutation has an id property.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
object | Configuration.
Properties
|
- Source:
Returns:
- Returns a Vuex mutation function.
- Type
- function
Examples
Using the factory function
{ state: {nameOfContainer: [{id: 2, name: "element"}], nameOfIndex: {2:0}},
mutations: {
add: addArrayElementFactory({container: "nameOfContainer", index: "nameOfIndex"}),
}}
Using the mutation
store.commit("add", {id: 3, name: "newElement"});
crudContainerFactory(settings) → {object}
The factory returns a store module preset. The preset contains a container array intended to hold elements as well as associated CRUD functions.
Notice that keeping the default names of store components for non-namespaced containers will result in duplicate commit/dispatch calls. Make sure to provide unique names to non-namespaced modules.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
object | Configuration.
Properties
|
- Source:
Returns:
- A Vuex store object.
- Type
- object
getArrayElWIdxByIdFactory(settings) → {var}
Factory function that can be adapted to your Vuex state and that returns a getter function. The getter returns the element with the id provided from the state's container.
Assumes that you have on your state an array container and an index object holding id/array index pairs.
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
object | Configuration.
Properties
|
- Source:
Returns:
- Returns null or a user provided value.
- Type
- var
Examples
Using the factory function
{ state: {nameOfContainer: [{id: 2, name: "element", data: 123}], nameOfIndex: {2:0}},
getters: {
getElementById: getArrayElWIdxByIdFactory({container: "nameOfContainer", index: "nameOfIndex"}),
}}
Using the getter
store.getters.getElementById(2);
passThruActionsFactory(names) → {function|object}
Parameters:
Name | Type | Description |
---|---|---|
names |
string | Array.<string> | object | A single name of an action/commit, an array of action/commit names or an object of action name/commit name pairs. |
- Source:
Returns:
- Returns an action function (if param string) or an object of functions (if param object/array).
- Type
- function | object
Examples
Using the factory function
{ state: {propA: 1, propB: 2},
actions: {
anAction: passThruActionsFactory("doSth"),
...passThruActionsFactory(["doA", "doB"]),
...passThruActionsFactory({actionA: "commitB"})
}}
Equivalent - parameter string
passThruActionsFactory("doSth")
doSth(store, data, options) {store.commit("doSth", data, options);}
Equivalent - parameter array
passThruActionsFactory(["doA", "doB"])
doA(store, data, options) {store.commit("doA", data, options);},
doB(store, data, options) {store.commit("doB", data, options);}
Equivalent - parameter object
passThruActionsFactory({actionA: "commitA"})
actionA(store, data, options) {store.commit("commitA", data, options);}
removeArrayElementByIdFactory(settings) → {function}
Factory function that can be adapted to your Vuex state and that returns a mutation function. The mutation removes an element from an array.
Assumes that you have on your state an array container and an index object holding id/array index pairs.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
object | Configuration.
Properties
|
- Source:
Returns:
- Returns a Vuex mutation function.
- Type
- function
Examples
Using the factory function
{ state: {nameOfContainer: [{id: 2, name: "element"}], nameOfIndex: {2:0}},
mutations: {
delete: removeArrayElementByIdFactory({container: "nameOfContainer", index: "nameOfIndex"}),
}}
Using the mutation
store.commit("delete", {id: 2});
resetArrayFactory(settings) → {function}
Factory function that can be adapted to your Vuex state and that returns a mutation function. The mutation empties or replaces the container array.
Assumes that you have on your state an array container and an index object holding id/array index pairs.
Assumes that you do not use the index as reactive property.
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
object | Configuration.
Properties
|
- Source:
Returns:
- Returns a Vuex mutation function.
- Type
- function
Examples
Using the factory function
{ state: {nameOfContainer: [{id: 2, name: "element"}], nameOfIndex: {2:0}},
mutations: {
reset: resetArrayFactory({container: "nameOfContainer", index: "nameOfIndex"}),
}}
Using the mutation
store.commit("reset", {elements: [{id: 3, name: "replacement"}]); //replace
store.commit("reset"); //empty
setArrayElPropsByIdFactory(settings) → {function}
Factory function that can be adapted to your Vuex state and that returns a mutation function. The mutation sets the properties of an element within an array to the given values. See setPropsHandleObject how object/array values can be handled.
Assumes that you have on your state an array container and an index object holding id/array index pairs.
Assumes that the update data provided to the mutation have an id property.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
object | Configuration.
Properties
|
- Source:
Returns:
- Returns a Vuex mutation function.
- Type
- function
Examples
Using the factory function
{ state: {nameOfContainer: [{id: 2, name: "element", data: 123}], nameOfIndex: {2:0}},
mutations: {
set: setArrayElPropsByIdFactory({container: "nameOfContainer", index: "nameOfIndex"}),
}}
Using the mutation
store.commit("set", {id: 2, name: "newName", data: 456});
setProps()
The mutation sets state properties by key/val pairs on the data parameter. See setPropsHandleObject how object/array values can be handled.
- Source:
Throws:
Throws for undefined properties - after all valid properties have been set.
Examples
Using the factory function
{ state: {propA: 1, propB: 2},
mutations: {
set: setProps
}}
Using the mutation
store.commit("set", {propA: 2, propB: 3});
setPropsHandleObject(state, data, propName)
Private function used by setProps, setPropsOnObjectFactory, setArrayElPropsByIdFactory to handle object (nested) and array property values.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
state |
object | Vuex state object of mutation. | ||||||||||||
data |
object | Your data passed to the mutation.
Properties
|
||||||||||||
propName |
string | Interal helper |
- Source:
Example
{ state: {propA: 1, propB: {subPropC: 2, subPropD: 3}, propE: [1,2,3]},
mutations: { set: setProps
}
//...
store.commit("set", {propE: ["a", "b", "c"]} // replaces array of propE
store.commit("set", {propE: "four", arrOp: "push"}) // appends "four" to propE
store.commit("set", {propB: {subPropD: 4}, objOp: "recur"}) // sets subPropD to 4
store.commit("set", {propE: {value: 1.5, element: 2}, arrOp: "insert"}) // inserts 1.5 before 2 in propE array
setPropsOnObjectFactory(settings) → {function}
Factory function that can be adapted to your Vuex state and that returns a mutation function. The mutation sets the properties of an object on the state. See setPropsHandleObject how object/array values can be handled.
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
settings |
object | Configuration.
Properties
|
- Source:
Returns:
- Returns a Vuex mutation function.
- Type
- function
Examples
Using the factory function
{ state: {someObject: {propA: 2, propB: 5}},
mutations: {
set: setPropsOnObjectFactory({object: "someObject"}),
}}
Using the mutation
store.commit("set", {propA: 123, propB: 456});
setPropVal()
The mutation sets a state property.
- Source:
Throws:
Throws for undefined properties - after all valid properties have been set.
Examples
Using the factory function
{ state: {propA: 1, propB: 2},
mutations: {
set: setPropVal
}}
Using the mutation
store.commit("set", {prop: "propA", val: 3});
storeVisitor(storeObj, callback) → {undefined}
Store visitor recurs over each of your Vuex modules (including root) and allows you to build queries such as "call each init action on every module".
Experimental: Currently, maybe too high level and exposes stuff which it probably should not. Treat callback params read-only, expect interface changes.
Parameters:
Name | Type | Description |
---|---|---|
storeObj |
object | The Vuex instance. Make sure to call storeVisitor after all dynamic modules have been registered. |
callback |
function | Callback(module, namespace) visiting each store module providing the current module and the namespace chain, if any. |
- Source:
Returns:
- Type
- undefined
Example
const store = new Vuex.Store();
store.registerModule("storeVisitor", {actions: {
storeVisitor: function(storeParams, callback) {
storeVisitor(store, callback);
}
}});
//calls all init actions
store.dispatch("storeVisitor", function callback(module, namespace) {
if("actions" in module && "init" in module.actions) { store.dispatch(namespace+"/"+init); }
})