database.read(pathOrRef)
Returns the data at this path in firebase's database.
Type | Description | |
---|---|---|
pathOrRef Optional | String or Firebase Database Reference | The path or reference to the value to read. |
Whatever value is store at this path in the database (number, string, object, etc).
function* getTodo() {
const firstTodo = yield call(rsf.database.read, 'todos/1');
yield put(gotTodo(firstTodo));
}
database.create(pathOrRef, data)
Create a new path in the database and stores the data there.
Type | Description | |
---|---|---|
pathOrRef Optional | String or Firebase Database Reference | The path or reference to the destination. |
data Optional | Any value | The value to store. |
The key newly created (a string).
function* addTodo() {
const key = yield call(rsf.database.create, 'todos', {
done: false,
label: 'Do this',
});
// `key` is something like "-Kfn7EyLEoHax0YGoQr0"
}
database.update(pathOrRef, data)
Replace the value store at path
in the database with data
.
Type | Description | |
---|---|---|
pathOrRef Optional | String or Firebase Database Reference | The path or reference to the value to update. |
data Optional | Any value | The value to store. |
function* updateTodo() {
yield call(rsf.database.update, 'todos/-Kfn7EyLEoHax0YGoQr0', {
done: true, // yay, it's done now!
label: 'Do this',
});
}
database.patch(pathOrRef, data)
Patches the value store at path
in the database with data
. Like database.update
but doesn't remove unmentionned keys.
Type | Description | |
---|---|---|
pathOrRef Optional | String or Firebase Database Reference | The path or reference to the value to update. |
data Optional | Any value | The value to store. |
function* updateTodo() {
// With this call, no need to re-send the todo label.
yield call(rsf.database.patch, 'todos/-Kfn7EyLEoHax0YGoQr0', {
done: true,
});
}
database.delete(pathOrRef)
Removes the value at the specified path
in the database.
Type | Description | |
---|---|---|
pathOrRef Optional | String or Firebase Database Reference | The path or reference to the value to delete. |
function* deleteTodo() {
yield call(rsf.database.delete, 'todos/-Kfn7EyLEoHax0YGoQr0');
}
database.channel(pathOrRef, event, buffer)
Returns a redux-saga Channel which emits every change at the specified path in the database.
Type | Description | |
---|---|---|
pathOrRef Optional | String or Firebase Database Reference | The path or reference to the value to read. |
event Optional | String | Defaults to |
buffer Optional | A Buffer | Defaults to |
A redux-saga Channel which emits every change at the specified path in the database. The emitted value is an object with two keys:
snapshot
: a firebase.database.DataSnapshot ;value
: the result of snapshot.val()
, which is the actual value stored in the database (any type).function* syncTodosSaga() {
const channel = yield call(rsf.database.channel, 'todos');
while(true) {
const { value: todos } = yield take(channel);
yield put(syncTodos(todos));
}
}
database.sync(pathOrRef, options, event)
Automatically dispatches a redux action every time path
changes.
Type | Description | |
---|---|---|
pathOrRef Optional | String or Firebase Database Reference | The path or reference to the value to synced. |
options Optional | Object | An object to configure how the database should be synchronised. It must contain at least the |
event Optional | String | One of the following strings: |
import { syncTodos } from '../actionCreators/todos';
function* todoRootSaga() {
yield fork(
rsf.database.sync,
'todos',
{ successActionCreator: syncTodos }
);
}