Skip to content

Instantly share code, notes, and snippets.

@doraeminemon
Last active January 2, 2017 13:16
Show Gist options
  • Save doraeminemon/32f6b96f9ad93ae94a55d1ed9ab1b3d1 to your computer and use it in GitHub Desktop.
Save doraeminemon/32f6b96f9ad93ae94a55d1ed9ab1b3d1 to your computer and use it in GitHub Desktop.
Code reading process of AsyncDisplayKit library ( github/facebook/asyncdisplaykit )

Pre-words

This is a description of the though process of me, how I'm going through the code of the AsyncDisplayKit library in order to try to understand it. The current knowledge level of me when I'm reading this :

  • Swift : intermediate / post-intermediate
  • Objectice-C : intermediate
  • C++ / C : mediocre

I'm going to describe the order of the files I'm reading and why. In each and every file, I'm going to describe :

  • Unknown import : These will be due until I can't explain what the class is doing within my depth of knowledge. Otherwise explain and educated guess.
  • Unknown structure : These structure will need to be googled and explain right away.
  • Methods and properties : These will only be explained should they are interesting enough by their own. Otherwise I will try to summarise the whole class purpose.

Summary

AsyncDisplayKit push the whole display process to the background thread by writing a wrapper of UIView in C and C++ ( mostly C++). The wrapper allows for values of UIView to be assigned to the ASDisplayNode and ASControlNode objects, then these values will then be reassigned to the UIView/ NSObject when these objects are actually initialized.

Code reading process

First I'm reading the ASButtonNode.h and ASButtonNode.mm by random. This object are subclassed from ASControlNode so I'm going to read it first.

ASControlNode.mm

Unknown import :

  • #import "ASControlTargetAction.h" : seems to be a convenient class for assigning target - action
  • #import "ASControlNode+Subclasses.h" : categories for subclasses Unknown structure :
  • pragma clang push / pragma clang pop : This is a hack into clang in order to silence the warning given by the clang compiler.
  • ASDN::RecursiveMutex _controlLock; : A C++ bridge to access the RecursiveMutex class inside the ASDN C namespace. Summary : The whole class seems to be a wrapper of an UIControl element. The process use the MutexLocker class in order to verify that only a single writer is allow to access the class at run time. It override the action-target mechanism by using a string mutable dictionary ( _controlEventDispatchTable ) to assign the overrided selector into the action.

//Require more details about the object lifecycle

ASDisplayNode.mm

Unknown imports :

  • ASSentinel : A sentinal variable for marking improper intialize object.
  • ASLayoutableSizeForwarding
  • ASLayoutableSizeHelperForwarding Unknown structure :
  • pragma once : allow source file being compile only once Summary : Object lifecycle follows :
  • loadNode
  • unloadNode
  • shouldLoadViewOrLayer
  • _viewToLoad
  • layerToLoad
  • _loadViewOrLayerIsLayerBacked
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment