11/**
22* @author Jason Dobry <jason.dobry@gmail.com>
33* @file js-data-firebase.js
4- * @version 1.0.0-alpha .1 - Homepage <http://www.js-data.iojs-data-firebase/>
4+ * @version 1.0.0-beta .1 - Homepage <http://www.js-data.iojs-data-firebase/>
55* @copyright (c) 2014 Jason Dobry
66* @license MIT <https://github.com/js-data/js-data-firebase/blob/master/LICENSE>
77*
@@ -179,20 +179,20 @@ function DSFirebaseAdapter(options) {
179179 options = options || { } ;
180180 this . defaults = new Defaults ( ) ;
181181 deepMixIn ( this . defaults , options ) ;
182+ this . ref = new Firebase ( options . basePath || this . defaults . basePath ) ;
182183}
183184
184185var dsFirebaseAdapterPrototype = DSFirebaseAdapter . prototype ;
185186
186187dsFirebaseAdapterPrototype . getRef = function ( resourceConfig , options ) {
187188 options = options || { } ;
188- return new Firebase ( makePath ( options . basePath || this . defaults . basePath || resourceConfig . basePath , options . endpoint || resourceConfig . endpoint ) ) ;
189+ return this . ref . child ( options . endpoint || resourceConfig . endpoint ) ;
189190} ;
190191
191192dsFirebaseAdapterPrototype . find = function ( resourceConfig , id , options ) {
192193 var _this = this ;
193194 return new P ( function ( resolve , reject ) {
194- var resourceRef = _this . getRef ( resourceConfig , options ) ;
195- resourceRef . child ( id ) . once ( 'value' , function ( dataSnapshot ) {
195+ return _this . getRef ( resourceConfig , options ) . child ( id ) . once ( 'value' , function ( dataSnapshot ) {
196196 resolve ( dataSnapshot . val ( ) ) ;
197197 } , reject , _this ) ;
198198 } ) ;
@@ -201,8 +201,7 @@ dsFirebaseAdapterPrototype.find = function (resourceConfig, id, options) {
201201dsFirebaseAdapterPrototype . findAll = function ( resourceConfig , params , options ) {
202202 var _this = this ;
203203 return new P ( function ( resolve , reject ) {
204- var resourceRef = _this . getRef ( resourceConfig , options ) ;
205- resourceRef . once ( 'value' , function ( dataSnapshot ) {
204+ return _this . getRef ( resourceConfig , options ) . once ( 'value' , function ( dataSnapshot ) {
206205 resolve ( filter . call ( emptyStore , values ( dataSnapshot . val ( ) ) , resourceConfig . name , params , options ) ) ;
207206 } , reject , _this ) ;
208207 } ) ;
@@ -243,8 +242,7 @@ dsFirebaseAdapterPrototype.create = function (resourceConfig, attrs, options) {
243242dsFirebaseAdapterPrototype . update = function ( resourceConfig , id , attrs , options ) {
244243 var _this = this ;
245244 return new P ( function ( resolve , reject ) {
246- var resourceRef = _this . getRef ( resourceConfig , options ) ;
247- var itemRef = resourceRef . child ( id ) ;
245+ var itemRef = _this . getRef ( resourceConfig , options ) . child ( id ) ;
248246 itemRef . once ( 'value' , function ( dataSnapshot ) {
249247 try {
250248 var item = dataSnapshot . val ( ) || { } ;
@@ -292,8 +290,7 @@ dsFirebaseAdapterPrototype.updateAll = function (resourceConfig, attrs, params,
292290dsFirebaseAdapterPrototype . destroy = function ( resourceConfig , id , options ) {
293291 var _this = this ;
294292 return new P ( function ( resolve , reject ) {
295- var resourceRef = _this . getRef ( resourceConfig , options ) ;
296- resourceRef . child ( id ) . remove ( function ( err ) {
293+ _this . getRef ( resourceConfig , options ) . child ( id ) . remove ( function ( err ) {
297294 if ( err ) {
298295 reject ( err ) ;
299296 } else {
0 commit comments