@@ -4,12 +4,12 @@ import type { Database } from "firebase/database";
44
55/**
66 * @param {Database } rtdb - Firebase Realtime Database instance.
7- * @param {string } path - Path to the database reference.
7+ * @param {string } ref - Database path or reference.
88 * @param {T | undefined } startWith - Optional default data.
99 * @returns a store with realtime updates on individual database reference data.
1010 */
11- export function refStore < T = any > ( rtdb : Database , path : string , startWith ?: T ) {
12- const dataRef = dbRef ( rtdb , path ) ;
11+ export function refStore < T = any > ( rtdb : Database , ref : string , startWith ?: T ) {
12+ const dataRef = dbRef ( rtdb , ref ) ;
1313
1414 const { subscribe } = writable < T | null > ( startWith , ( set ) => {
1515 const unsubscribe = onValue ( dataRef , ( snapshot ) => {
@@ -27,25 +27,25 @@ export function refStore<T = any>(rtdb: Database, path: string, startWith?: T) {
2727
2828/**
2929 * @param {Database } rtdb - Firebase Realtime Database instance.
30- * @param {string } path - Path to the database reference.
30+ * @param {string } ref - Database path or reference.
3131 * @param {T[] } startWith - Optional default data.
3232 * @returns a store with realtime updates on lists of data.
3333 */
3434export function listStore < T = any > (
3535 rtdb : Database ,
36- path : string ,
36+ ref : string ,
3737 startWith : T [ ] = [ ]
3838) {
39- const listRef = dbRef ( rtdb , path ) ;
39+ const listRef = dbRef ( rtdb , ref ) ;
4040
4141 const { subscribe } = writable < T [ ] > ( startWith , ( set ) => {
4242 const unsubscribe = onValue ( listRef , ( snapshot ) => {
4343 const dataArr : T [ ] = [ ] ;
4444 snapshot . forEach ( ( childSnapshot ) => {
4545 dataArr . push ( {
46- key : childSnapshot . ref . key ,
47- ...( childSnapshot . val ( ) as T ) ,
48- } ) ;
46+ ref : childSnapshot . ref ,
47+ ...childSnapshot . val ( ) ,
48+ } as T ) ;
4949 } ) ;
5050 set ( dataArr ) ;
5151 } ) ;
0 commit comments