@@ -21,7 +21,7 @@ export default class Reference extends ReferenceBase {
2121 db : FirestackDatabase ;
2222 query : Query ;
2323
24- constructor ( db : FirestackDatabase , path : Array < string > , existingModifiers ?: Array < string > ) {
24+ constructor ( db : FirestackDatabase , path : string , existingModifiers ?: Array < string > ) {
2525 super ( db . firestack , path ) ;
2626 this . db = db ;
2727 this . namespace = 'firestack:db:ref' ;
@@ -77,9 +77,8 @@ export default class Reference extends ReferenceBase {
7777 */
7878 push ( value : any , onComplete : Function ) {
7979 if ( value === null || value === undefined ) {
80- // todo add server timestamp to push id call.
81- const _paths = this . path . concat ( [ generatePushID ( this . db . serverTimeOffset ) ] ) ;
82- return new Reference ( this . db , _paths ) ;
80+ const _path = this . path + '/' + generatePushID ( this . db . serverTimeOffset ) ;
81+ return new Reference ( this . db , _path ) ;
8382 }
8483
8584 const path = this . _dbPath ( ) ;
@@ -253,19 +252,12 @@ export default class Reference extends ReferenceBase {
253252 return newRef ;
254253 }
255254
256- // TODO why is this presence here on DB ref? its unrelated?
257- presence ( path : string ) {
258- const presence = this . firestack . presence ;
259- const ref = path ? this . child ( path ) : this ;
260- return presence . ref ( ref , this . _dbPath ( ) ) ;
261- }
262-
263255 onDisconnect ( ) {
264256 return new Disconnect ( this ) ;
265257 }
266258
267259 child ( path : string ) {
268- return new Reference ( this . db , this . path . concat ( path . split ( '/' ) ) ) ;
260+ return new Reference ( this . db , this . path + '/' + path ) ;
269261 }
270262
271263 toString ( ) : string {
@@ -276,22 +268,13 @@ export default class Reference extends ReferenceBase {
276268 * GETTERS
277269 */
278270
279- /**
280- * Returns the current key of this ref - i.e. /foo/bar returns 'bar'
281- * @returns {* }
282- */
283- get key ( ) : string | null {
284- if ( ! this . path . length ) return null ;
285- return this . path . slice ( this . path . length - 1 , this . path . length ) [ 0 ] ;
286- }
287-
288271 /**
289272 * Returns the parent ref of the current ref i.e. a ref of /foo/bar would return a new ref to '/foo'
290273 * @returns {* }
291274 */
292275 get parent ( ) : Reference | null {
293- if ( ! this . path . length || this . path . length === 1 ) return null ;
294- return new Reference ( this . db , this . path . slice ( 0 , - 1 ) ) ;
276+ if ( this . path === '/' ) return null ;
277+ return new Reference ( this . db , this . path . substring ( 0 , this . path . lastIndexOf ( '/' ) ) ) ;
295278 }
296279
297280
@@ -300,22 +283,15 @@ export default class Reference extends ReferenceBase {
300283 * @returns {Reference }
301284 */
302285 get root ( ) : Reference {
303- return new Reference ( this . db , [ ] ) ;
286+ return new Reference ( this . db , '/' ) ;
304287 }
305288
306289 /**
307290 * INTERNALS
308291 */
309292
310- _dbPath ( paths ?: Array < string > ) : string {
311- const path = paths || this . path ;
312- const pathStr = ( path . length > 0 ? path . join ( '/' ) : '/' ) ;
313-
314- if ( pathStr [ 0 ] !== '/' ) {
315- return `/${ pathStr } ` ;
316- }
317-
318- return pathStr ;
293+ _dbPath ( ) : string {
294+ return this . path ;
319295 }
320296
321297 /**
0 commit comments