FChange.m 2.0 KB

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