Merge pull request #461 from facebook/memoryMethods

Updating API names for network range and memory culling before ASDK 1.2 tag.
This commit is contained in:
appleguy 2015-05-21 22:44:44 -10:00
commit b9597ff96b
10 changed files with 50 additions and 47 deletions

View File

@ -190,8 +190,9 @@
* *
* @discussion Subclasses may override this method to be notified when they should begin to fetch data. Fetching * @discussion Subclasses may override this method to be notified when they should begin to fetch data. Fetching
* should be done asynchronously. The node is also responsible for managing the memory of any data. * should be done asynchronously. The node is also responsible for managing the memory of any data.
* The data may be remote and accessed via the network, but could also be a local database query.
*/ */
- (void)fetchRemoteData ASDISPLAYNODE_REQUIRES_SUPER; - (void)fetchData ASDISPLAYNODE_REQUIRES_SUPER;
/** /**
* @abstract Indicates that the receiver is about to display its subnodes. This method is not called if there are no * @abstract Indicates that the receiver is about to display its subnodes. This method is not called if there are no
@ -323,18 +324,18 @@
* Provides an opportunity to clear backing store and other memory-intensive intermediates, such as text layout managers * Provides an opportunity to clear backing store and other memory-intensive intermediates, such as text layout managers
* on the current node. * on the current node.
* *
* @discussion Called by -recursivelyClearRendering. Base class implements self.contents = nil, clearing any backing * @discussion Called by -recursivelyClearContents. Base class implements self.contents = nil, clearing any backing
* store, for asynchronous regeneration when needed. * store, for asynchronous regeneration when needed.
*/ */
- (void)clearRendering ASDISPLAYNODE_REQUIRES_SUPER; - (void)clearContents ASDISPLAYNODE_REQUIRES_SUPER;
/** /**
* Provides an opportunity to clear any remote data on the current node. * Provides an opportunity to clear any fetched data (e.g. remote / network or database-queried) on the current node.
* *
* @discussion This will not clear data recursively for all subnodes. Either call -recursivelyClearRemoteData or * @discussion This will not clear data recursively for all subnodes. Either call -recursivelyClearFetchedData or
* selectively clear remote data. * selectively clear fetched data.
*/ */
- (void)clearRemoteData ASDISPLAYNODE_REQUIRES_SUPER; - (void)clearFetchedData ASDISPLAYNODE_REQUIRES_SUPER;
/** @name Placeholders */ /** @name Placeholders */

View File

@ -312,7 +312,7 @@ typedef CALayer *(^ASDisplayNodeLayerBlock)();
- (void)recursivelySetDisplaySuspended:(BOOL)flag; - (void)recursivelySetDisplaySuspended:(BOOL)flag;
/** /**
* @abstract Calls -clearRendering on the receiver and its subnode hierarchy. * @abstract Calls -clearContents on the receiver and its subnode hierarchy.
* *
* @discussion Clears backing stores and other memory-intensive intermediates. * @discussion Clears backing stores and other memory-intensive intermediates.
* If the node is removed from a visible hierarchy and then re-added, it will automatically trigger a new asynchronous display, * If the node is removed from a visible hierarchy and then re-added, it will automatically trigger a new asynchronous display,
@ -322,27 +322,27 @@ typedef CALayer *(^ASDisplayNodeLayerBlock)();
* @see displaySuspended and setNeedsDisplay * @see displaySuspended and setNeedsDisplay
*/ */
- (void)recursivelyClearRendering; - (void)recursivelyClearContents;
/** /**
* @abstract Calls -clearRemoteData on the receiver and its subnode hierarchy. * @abstract Calls -clearFetchedData on the receiver and its subnode hierarchy.
* *
* @discussion Clears any memory-intensive fetched content. * @discussion Clears any memory-intensive fetched content.
* This method is used to notify the node that it should purge any content that is both expensive to fetch and to * This method is used to notify the node that it should purge any content that is both expensive to fetch and to
* retain in memory. * retain in memory.
* *
* @see clearRemoteData and fetchRemoteData * @see clearFetchedData and fetchData
*/ */
- (void)recursivelyClearRemoteData; - (void)recursivelyClearFetchedData;
/** /**
* @abstract Calls -fetchRemoteData on the receiver and its subnode hierarchy. * @abstract Calls -fetchData on the receiver and its subnode hierarchy.
* *
* @discussion Fetches content from remote sources for the current node and all subnodes. * @discussion Fetches content from remote sources for the current node and all subnodes.
* *
* @see fetchRemoteData and clearRemoteData * @see fetchData and clearFetchedData
*/ */
- (void)recursivelyFetchRemoteData; - (void)recursivelyFetchData;
/** /**
* @abstract Toggle displaying a placeholder over the node that covers content until the node and all subnodes are * @abstract Toggle displaying a placeholder over the node that covers content until the node and all subnodes are

View File

@ -90,8 +90,8 @@ void ASDisplayNodePerformBlockOnMainThread(void (^block)())
// Subclasses should never override these // Subclasses should never override these
ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(calculatedSize)), @"Subclass %@ must not override calculatedSize method", NSStringFromClass(self)); ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(calculatedSize)), @"Subclass %@ must not override calculatedSize method", NSStringFromClass(self));
ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(measure:)), @"Subclass %@ must not override measure method", NSStringFromClass(self)); ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(measure:)), @"Subclass %@ must not override measure method", NSStringFromClass(self));
ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(recursivelyClearRendering)), @"Subclass %@ must not override recursivelyClearRendering method", NSStringFromClass(self)); ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(recursivelyClearContents)), @"Subclass %@ must not override recursivelyClearContents method", NSStringFromClass(self));
ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(recursivelyClearRemoteData)), @"Subclass %@ must not override recursivelyClearRemoteData method", NSStringFromClass(self)); ASDisplayNodeAssert(!ASDisplayNodeSubclassOverridesSelector(self, @selector(recursivelyClearFetchedData)), @"Subclass %@ must not override recursivelyClearFetchedData method", NSStringFromClass(self));
} }
+ (BOOL)layerBackedNodesEnabled + (BOOL)layerBackedNodesEnabled
@ -1331,44 +1331,44 @@ static NSInteger incrementIfFound(NSInteger i) {
[self __exitedHierarchy]; [self __exitedHierarchy];
} }
- (void)clearRendering - (void)clearContents
{ {
self.layer.contents = nil; self.layer.contents = nil;
_placeholderLayer.contents = nil; _placeholderLayer.contents = nil;
} }
- (void)recursivelyClearRendering - (void)recursivelyClearContents
{ {
for (ASDisplayNode *subnode in self.subnodes) { for (ASDisplayNode *subnode in self.subnodes) {
[subnode recursivelyClearRendering]; [subnode recursivelyClearContents];
} }
[self clearRendering]; [self clearContents];
} }
- (void)fetchRemoteData - (void)fetchData
{ {
// subclass override // subclass override
} }
- (void)recursivelyFetchRemoteData - (void)recursivelyFetchData
{ {
for (ASDisplayNode *subnode in self.subnodes) { for (ASDisplayNode *subnode in self.subnodes) {
[subnode recursivelyFetchRemoteData]; [subnode recursivelyFetchData];
} }
[self fetchRemoteData]; [self fetchData];
} }
- (void)clearRemoteData - (void)clearFetchedData
{ {
// subclass override // subclass override
} }
- (void)recursivelyClearRemoteData - (void)recursivelyClearFetchedData
{ {
for (ASDisplayNode *subnode in self.subnodes) { for (ASDisplayNode *subnode in self.subnodes) {
[subnode recursivelyClearRemoteData]; [subnode recursivelyClearFetchedData];
} }
[self clearRemoteData]; [self clearFetchedData];
} }
- (void)layout - (void)layout
@ -1822,12 +1822,12 @@ static const char *ASDisplayNodeAssociatedNodeKey = "ASAssociatedNode";
- (void)reclaimMemory - (void)reclaimMemory
{ {
[self clearRendering]; [self clearContents];
} }
- (void)recursivelyReclaimMemory - (void)recursivelyReclaimMemory
{ {
[self recursivelyClearRendering]; [self recursivelyClearContents];
} }
@end @end

View File

@ -162,9 +162,9 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
} }
#pragma mark - ASDisplayNode Overrides #pragma mark - ASDisplayNode Overrides
- (void)clearRendering - (void)clearContents
{ {
[super clearRendering]; // This actually clears the contents, so we need to do this first for our displayedImageIdentifier to be meaningful. [super clearContents]; // This actually clears the contents, so we need to do this first for our displayedImageIdentifier to be meaningful.
[self _setDisplayedImageIdentifier:nil withImage:nil]; [self _setDisplayedImageIdentifier:nil withImage:nil];
if (_downloadIdentifier) { if (_downloadIdentifier) {
@ -177,12 +177,12 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
{ {
[super displayWillStart]; [super displayWillStart];
[self fetchRemoteData]; [self fetchData];
} }
- (void)fetchRemoteData - (void)fetchData
{ {
[super fetchRemoteData]; [super fetchData];
[self _loadImageIdentifiers]; [self _loadImageIdentifiers];
} }

View File

@ -127,12 +127,12 @@
{ {
[super displayWillStart]; [super displayWillStart];
[self fetchRemoteData]; [self fetchData];
} }
- (void)clearRemoteData - (void)clearFetchedData
{ {
[super clearRemoteData]; [super clearFetchedData];
{ {
ASDN::MutexLocker l(_lock); ASDN::MutexLocker l(_lock);
@ -143,9 +143,9 @@
} }
} }
- (void)fetchRemoteData - (void)fetchData
{ {
[super fetchRemoteData]; [super fetchData];
{ {
ASDN::MutexLocker l(_lock); ASDN::MutexLocker l(_lock);

View File

@ -226,12 +226,12 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
[self _invalidateRenderer]; [self _invalidateRenderer];
} }
- (void)clearRendering - (void)clearContents
{ {
// We discard the backing store and renderer to prevent the very large // We discard the backing store and renderer to prevent the very large
// memory overhead of maintaining these for all text nodes. They can be // memory overhead of maintaining these for all text nodes. They can be
// regenerated when layout is necessary. // regenerated when layout is necessary.
[super clearRendering]; // ASDisplayNode will set layer.contents = nil [super clearContents]; // ASDisplayNode will set layer.contents = nil
[self _invalidateRenderer]; [self _invalidateRenderer];
} }

View File

@ -16,13 +16,13 @@
- (void)node:(ASDisplayNode *)node enteredRangeOfType:(ASLayoutRangeType)rangeType - (void)node:(ASDisplayNode *)node enteredRangeOfType:(ASLayoutRangeType)rangeType
{ {
ASDisplayNodeAssert(rangeType == ASLayoutRangeTypePreload, @"Preload delegate should not handle other ranges"); ASDisplayNodeAssert(rangeType == ASLayoutRangeTypePreload, @"Preload delegate should not handle other ranges");
[node recursivelyFetchRemoteData]; [node recursivelyFetchData];
} }
- (void)node:(ASDisplayNode *)node exitedRangeOfType:(ASLayoutRangeType)rangeType - (void)node:(ASDisplayNode *)node exitedRangeOfType:(ASLayoutRangeType)rangeType
{ {
ASDisplayNodeAssert(rangeType == ASLayoutRangeTypePreload, @"Preload delegate should not handle other ranges"); ASDisplayNodeAssert(rangeType == ASLayoutRangeTypePreload, @"Preload delegate should not handle other ranges");
[node recursivelyClearRemoteData]; [node recursivelyClearFetchedData];
} }
@end @end

View File

@ -50,7 +50,7 @@
[node recursivelySetDisplaySuspended:YES]; [node recursivelySetDisplaySuspended:YES];
[node.view removeFromSuperview]; [node.view removeFromSuperview];
[node recursivelyClearRendering]; [node recursivelyClearContents];
} }
@end @end

View File

@ -42,6 +42,7 @@
XCTAssert([context isCancelled], @"Context should be cancelled"); XCTAssert([context isCancelled], @"Context should be cancelled");
} }
/* This test is currently unreliable. See https://github.com/facebook/AsyncDisplayKit/issues/459
- (void)testAsyncContextInvalidation - (void)testAsyncContextInvalidation
{ {
NSURL *url = [self randomURL]; NSURL *url = [self randomURL];
@ -56,6 +57,7 @@
[context cancel]; [context cancel];
[self waitForExpectationsWithTimeout:30.0 handler:nil]; [self waitForExpectationsWithTimeout:30.0 handler:nil];
} }
*/
- (void)testContextSessionCanceled - (void)testContextSessionCanceled
{ {

View File

@ -10,4 +10,4 @@ SPEC CHECKSUMS:
FBSnapshotTestCase: 3dc3899168747a0319c5278f5b3445c13a6532dd FBSnapshotTestCase: 3dc3899168747a0319c5278f5b3445c13a6532dd
OCMock: a6a7dc0e3997fb9f35d99f72528698ebf60d64f2 OCMock: a6a7dc0e3997fb9f35d99f72528698ebf60d64f2
COCOAPODS: 0.36.3 COCOAPODS: 0.37.1