FDataEvent.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FDataEvent.h"
  17. #import "FEventRegistration.h"
  18. #import "FIRDatabaseQuery_Private.h"
  19. #import "FIndex.h"
  20. @interface FDataEvent ()
  21. @property(nonatomic, strong, readwrite) id<FEventRegistration>
  22. eventRegistration;
  23. @property(nonatomic, strong, readwrite) FIRDataSnapshot *snapshot;
  24. @property(nonatomic, strong, readwrite) NSString *prevName;
  25. @property(nonatomic, readwrite) FIRDataEventType eventType;
  26. @end
  27. @implementation FDataEvent
  28. @synthesize eventRegistration;
  29. @synthesize snapshot;
  30. @synthesize prevName;
  31. @synthesize eventType;
  32. - (id)initWithEventType:(FIRDataEventType)type
  33. eventRegistration:(id<FEventRegistration>)registration
  34. dataSnapshot:(FIRDataSnapshot *)dataSnapshot {
  35. return [self initWithEventType:type
  36. eventRegistration:registration
  37. dataSnapshot:dataSnapshot
  38. prevName:nil];
  39. }
  40. - (id)initWithEventType:(FIRDataEventType)type
  41. eventRegistration:(id<FEventRegistration>)registration
  42. dataSnapshot:(FIRDataSnapshot *)dataSnapshot
  43. prevName:(NSString *)previousName {
  44. self = [super init];
  45. if (self) {
  46. self.eventRegistration = registration;
  47. self.snapshot = dataSnapshot;
  48. self.prevName = previousName;
  49. self.eventType = type;
  50. }
  51. return self;
  52. }
  53. - (FPath *)path {
  54. // Used for logging, so delay calculation
  55. FIRDatabaseReference *ref = self.snapshot.ref;
  56. if (self.eventType == FIRDataEventTypeValue) {
  57. return ref.path;
  58. } else {
  59. return ref.parent.path;
  60. }
  61. }
  62. - (void)fireEventOnQueue:(dispatch_queue_t)queue {
  63. [self.eventRegistration fireEvent:self queue:queue];
  64. }
  65. - (BOOL)isCancelEvent {
  66. return NO;
  67. }
  68. - (NSString *)description {
  69. return [NSString stringWithFormat:@"event %d, data: %@", (int)eventType,
  70. [snapshot value]];
  71. }
  72. @end