1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use ModuleDatabase;
use ;
use crate::;
// pub struct FirebaseDatabase<'a>(&'a JsValue);
;
// pub struct FirebaseDbReference<'a>(&'a JsValue);
;
/// Takes a [FirebaseApp] instance and a [url] and returns a [FirebaseDatabase] instance.
/// Fails only if underlying JS function fails.
///
/// ## Examples
/// ```rs
/// use firebase_js_sys::{app::initialize_app, database::get_database};
///
/// let app = initialize_app(config); // config is a FirebaseConfig instance
/// let db = get_database(&app, "https://my-project.firebaseio.com");
/// ```
/// Takes a [FirebaseDatabase] instance and a [path] and returns a [FirebaseDbReference] instance.
/// Fails only if underlying JS function fails.
///
/// You can think of the returne [FirebaseDbReference] as a pointer into a specific part of your database,
/// which you can use in conjunction with other functions to read and write data.
///
/// ## Examples
/// ```rs
/// use firebase_js_sys::{app::initialize_app, database::{get_database, get_ref}};
///
/// let app = initialize_app(config); // config is a FirebaseConfig instance
/// let db = get_database(&app, "https://my-project.firebaseio.com");
///
/// let db_ref = get_ref(&db, "users/1234");
/// let db_ref2 = get_ref(&db, "users/1234/name");
/// ```
/// See [get_ref] documentation. Basically gains a reference to the root of your database,
/// like (but not equivalent I don't think) to calling [get_ref] with a path of `""` or `"/"`.
///
/// ## Examples
/// ```rs
/// use firebase_js_sys::database::get_ref_of_root;
///
/// let db_ref = get_ref_of_root(&db, "/");
/// ```
/// Registers a [callback] to be executed every time some data at the specified [DatabaseReference] changes.
/// Note: This closure will be called the first time the data becomes available.
///
/// ## Examples
/// ```rs
/// use firebase_js::database::{get_database, get_ref, on_value_changed};
///
/// let db = get_database(&app, "https://my-project.firebaseio.com");
/// let db_ref = get_ref(&db, "users/1234");
///
/// on_value_changed(&db_ref, |data| {
/// // do something with data
/// });
/// ```
///
/// ## WIP:
/// - Unsubscribing does not work yet
/// - Potential for convenienve func to take [String] instead of &[DatabaseReference]