Skip to content

Commit

Permalink
Live-editing: root set at edit time
Browse files Browse the repository at this point in the history
Summary:
Otherwise it may be null. Reason the application is also set inside the context when the plugin connects.

Instead of just doing something similar, just set it when editing values.

Reviewed By: LukeDefeo

Differential Revision: D53312024

fbshipit-source-id: a4a98b938f36a6d5e19bcc40ed22d68fc5e563b7
  • Loading branch information
lblasa authored and facebook-github-bot committed Feb 2, 2024
1 parent a055857 commit 35bcc75
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ typedef void (^ReportAttributeEditorResult)(NSError* _Nullable);
@class UIDDescriptorRegister;
@interface UIDAttributeEditor : NSObject

+ (instancetype)attributeEditorForApplication:(UIApplication*)application
withDescriptorRegister:
(UIDDescriptorRegister*)descriptorRegister;
+ (instancetype)attributeEditorWithDescriptorRegister:
(UIDDescriptorRegister*)descriptorRegister;

- (void)editNodeWithId:(NSNumber*)nodeId
value:(id)value
metadataIdentifiers:(NSArray<UIDMetadataId>*)metadataIdentifiers
compoundTypeHint:(UIDCompoundTypeHint)compoundTypeHint
root:(id _Nullable)root
reportResult:(ReportAttributeEditorResult)reportResult;

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,33 @@ + (NSDictionary*)UID_errorPayloadWithError:(NSError*)error {
@end

@interface UIDAttributeEditor () {
__weak UIApplication* _application;
__weak UIDDescriptorRegister* _descriptorRegister;
}

@end

@implementation UIDAttributeEditor

- (id)initWithApplication:(UIApplication*)application
withDescriptorRegister:(UIDDescriptorRegister*)descriptorRegister {
- (id)initWithDescriptorRegister:(UIDDescriptorRegister*)descriptorRegister {
self = [super init];
if (self) {
_application = application;
_descriptorRegister = descriptorRegister;
}

return self;
}

+ (instancetype)attributeEditorForApplication:(UIApplication*)application
withDescriptorRegister:
(UIDDescriptorRegister*)descriptorRegister {
return [[UIDAttributeEditor alloc] initWithApplication:application
withDescriptorRegister:descriptorRegister];
+ (instancetype)attributeEditorWithDescriptorRegister:
(UIDDescriptorRegister*)descriptorRegister {
return [[UIDAttributeEditor alloc]
initWithDescriptorRegister:descriptorRegister];
}

- (void)editNodeWithId:(NSNumber*)nodeId
value:(id)value
metadataIdentifiers:(NSArray<UIDMetadataId>*)metadataIdentifiers
compoundTypeHint:(UIDCompoundTypeHint)compoundTypeHint
root:(id)root
reportResult:(ReportAttributeEditorResult)reportResult {
UIDHierarchyTraversal* const traversal =
[UIDHierarchyTraversal createWithDescriptorRegister:_descriptorRegister];
Expand All @@ -110,7 +107,7 @@ - (void)editNodeWithId:(NSNumber*)nodeId
}

id<NSObject> node = [traversal findWithId:[nodeId unsignedIntegerValue]
inHierarchyWithRoot:editor->_application];
inHierarchyWithRoot:root];
if (!node) {
reportResult(
[NSError UID_errorWithType:AttributeEditorErrorTypeNodeNotFound]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ - (instancetype)initWithApplication:(UIApplication*)application
_observerFactory = observerFactory;
_connection = nil;
_frameworkEventManager = [UIDSerialFrameworkEventManager new];
_attributeEditor =
[UIDAttributeEditor attributeEditorForApplication:application
withDescriptorRegister:descriptorRegister];
_attributeEditor = [UIDAttributeEditor
attributeEditorWithDescriptorRegister:descriptorRegister];
_connectionListeners = [NSMutableSet new];
_accessQueue =
dispatch_queue_create("ui-debugger.context", DISPATCH_QUEUE_SERIAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ - (void)startWithContext:(UIDContext*)context {
[responder error:[NSError UID_errorPayloadWithError:error]];
}
};
id root = strongSelf->_context.application;
[strongSelf->_context.attributeEditor editNodeWithId:nodeId
value:value
metadataIdentifiers:metadataIds
compoundTypeHint:hint
root:root
reportResult:reportResult];
}];
}
Expand Down

0 comments on commit 35bcc75

Please sign in to comment.