Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Cell Node Properties Atomic #74

Merged
merged 8 commits into from
May 2, 2017
Merged

Make Cell Node Properties Atomic #74

merged 8 commits into from
May 2, 2017

Conversation

Adlai-Holler
Copy link
Member

This way if you do logging or other tasks on background threads, you can read indexPath and supplementaryElementKind safely.

It kind of spiraled out of control, so:

  • Add ASRangeManagedNode protocol to cover ASCollectionNode and ASTableNode.
  • Remove ASDataControllerEnvironmentDelegate – instead pass in ASRangeManagedNode to init.
  • Make the storage for ASDataController.visibleMap/pendingMap atomic.
  • Make the storage for ASCellNode.owningNode atomic.
  • (For good measure) Modify places in ASDataController where we repeatedly access a weak variable to use a strong variable instead.

*/
@property (weak, nonatomic, readonly, nullable) ASDisplayNode *owningNode;
@property (weak, readonly, nullable) id<ASRangeManagedNode> owningNode;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This s technically a breaking API change but it's so minor that we shouldn't worry about it. Virtually nobody uses this property – it was recently added and probably shouldn't be public anyway – and the migration pathway is trivial.

@Adlai-Holler
Copy link
Member Author

Hmm I wonder if ASRangeManagedNode should be a base class rather than a protocol. It may well evolve into one over time. I remember @appleguy you proposed having a shared base class for these kinds of things. Let's leave it as a protocol for now, then see what the world looks like after we make naked-ASTableView-and-ASCollectionView usage unavailable.

@@ -87,7 +88,7 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
* @return The supplementary element kind, or @c nil if this node does not represent a supplementary element.
*/
//TODO change this to be a generic "kind" or "elementKind" that exposes `nil` for row kind
@property (nonatomic, copy, readonly, nullable) NSString *supplementaryElementKind;
@property (copy, readonly, nullable) NSString *supplementaryElementKind;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is implied, but stylistically, I think it would be a good idea to require atomic to be stated explicitly for properties that intend it. Although it might become the more common thing, currently it's uncommon enough that most cases where it is omitted could be confused for mistakes. Any thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm down with it. The explicitness is nice.

@appleguy
Copy link
Member

@Adlai-Holler Yes, I still think having a true bass class would be a very good thing. It would be a substantial project to build - I attempted it over Christmas holiday the year before this most recent, and it got complicated. I think it would be an architectural gift that keeps on giving, though :). In particular, it could even provide some APIs that are appropriate to offer publicly, and allow advanced apps to create custom range-managed scrollers.

/**
* Basically ASTableNode or ASCollectionNode.
*/
@protocol ASRangeManagedNode <NSObject, ASTraitEnvironment>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm being overly semantic, but the methods these adopt don't seem to match the name. I can imagine nodes that range manage other nodes that don't have index paths. Anyway, wondering if there's a better name but I don't have suggestions.

Also, should it be ASRangeManagingNode instead? That would better align with ASHierarchyStateRangeManaged state naming.

@@ -80,7 +80,7 @@ - (instancetype)initWithStyle:(UITableViewStyle)style
[self setViewBlock:^{
// Variable will be unused if event logging is off.
__unused __typeof__(self) strongSelf = weakSelf;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the strongSelf necessary? If the viewBlock is running, self shouldn't be nil, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep but we should strongify once, rather than implicitly strongifying each time we use weakSelf.

*/
@property (nonatomic, strong, readonly) ASElementMap *visibleMap;
@property (atomic, copy, readonly) ASElementMap *visibleMap;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there asserts that ensure this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need asserts to check this. We only change it internally. And we can't override atomic accessors so it's impossible to assert.

@ghost
Copy link

ghost commented May 2, 2017

🚫 CI failed with log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants