FViewCache.m 2.4 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 "FViewCache.h"
  17. #import "FCacheNode.h"
  18. #import "FEmptyNode.h"
  19. #import "FNode.h"
  20. @interface FViewCache ()
  21. @property(nonatomic, strong, readwrite) FCacheNode *cachedEventSnap;
  22. @property(nonatomic, strong, readwrite) FCacheNode *cachedServerSnap;
  23. @end
  24. @implementation FViewCache
  25. - (id)initWithEventCache:(FCacheNode *)eventCache
  26. serverCache:(FCacheNode *)serverCache {
  27. self = [super init];
  28. if (self) {
  29. self.cachedEventSnap = eventCache;
  30. self.cachedServerSnap = serverCache;
  31. }
  32. return self;
  33. }
  34. - (FViewCache *)updateEventSnap:(FIndexedNode *)eventSnap
  35. isComplete:(BOOL)complete
  36. isFiltered:(BOOL)filtered {
  37. FCacheNode *updatedEventCache =
  38. [[FCacheNode alloc] initWithIndexedNode:eventSnap
  39. isFullyInitialized:complete
  40. isFiltered:filtered];
  41. return [[FViewCache alloc] initWithEventCache:updatedEventCache
  42. serverCache:self.cachedServerSnap];
  43. }
  44. - (FViewCache *)updateServerSnap:(FIndexedNode *)serverSnap
  45. isComplete:(BOOL)complete
  46. isFiltered:(BOOL)filtered {
  47. FCacheNode *updatedServerCache =
  48. [[FCacheNode alloc] initWithIndexedNode:serverSnap
  49. isFullyInitialized:complete
  50. isFiltered:filtered];
  51. return [[FViewCache alloc] initWithEventCache:self.cachedEventSnap
  52. serverCache:updatedServerCache];
  53. }
  54. - (id<FNode>)completeEventSnap {
  55. return (self.cachedEventSnap.isFullyInitialized) ? self.cachedEventSnap.node
  56. : nil;
  57. }
  58. - (id<FNode>)completeServerSnap {
  59. return (self.cachedServerSnap.isFullyInitialized)
  60. ? self.cachedServerSnap.node
  61. : nil;
  62. }
  63. @end