Skip to content

Commit

Permalink
Merge pull request facebook#536 from adamjernst/scope
Browse files Browse the repository at this point in the history
Docs and fixes for CKComponentScope stateUpdater
  • Loading branch information
adamjernst committed Apr 17, 2016
2 parents 0faff1c + 2e43435 commit c813e5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion ComponentKit/Core/Scope/CKComponentScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ class CKComponentScope {
/** @return The current state for the component being built. */
id state(void) const;

/** @return A block that schedules a state update. Usually, use [CKComponent -updateState:mode:] instead. */
/**
@return A block that schedules a state update when invoked.
@discussion Usually, prefer the more idiomatic [CKComponent -updateState:mode:]. Use this in the rare case where you
need to pass a state updater to a child component during +new. (Usually, the child should communicate back via
CKComponentAction and the parent should call -updateState:mode: on itself; this hides the implementation details
of the parent's state from the child.)
*/
CKComponentStateUpdater stateUpdater(void) const;

private:
Expand Down
4 changes: 3 additions & 1 deletion ComponentKit/Core/Scope/CKComponentScope.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@

CKComponentStateUpdater CKComponentScope::stateUpdater(void) const
{
return ^(id (^update)(id), CKUpdateMode mode){ [_scopeHandle updateState:update mode:mode]; };
// We must capture _scopeHandle in a local, since this may be destroyed by the time the block executes.
CKComponentScopeHandle *const scopeHandle = _scopeHandle;
return ^(id (^update)(id), CKUpdateMode mode){ [scopeHandle updateState:update mode:mode]; };
}

0 comments on commit c813e5d

Please sign in to comment.