@@ -56,6 +56,34 @@ return /******/ (function(modules) { // webpackBootstrap
56
56
57
57
var Vue // late binding
58
58
59
+ /**
60
+ * Returns the key of a Firebase snapshot across SDK versions.
61
+ *
62
+ * @param {FirebaseSnapshot } snapshot
63
+ * @return {string|null }
64
+ */
65
+ function _getKey ( snapshot ) {
66
+ return typeof snapshot . key === 'function'
67
+ ? snapshot . key ( )
68
+ : snapshot . key
69
+ }
70
+
71
+ /**
72
+ * Returns the original reference of a Firebase reference or query across SDK versions.
73
+ *
74
+ * @param {FirebaseReference|FirebaseQuery } refOrQuery
75
+ * @return {FirebaseReference }
76
+ */
77
+ function _getRef ( refOrQuery ) {
78
+ if ( typeof refOrQuery . ref === 'function' ) {
79
+ refOrQuery = refOrQuery . ref ( )
80
+ } else if ( typeof refOrQuery . ref === 'object' ) {
81
+ refOrQuery = refOrQuery . ref
82
+ }
83
+
84
+ return refOrQuery
85
+ }
86
+
59
87
/**
60
88
* Check if a value is an object.
61
89
*
@@ -77,7 +105,7 @@ return /******/ (function(modules) { // webpackBootstrap
77
105
var res = isObject ( value )
78
106
? value
79
107
: { '.value' : value }
80
- res [ '.key' ] = snapshot . key ( )
108
+ res [ '.key' ] = _getKey ( snapshot )
81
109
return res
82
110
}
83
111
@@ -117,11 +145,7 @@ return /******/ (function(modules) { // webpackBootstrap
117
145
if ( ! isObject ( source ) ) {
118
146
throw new Error ( 'VueFire: invalid Firebase binding source.' )
119
147
}
120
- // get the original ref for possible queries
121
- var ref = source
122
- if ( typeof source . ref === 'function' ) {
123
- ref = source . ref ( )
124
- }
148
+ var ref = _getRef ( source )
125
149
vm . $firebaseRefs [ key ] = ref
126
150
vm . _firebaseSources [ key ] = source
127
151
// bind based on initial value type
@@ -150,17 +174,17 @@ return /******/ (function(modules) { // webpackBootstrap
150
174
} , cancelCallback )
151
175
152
176
var onRemove = source . on ( 'child_removed' , function ( snapshot ) {
153
- var index = indexForKey ( array , snapshot . key ( ) )
177
+ var index = indexForKey ( array , _getKey ( snapshot ) )
154
178
array . splice ( index , 1 )
155
179
} , cancelCallback )
156
180
157
181
var onChange = source . on ( 'child_changed' , function ( snapshot ) {
158
- var index = indexForKey ( array , snapshot . key ( ) )
182
+ var index = indexForKey ( array , _getKey ( snapshot ) )
159
183
array . splice ( index , 1 , createRecord ( snapshot ) )
160
184
} , cancelCallback )
161
185
162
186
var onMove = source . on ( 'child_moved' , function ( snapshot , prevKey ) {
163
- var index = indexForKey ( array , snapshot . key ( ) )
187
+ var index = indexForKey ( array , _getKey ( snapshot ) )
164
188
var record = array . splice ( index , 1 ) [ 0 ]
165
189
var newIndex = prevKey ? indexForKey ( array , prevKey ) + 1 : 0
166
190
array . splice ( newIndex , 0 , record )
0 commit comments