Files
flipper/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Observer/UIDTreeObserverFactory.m
Lorenzo Blasa db7aa9eeaf OSS
Summary: Move UIDebugger plugin to OSS space.

Reviewed By: passy

Differential Revision: D47634848

fbshipit-source-id: 90e8c0181a2434d0e5d76bdb99b902051e6d702e
2023-07-21 04:47:13 -07:00

67 lines
1.4 KiB
Objective-C

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#if FB_SONARKIT_ENABLED
#import "UIDTreeObserverFactory.h"
#import "UIDUIApplicationObserver.h"
@interface UIDTreeObserverFactory () {
NSMutableArray<id<UIDTreeObserverBuilder>>* _builders;
}
@end
@implementation UIDTreeObserverFactory
- (instancetype)init {
self = [super init];
if (self) {
_builders = [NSMutableArray new];
}
return self;
}
+ (instancetype)shared {
static UIDTreeObserverFactory* factory = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
factory = [UIDTreeObserverFactory new];
[factory registerBuilder:[UIDUIApplicationObserverBuilder new]];
});
return factory;
}
- (void)registerBuilder:(id<UIDTreeObserverBuilder>)builder {
[_builders addObject:builder];
}
- (UIDTreeObserver*)createObserverForNode:(id)node
withContext:(UIDContext*)context {
for (id<UIDTreeObserverBuilder> builder in _builders) {
if ([builder canBuildFor:node]) {
return [builder buildWithContext:context];
}
}
return nil;
}
- (BOOL)hasObserverForNode:(id)node {
for (id<UIDTreeObserverBuilder> builder in _builders) {
if ([builder canBuildFor:node]) {
return true;
}
}
return false;
}
@end
#endif