Skip to content

Commit 189160f

Browse files
committed
✨ Add readyCallback
Closes #22 Signed-off-by: Eduardo San Martin Morote <[email protected]>
1 parent 7a6b262 commit 189160f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: packages/vuexfire/src/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ function bind ({
122122
source,
123123
options: {
124124
cancelCallback,
125+
readyCallback,
125126
},
126127
}) {
127128
if (!isObject(source)) {
@@ -153,6 +154,11 @@ function bind ({
153154
}
154155

155156
binding.listeners[key] = listener
157+
158+
// Support for SSR
159+
if (readyCallback) {
160+
source.once('value', readyCallback)
161+
}
156162
}
157163

158164
function unbind ({ commit, key }) {

Diff for: packages/vuexfire/test/firebase.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ test.beforeEach(async (t) => {
2929
unbindItemsRef: firebaseAction(({ unbindFirebaseRef }) => {
3030
unbindFirebaseRef('items')
3131
}),
32+
bindsWithCallback: firebaseAction(
33+
({ bindFirebaseRef }, { ref, readyCallback }) => {
34+
bindFirebaseRef('items', ref, { readyCallback })
35+
}
36+
),
3237
},
3338
mutations: firebaseMutations,
3439
})
@@ -120,3 +125,14 @@ test('moves a record when the order changes', async (t) => {
120125
{ '.key': 'c', '.value': 3 },
121126
])
122127
})
128+
129+
test.cb('readyCallback', t => {
130+
const foo = t.context.ref.child('foo')
131+
t.plan(1)
132+
const readyCallback = res => {
133+
t.deepEqual(res.val(), { bar: 'bar' })
134+
t.end()
135+
}
136+
t.context.store.dispatch('bindsWithCallback', { ref: foo, readyCallback })
137+
foo.child('bar').set('bar')
138+
})

0 commit comments

Comments
 (0)