FChange.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "FirebaseDatabase/Sources/Core/View/FChange.h"
  17. @interface FChange ()
  18. @property(nonatomic, strong, readwrite) NSString *prevKey;
  19. @end
  20. @implementation FChange
  21. - (id)initWithType:(FIRDataEventType)type
  22. indexedNode:(FIndexedNode *)indexedNode {
  23. return [self initWithType:type
  24. indexedNode:indexedNode
  25. childKey:nil
  26. oldIndexedNode:nil];
  27. }
  28. - (id)initWithType:(FIRDataEventType)type
  29. indexedNode:(FIndexedNode *)indexedNode
  30. childKey:(NSString *)childKey {
  31. return [self initWithType:type
  32. indexedNode:indexedNode
  33. childKey:childKey
  34. oldIndexedNode:nil];
  35. }
  36. - (id)initWithType:(FIRDataEventType)type
  37. indexedNode:(FIndexedNode *)indexedNode
  38. childKey:(NSString *)childKey
  39. oldIndexedNode:(FIndexedNode *)oldIndexedNode {
  40. self = [super init];
  41. if (self != nil) {
  42. self->_type = type;
  43. self->_indexedNode = indexedNode;
  44. self->_childKey = childKey;
  45. self->_oldIndexedNode = oldIndexedNode;
  46. }
  47. return self;
  48. }
  49. - (FChange *)changeWithPrevKey:(NSString *)prevKey {
  50. FChange *newChange = [[FChange alloc] initWithType:self.type
  51. indexedNode:self.indexedNode
  52. childKey:self.childKey
  53. oldIndexedNode:self.oldIndexedNode];
  54. newChange.prevKey = prevKey;
  55. return newChange;
  56. }
  57. - (NSString *)description {
  58. return [NSString stringWithFormat:@"event: %d, data: %@", (int)self.type,
  59. [self.indexedNode.node val]];
  60. }
  61. @end