[android][ios][database] Add missing setPriority and setWithPriority methods

This commit is contained in:
Chris Bianca 2017-07-19 18:18:16 +01:00
parent c2400edd0a
commit 46772d253d
6 changed files with 137 additions and 12 deletions

View File

@ -88,7 +88,6 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
DatabaseReference ref = mFirebaseDatabase.getReference(path);
Map<String, Object> m = Utils.recursivelyDeconstructReadableMap(props);
DatabaseReference.CompletionListener listener = new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError error, DatabaseReference ref) {
@ -99,6 +98,44 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
ref.setValue(m.get("value"), listener);
}
@ReactMethod
public void priority(
final String path,
final ReadableMap priority,
final Callback callback) {
DatabaseReference ref = mFirebaseDatabase.getReference(path);
Map<String, Object> priorityMap = Utils.recursivelyDeconstructReadableMap(priority);
DatabaseReference.CompletionListener listener = new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError error, DatabaseReference ref) {
handleCallback("priority", callback, error);
}
};
ref.setPriority(priorityMap.get("value"), listener);
}
@ReactMethod
public void withPriority(
final String path,
final ReadableMap data,
final ReadableMap priority,
final Callback callback) {
DatabaseReference ref = mFirebaseDatabase.getReference(path);
Map<String, Object> dataMap = Utils.recursivelyDeconstructReadableMap(data);
Map<String, Object> priorityMap = Utils.recursivelyDeconstructReadableMap(priority);
DatabaseReference.CompletionListener listener = new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError error, DatabaseReference ref) {
handleCallback("withPriority", callback, error);
}
};
ref.setValue(dataMap.get("value"), priorityMap.get("value"), listener);
}
@ReactMethod
public void update(final String path,
final ReadableMap props,

View File

@ -148,6 +148,25 @@ RCT_EXPORT_METHOD(set:
}];
}
RCT_EXPORT_METHOD(priority:(NSString *) path
priorityData:(NSDictionary *) priorityData
callback:(RCTResponseSenderBlock) callback) {
FIRDatabaseReference *ref = [self getPathRef:path];
[ref setPriority:[priorityData valueForKey:@"value"] withCompletionBlock:^(NSError * _Nullable error, FIRDatabaseReference * _Nonnull ref) {
[self handleCallback:@"priority" callback:callback databaseError:error];
}];
}
RCT_EXPORT_METHOD(withPriority:(NSString *) path
data:(NSDictionary *) data
priorityData:(NSDictionary *) priorityData
callback:(RCTResponseSenderBlock) callback) {
FIRDatabaseReference *ref = [self getPathRef:path];
[ref setValue:[data valueForKey:@"value"] andPriority:[priorityData valueForKey:@"value"] withCompletionBlock:^(NSError * _Nullable error, FIRDatabaseReference * _Nonnull ref) {
[self handleCallback:@"withPriority" callback:callback databaseError:error];
}];
}
RCT_EXPORT_METHOD(update:
(NSString *) path
value:

View File

@ -91,6 +91,29 @@ export default class Reference extends ReferenceBase {
return promisify('set', FirebaseDatabase)(path, _value);
}
/**
*
* @param priority
* @returns {*}
*/
setPriority(priority: string | number | null) {
const path = this.path;
const _priority = this._serializeAnyType(priority);
return promisify('priority', FirebaseDatabase)(path, _priority);
}
/**
*
* @param priority
* @returns {*}
*/
setWithPriority(value: any, priority: string | number | null) {
const path = this.path;
const _priority = this._serializeAnyType(priority);
const _value = this._serializeAnyType(value);
return promisify('withPriority', FirebaseDatabase)(path, _value, _priority);
}
/**
*
* @param val

View File

@ -90,16 +90,17 @@ PODS:
- GoogleToolboxForMac/NSString+URLArguments (2.1.1)
- GTMSessionFetcher/Core (1.1.10)
- Protobuf (3.3.0)
- React (0.44.3):
- React/Core (= 0.44.3)
- React/Core (0.44.3):
- React (0.44.0):
- React/Core (= 0.44.0)
- React/Core (0.44.0):
- React/cxxreact
- Yoga (= 0.44.3.React)
- React/cxxreact (0.44.3):
- Yoga (= 0.44.0.React)
- React/cxxreact (0.44.0):
- React/jschelpers
- React/jschelpers (0.44.3)
- RNFirebase (2.0.0)
- Yoga (0.44.3.React)
- React/jschelpers (0.44.0)
- RNFirebase (2.0.4):
- React
- Yoga (0.44.0.React)
DEPENDENCIES:
- Firebase/AdMob
@ -142,9 +143,9 @@ SPEC CHECKSUMS:
GoogleToolboxForMac: 8e329f1b599f2512c6b10676d45736bcc2cbbeb0
GTMSessionFetcher: 30d874b96d0d76028f61fbd122801e3f030d47db
Protobuf: d582fecf68201eac3d79ed61369ef45734394b9c
React: 6361345ebeb769a929e10a06baf0c868d6d03ad5
RNFirebase: dcc4dcb1c9400a9bc01866e50d1351272a7df311
Yoga: c90474ca3ec1edba44c97b6c381f03e222a9e287
React: d2077cc20245ccdc8bfe1fdc002f2003318ae8d8
RNFirebase: 3e5a3ff431c5c8a997152f5f19d354e1ca66f65d
Yoga: a92a5d8e128905bf9f29c82f870192a6e873dd98
PODFILE CHECKSUM: 45666f734ebfc8b3b0f2be0a83bc2680caeb502f

View File

@ -17,6 +17,7 @@ import rootTests from './rootTests';
import transactionTests from './transactionTests';
import queryTests from './queryTests';
import issueSpecificTests from './issueSpecificTests';
import priorityTests from './priorityTests';
import DatabaseContents from '../../support/DatabaseContents';
@ -24,6 +25,7 @@ const testGroups = [
issueSpecificTests, factoryTests, keyTests, parentTests, childTests, rootTests,
pushTests, onTests, onValueTests, onChildAddedTests, offTests, onceTests, updateTests,
removeTests, setTests, transactionTests, queryTests, refTests, isEqualTests,
priorityTests,
];
function registerTestSuite(testSuite) {

View File

@ -0,0 +1,43 @@
import DatabaseContents from '../../support/DatabaseContents';
function setTests({ describe, it, firebase }) {
describe('ref().priority', () => {
it('setPriority() should correctly set a priority for all non-null values', async () => {
await Promise.map(Object.keys(DatabaseContents.DEFAULT), async (dataRef) => {
// Setup
const ref = firebase.native.database().ref(`tests/types/${dataRef}`);
// Test
await ref.setPriority(1);
// Assertion
await ref.once('value').then((snapshot) => {
if (snapshot.val() !== null) {
snapshot.getPriority().should.eql(1);
}
});
});
});
it('setWithPriority() should correctly set the priority', async () => {
// Setup
const ref = firebase.native.database().ref('tests/types/number');
// Test
await ref.setWithPriority(DatabaseContents.DEFAULT.number, '2');
// Assertion
await ref.once('value').then((snapshot) => {
snapshot.getPriority().should.eql('2');
});
});
});
}
export default setTests;