feat:iOS load Resource use NSDictionary

This commit is contained in:
pengfei.zhou
2021-11-18 19:08:33 +08:00
committed by osborn
parent e270b9c520
commit 7978900a4f
3 changed files with 13 additions and 19 deletions

View File

@@ -25,8 +25,6 @@
- (void)unRegisterLoader:(id <DoricResourceLoader>)loader;
- (__kindof DoricResource *)load:(NSString *)resId
withIdentifier:(NSString *)identifier
withResourceType:(NSString *)resourceType
- (__kindof DoricResource *)load:(NSDictionary *)resource
withContext:(DoricContext *)context;
@end

View File

@@ -49,20 +49,21 @@ - (void)unRegisterLoader:(id <DoricResourceLoader>)loader {
});
}
- (__kindof DoricResource *)load:(NSString *)resId
withIdentifier:(NSString *)identifier
withResourceType:(NSString *)resourceType
- (__kindof DoricResource *)load:(NSDictionary *)resource
withContext:(DoricContext *)context {
__block __kindof DoricResource *resource;
NSString *type = resource[@"type"];
NSString *identifier = resource[@"identifier"];
NSString *resId = resource[@"resId"];
__block __kindof DoricResource *doricResource;
dispatch_sync(self.mapQueue, ^() {
resource = [self.cachedResources objectForKey:resId];
if (!resource) {
id <DoricResourceLoader> loader = self.loaders[resourceType];
resource = [loader load:identifier withContext:context];
[self.cachedResources setObject:resource forKey:resId];
doricResource = [self.cachedResources objectForKey:resId];
if (!doricResource) {
id <DoricResourceLoader> loader = self.loaders[type];
doricResource = [loader load:identifier withContext:context];
[self.cachedResources setObject:doricResource forKey:resId];
}
});
return resource;
return doricResource;
}
@end