Skip to content

Commit 02c1020

Browse files
committed
feat(vuexfire): rename exports
BREAKING CHANGE: Rename `firebaseMutations` into `vuefireMutations`. Rename `firebaseAction` into `firestoreAction` since we want to allow using RTDB as well and that name will be used for the firebaseAction as well
1 parent c746bbc commit 02c1020

File tree

5 files changed

+59
-41
lines changed

5 files changed

+59
-41
lines changed

packages/vuexfire/src/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import mutations from './mutations'
2-
import { VUEXFIRE_SET_VALUE, VUEXFIRE_ARRAY_ADD, VUEXFIRE_ARRAY_REMOVE } from './types'
2+
import {
3+
VUEXFIRE_SET_VALUE,
4+
VUEXFIRE_ARRAY_ADD,
5+
VUEXFIRE_ARRAY_REMOVE
6+
} from './types'
37

48
import { bindCollection, bindDocument } from '@posva/vuefire-core'
5-
export const firebaseMutations = {}
9+
export const vuefireMutations = {}
610
const commitOptions = { root: true }
711

812
Object.keys(mutations).forEach(type => {
913
// the { commit, state, type, ...payload } syntax is not supported by buble...
10-
firebaseMutations[type] = (_, context) => {
14+
vuefireMutations[type] = (_, context) => {
1115
mutations[type](context.state, context)
1216
}
1317
})
@@ -64,7 +68,7 @@ function unbind ({ commit, key }) {
6468
delete sub[key]
6569
}
6670

67-
export function firebaseAction (action) {
71+
export function firestoreAction (action) {
6872
return function firebaseEnhancedActionFn (context, payload) {
6973
// get the local state and commit. These may be bound to a module
7074
const { state, commit } = context

packages/vuexfire/test/index.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Vuex from 'vuex'
2-
import { firebaseMutations, firebaseAction } from '../src'
2+
import { vuefireMutations, firestoreAction } from '../src'
33
import { db, tick, Vue, delayUpdate } from '@posva/vuefire-test-helpers'
44

55
Vue.use(Vuex)
66

77
describe('firebaseAction', () => {
88
const store = new Vuex.Store({
9-
mutations: firebaseMutations,
9+
mutations: vuefireMutations,
1010
actions: {
11-
action: firebaseAction((context, fn) => fn(context))
11+
action: firestoreAction((context, fn) => fn(context))
1212
}
1313
})
1414

packages/vuexfire/test/mutations.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { firebaseMutations } from '../src'
1+
import { vuefireMutations } from '../src'
22
import {
33
VUEXFIRE_SET_VALUE,
44
VUEXFIRE_ARRAY_ADD,
@@ -9,7 +9,7 @@ import {
99
describe('mutations', () => {
1010
it('sets a value', () => {
1111
const state = { foo: null }
12-
firebaseMutations[VUEXFIRE_SET_VALUE](state, {
12+
vuefireMutations[VUEXFIRE_SET_VALUE](state, {
1313
path: 'foo',
1414
target: state,
1515
data: 'foo'
@@ -19,7 +19,7 @@ describe('mutations', () => {
1919

2020
it('sets a value with a path', () => {
2121
const state = { foo: { a: { b: null }}}
22-
firebaseMutations[VUEXFIRE_SET_VALUE](state, {
22+
vuefireMutations[VUEXFIRE_SET_VALUE](state, {
2323
path: 'foo.a.b',
2424
target: state,
2525
data: 'foo'
@@ -29,14 +29,14 @@ describe('mutations', () => {
2929

3030
it('adds to arrays', () => {
3131
const state = { items: [] }
32-
firebaseMutations[VUEXFIRE_ARRAY_ADD](state, {
32+
vuefireMutations[VUEXFIRE_ARRAY_ADD](state, {
3333
target: state.items,
3434
newIndex: 0,
3535
data: 'foo'
3636
})
3737
expect(state.items).toEqual(['foo'])
3838

39-
firebaseMutations[VUEXFIRE_ARRAY_ADD](state, {
39+
vuefireMutations[VUEXFIRE_ARRAY_ADD](state, {
4040
target: state.items,
4141
newIndex: 0,
4242
data: 'bar'
@@ -46,13 +46,13 @@ describe('mutations', () => {
4646

4747
it('removes from arrays', () => {
4848
const state = { items: ['foo', 'bar'] }
49-
firebaseMutations[VUEXFIRE_ARRAY_REMOVE](state, {
49+
vuefireMutations[VUEXFIRE_ARRAY_REMOVE](state, {
5050
target: state.items,
5151
oldIndex: 0
5252
})
5353
expect(state.items).toEqual(['bar'])
5454

55-
firebaseMutations[VUEXFIRE_ARRAY_REMOVE](state, {
55+
vuefireMutations[VUEXFIRE_ARRAY_REMOVE](state, {
5656
target: state.items,
5757
oldIndex: 0
5858
})

packages/vuexfire/types/index.d.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import { MutationTree, ActionContext, Action } from 'vuex'
22
import { firestore } from 'firebase'
33

4-
export declare const firebaseMutations: MutationTree<any>
4+
export declare const vuefireMutations: MutationTree<any>
55

6-
interface FirebaseActionContext<S, R> extends ActionContext<S, R> {
7-
bindFirebaseRef(key: string, ref: firestore.Query): Promise<firestore.DocumentData[]>
8-
bindFirebaseRef(key: string, ref: firestore.DocumentReference): Promise<firestore.DocumentData>
6+
interface FirestoreActionContext<S, R> extends ActionContext<S, R> {
7+
bindFirebaseRef(
8+
key: string,
9+
ref: firestore.Query
10+
): Promise<firestore.DocumentData[]>
11+
bindFirebaseRef(
12+
key: string,
13+
ref: firestore.DocumentReference
14+
): Promise<firestore.DocumentData>
915
unbindFirebaseRef(key: string): void
1016
}
1117

12-
export declare function firebaseAction<S, R>(cb: (context: FirebaseActionContext<S, R>, payload: any) => any): Action<S, R>
18+
export declare function firestoreAction<S, R>(
19+
cb: (context: FirestoreActionContext<S, R>, payload: any) => any
20+
): Action<S, R>

packages/vuexfire/types/test/index.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Vuex from 'vuex'
2-
import { firebaseMutations, firebaseAction } from '../'
2+
import { vuefireMutations, firestoreAction } from '../'
33
import { firestore } from 'firebase'
44

55
interface Payload {
@@ -16,31 +16,37 @@ new Vuex.Store({
1616
},
1717
mutations: {
1818
// your mutations
19-
...firebaseMutations
19+
...vuefireMutations
2020
},
2121
actions: {
22-
init: firebaseAction(({ bindFirebaseRef, unbindFirebaseRef, commit }, payload: Payload) => {
23-
// this will unbind any previously bound ref to 'todos'
24-
bindFirebaseRef('todos', payload.todos).then(todos => {
25-
todos.length
26-
commit('setTodosLoaded', true)
27-
}).catch((err) => {
28-
console.log(err)
29-
})
30-
bindFirebaseRef('sortedTodos', payload.sortedTodos).then(todos => {
31-
todos.length
32-
commit('setSortedTodosLoaded', true)
33-
}).catch((err) => {
34-
console.log(err)
35-
})
22+
init: firestoreAction(
23+
({ bindFirebaseRef, unbindFirebaseRef, commit }, payload: Payload) => {
24+
// this will unbind any previously bound ref to 'todos'
25+
bindFirebaseRef('todos', payload.todos)
26+
.then(todos => {
27+
todos.length
28+
commit('setTodosLoaded', true)
29+
})
30+
.catch(err => {
31+
console.log(err)
32+
})
33+
bindFirebaseRef('sortedTodos', payload.sortedTodos)
34+
.then(todos => {
35+
todos.length
36+
commit('setSortedTodosLoaded', true)
37+
})
38+
.catch(err => {
39+
console.log(err)
40+
})
3641

37-
bindFirebaseRef('user', payload.user).then(doc => {
38-
doc.something
39-
})
42+
bindFirebaseRef('user', payload.user).then(doc => {
43+
doc.something
44+
})
4045

41-
// you can unbind any ref easily
42-
unbindFirebaseRef('user')
43-
})
46+
// you can unbind any ref easily
47+
unbindFirebaseRef('user')
48+
}
49+
)
4450
},
4551
plugins: [
4652
store => {

0 commit comments

Comments
 (0)