FViewCache.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 "FNode.h"
  19. #import "FEmptyNode.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 serverCache:(FCacheNode *)serverCache {
  26. self = [super init];
  27. if (self) {
  28. self.cachedEventSnap = eventCache;
  29. self.cachedServerSnap = serverCache;
  30. }
  31. return self;
  32. }
  33. - (FViewCache *) updateEventSnap:(FIndexedNode *)eventSnap isComplete:(BOOL)complete isFiltered:(BOOL)filtered {
  34. FCacheNode *updatedEventCache = [[FCacheNode alloc] initWithIndexedNode:eventSnap
  35. isFullyInitialized:complete
  36. isFiltered:filtered];
  37. return [[FViewCache alloc] initWithEventCache:updatedEventCache serverCache:self.cachedServerSnap];
  38. }
  39. - (FViewCache *) updateServerSnap:(FIndexedNode *)serverSnap isComplete:(BOOL)complete isFiltered:(BOOL)filtered {
  40. FCacheNode *updatedServerCache = [[FCacheNode alloc] initWithIndexedNode:serverSnap
  41. isFullyInitialized:complete
  42. isFiltered:filtered];
  43. return [[FViewCache alloc] initWithEventCache:self.cachedEventSnap serverCache:updatedServerCache];
  44. }
  45. - (id<FNode>) completeEventSnap {
  46. return (self.cachedEventSnap.isFullyInitialized) ? self.cachedEventSnap.node : nil;
  47. }
  48. - (id<FNode>) completeServerSnap {
  49. return (self.cachedServerSnap.isFullyInitialized) ? self.cachedServerSnap.node : nil;
  50. }
  51. @end