Skip to content

Commit e7f268c

Browse files
authored
Merge pull request #210 from FrankSalad/v3-setWithPriority
[v3] Add setWithPriority support to ref.
2 parents 6e6fd33 + f7ea2f4 commit e7f268c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

docs/api/database.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ firestack.database()
2525
});
2626
```
2727

28+
Basic write with priority example:
29+
```javascript
30+
firestack.database()
31+
.ref('posts/1235')
32+
.setWithPriority({
33+
title: 'Another Awesome Post',
34+
content: 'Some awesome content',
35+
}, 10);
36+
```
37+
Useful for `orderByPriority` queries.
38+
2839
## Unmounted components
2940

3041
Listening to database updates on unmounted components will trigger a warning:

ios/Firestack/FirestackDatabase.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,17 @@ - (id) init
400400
}];
401401
}
402402

403+
RCT_EXPORT_METHOD(setWithPriority:(NSString *) path
404+
data:(NSDictionary *)data
405+
priority: (NSDictionary *)priority
406+
callback:(RCTResponseSenderBlock) callback)
407+
{
408+
FIRDatabaseReference *ref = [self getPathRef:path];
409+
[ref setValue:[data valueForKey:@"value"] andPriority:[priority valueForKey:@"value"] withCompletionBlock:^(NSError * _Nullable error, FIRDatabaseReference * _Nonnull ref) {
410+
[self handleCallback:@"setWithPriority" callback:callback databaseError:error];
411+
}];
412+
}
413+
403414
RCT_EXPORT_METHOD(update:(NSString *) path
404415
value:(NSDictionary *)value
405416
callback:(RCTResponseSenderBlock) callback)

lib/modules/database/reference.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ export default class Reference extends ReferenceBase {
5050
return promisify('set', FirestackDatabase)(path, _value);
5151
}
5252

53+
/**
54+
*
55+
* @param value
56+
* @returns {*}
57+
*/
58+
setWithPriority(value: any, priority: any) {
59+
const path = this._dbPath();
60+
const _value = this._serializeAnyType(value);
61+
const _priority = this._serializeAnyType(priority);
62+
return promisify('setWithPriority', FirestackDatabase)(path, _value, _priority);
63+
}
64+
5365
/**
5466
*
5567
* @param val

0 commit comments

Comments
 (0)