@@ -4,22 +4,20 @@ import {
4
4
indexForKey ,
5
5
getKey ,
6
6
isObject ,
7
- VUEXFIRE_OBJECT_VALUE ,
8
- VUEXFIRE_ARRAY_INITIALIZE ,
9
- VUEXFIRE_ARRAY_ADD ,
10
- VUEXFIRE_ARRAY_CHANGE ,
11
- VUEXFIRE_ARRAY_MOVE ,
12
- VUEXFIRE_ARRAY_REMOVE ,
13
- VUEXFIRE_MUTATION ,
14
7
mutations ,
15
8
} from './utils/index.js'
16
9
17
- export const firebaseMutations = {
10
+ import * as types from './utils/types.js'
11
+
12
+ export const firebaseMutations = { }
13
+
14
+ Object . keys ( types ) . forEach ( key => {
18
15
// the { commit, state, type, ...payload } syntax is not supported by buble...
19
- [ VUEXFIRE_MUTATION ] ( _ , context ) {
20
- mutations [ context . type ] ( context . state , context )
21
- } ,
22
- }
16
+ const type = types [ key ]
17
+ firebaseMutations [ type ] = ( _ , context ) => {
18
+ mutations [ type ] ( context . state , context )
19
+ }
20
+ } )
23
21
24
22
function bindAsObject ( {
25
23
key,
@@ -29,8 +27,8 @@ function bindAsObject ({
29
27
state,
30
28
} ) {
31
29
const cb = source . on ( 'value' , function ( snapshot ) {
32
- commit ( VUEXFIRE_MUTATION , {
33
- type : VUEXFIRE_OBJECT_VALUE ,
30
+ commit ( types . VUEXFIRE_OBJECT_VALUE , {
31
+ type : types . VUEXFIRE_OBJECT_VALUE ,
34
32
key,
35
33
record : createRecord ( snapshot ) ,
36
34
state,
@@ -49,16 +47,16 @@ function bindAsArray ({
49
47
state,
50
48
} ) {
51
49
// Initialise the array to an empty one
52
- commit ( VUEXFIRE_MUTATION , {
53
- type : VUEXFIRE_ARRAY_INITIALIZE ,
50
+ commit ( types . VUEXFIRE_ARRAY_INITIALIZE , {
51
+ type : types . VUEXFIRE_ARRAY_INITIALIZE ,
54
52
state,
55
53
key,
56
54
} )
57
55
const onAdd = source . on ( 'child_added' , function ( snapshot , prevKey ) {
58
56
const array = state [ key ]
59
57
const index = prevKey ? indexForKey ( array , prevKey ) + 1 : 0
60
- commit ( VUEXFIRE_MUTATION , {
61
- type : VUEXFIRE_ARRAY_ADD ,
58
+ commit ( types . VUEXFIRE_ARRAY_ADD , {
59
+ type : types . VUEXFIRE_ARRAY_ADD ,
62
60
state,
63
61
key,
64
62
index,
@@ -69,8 +67,8 @@ function bindAsArray ({
69
67
const onRemove = source . on ( 'child_removed' , function ( snapshot ) {
70
68
const array = state [ key ]
71
69
const index = indexForKey ( array , getKey ( snapshot ) )
72
- commit ( VUEXFIRE_MUTATION , {
73
- type : VUEXFIRE_ARRAY_REMOVE ,
70
+ commit ( types . VUEXFIRE_ARRAY_REMOVE , {
71
+ type : types . VUEXFIRE_ARRAY_REMOVE ,
74
72
state,
75
73
key,
76
74
index,
@@ -80,8 +78,8 @@ function bindAsArray ({
80
78
const onChange = source . on ( 'child_changed' , function ( snapshot ) {
81
79
const array = state [ key ]
82
80
const index = indexForKey ( array , getKey ( snapshot ) )
83
- commit ( VUEXFIRE_MUTATION , {
84
- type : VUEXFIRE_ARRAY_CHANGE ,
81
+ commit ( types . VUEXFIRE_ARRAY_CHANGE , {
82
+ type : types . VUEXFIRE_ARRAY_CHANGE ,
85
83
state,
86
84
key,
87
85
index,
@@ -95,8 +93,8 @@ function bindAsArray ({
95
93
var newIndex = prevKey ? indexForKey ( array , prevKey ) + 1 : 0
96
94
// TODO refactor + 1
97
95
newIndex += index < newIndex ? - 1 : 0
98
- commit ( VUEXFIRE_MUTATION , {
99
- type : VUEXFIRE_ARRAY_MOVE ,
96
+ commit ( types . VUEXFIRE_ARRAY_MOVE , {
97
+ type : types . VUEXFIRE_ARRAY_MOVE ,
100
98
state,
101
99
key,
102
100
index,
0 commit comments