何时应该在Play框架中返回一个Promise而不是实际的结果?(When should a method return a Promise instead of actual result in Play Framework?)
我对Play Framework相对较新。 我正在开发的当前项目中,有大量
Promise
由服务层组件返回到控制器。 我想知道这是否是最佳做法。 在我看来,使用Promise
真的会让消息来源混乱。 而且我必须频繁地使用final修饰符,以使局部变量,参数和类成员可以访问匿名Function
我需要为这些Promise
创建Function
。 它甚至会影响我创建单元测试用例的方式。 它感到丑陋诚实,并有太多的代码行数超过必要的。 我甚至不确定我们是否做得对,我觉得我们正在过度使用Promise
。顺便说一句,我正在使用Java。
那么,我应该什么时候使用
Promise
,何时应该返回Promise
,何时不应该使用Promise
? 我们所有的服务和接口都应该返回一个Promise
吗? 有没有更好的方法来做到这一点? 请用简单的英语。I'm relatively new to Play Framework. The current project I'm working on has tons of
Promise
s returned by the service layer components all the way down to controllers. I wonder if that's the best practice. In my opinion, usingPromise
s really clutters up the sources. And I have to make use of final modifiers too frequently just to make local variables, parameters, and class members accessible to anonymousFunction
I need to create for thesePromise
s. It even affects the way I create my unit test cases. It feels ugly honestly and there's simply too much lines of code than necessary. I'm not even sure if we're doing it right, I feel like we're overusingPromise
s.I'm using Java by the way.
So, when should I use a
Promise
, when should I return aPromise
, and when should I not use aPromise
? Should all our services and interfaces return aPromise
? Is there any better way of doing this? In plain English please.
原文:https://stackoverflow.com/questions/23465951
最满意答案
应用程序切片目前无法正常工作,直至另行通知。 目前,减少应用规模的唯一方法是减少.ipa中包含的资产数量。
如果它们对您的应用有意义,您可以尝试使用On Demand Resources 。
Searching app thining, bit code and on demand app resource from yesterday, Now I debug all these things and sharing my knowledge that I got from beautiful apple documentation with help of my sample project.
App thinning concept covers bit code and on-demand resource. I will discuss on-demand resource in detail below:-
On-Demand Resources in iOS:- It is accessing the images/videos/.h/.m/swift file whenever needed (
Yes, on-demand resouring include source code files also
).
- Goto
Resource tags
setting in your target.- Create a new
Tag
. It will appear under Download Only On demand.- You can add .h, .m, .xassest, .png etc under various tags. You can also assign tag by selecting individual file like this in file inspector.
Now comes the coding part (my favourite site):-
NSBundleResourceRequest *resourceRequest; #pragma mark - On demand resource -(void)getOnDemandResource{ NSSet *setOfTag = [NSSet setWithObjects:@"chair", nil]; resourceRequest = [[NSBundleResourceRequest alloc]initWithTags:setOfTag]; [resourceRequest conditionallyBeginAccessingResourcesWithCompletionHandler:^(BOOL resourcesAvailable) { if (!resourcesAvailable) { // resourceRequest.loadingPriority = 1;//set the downloading priority (0 - 1) , NSBundleResourceRequestLoadingPriorityUrgent [resourceRequest beginAccessingResourcesWithCompletionHandler:^(NSError * _Nullable error) { if (error) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:error.debugDescription preferredStyle:UIAlertControllerStyleAlert]; [self presentViewController:alert animated:YES completion:nil]; }else{ //// The associated resources are loaded } }]; }else{ // The associated resources are available } }]; }
End accessing the on demand resource when not in use(generally when game level changes)
#pragma mark - Remove access to on demand -(void)endAccessToOnDemandResource{ [resourceRequest endAccessingResources]; }
NOTE:-
Don't forgot to enable On_Demand_Resources in build setting.EXAMPLE PROJECT:- I create a sample project and uploaded here:- [http://www.dropbox.com/s/edi5zj68a4wuguh/WebOnTab.zip?dl=0][6]
Please don't bother about autolayout in this project. My main focus is on demand resourcing/App thing.
SUMMARY:- Thus we can achieve
app thinning
byon-demand resourcing
using above technique. Please also have a look at official documentation which also describes abouttracking progress
,priorities
of resourceRequests(NSBundleResourceRequest
).
相关问答
更多-
观看http://vimeo.com/3616452 Watch http://vimeo.com/3616452
-
应用程序切片目前无法正常工作,直至另行通知。 目前,减少应用规模的唯一方法是减少.ipa中包含的资产数量。 如果它们对您的应用有意义,您可以尝试使用On Demand Resources 。 Searching app thining, bit code and on demand app resource from yesterday, Now I debug all these things and sharing my knowledge that I got from beautiful apple ...
-
您无需连续检查连接。 您必须在启动需要有效连接的操作之前进行检查。 因此,您不会检入viewDidLoad或其他类。 如果是这种情况,您负责向用户报告连接不可用。 在开始需要连接到Internet的操作之前,请进行检查。 如果连接不可用,请立即通知用户。 在执行检查时可能会发生连接,但在操作期间稍后变得不可用。 你必须小心,在你的代码中包含一个检查。 当您丢失连接时,您需要再次通知用户。 You do not need to check continually the connection. You mus ...
-
iOS9:在iOS9之前,App Thinning是否适用于旧版iOS?(iOS9: Will App Thinning work on older iOS version before iOS9?)[2022-05-17]
根据App thinning Docs : 注意:对于iOS应用程序,最新的iTunes和运行iOS 9.0及更高版本的设备支持切片应用程序; 否则,App Store会向客户提供通用应用程序。 因此,安装了iOS 7和iOS 8的设备将获得通用版本。 According to App thinning Docs: Note: For iOS apps, sliced apps are supported on the latest iTunes and on devices running iOS 9.0 ... -
无论您是否需要保密,您都必须加密并混淆它,以保护自己免受偶然黑客的侵害。 另一方面,我不相信你可以阻止一个坚定的黑客。 越狱,gdb和流量嗅探器的组合将会打败几乎所有你能想到的保护。 大量投资于此类保护措施很少有意义,因此您必须在浪费大量时间和精力并让您的API密钥破解之间找到妥协方案。 就我个人而言,我喜欢在应用程序二进制文件中使用模糊处理API密钥的想法,因为您从App Store获得的二进制文件是加密的。 有PT_DENY_ATTACH的ptrace()小问题可能会使复杂(但绝不会完全阻止)通过gdb ...
-
我记得有关BuddyPress的一个插件,名为BPDEV XMLRPC,允许您通过XMLRPC与BuddyPress进行通信。 我不知道它是否还没有开发出来,但似乎可以使用它从iPhone应用程序发布消息给BuddyPress。 bp-dev.org目前似乎处于下降状态,但我在那里读到了它。 I remember reading about a plugin for BuddyPress, called BPDEV XMLRPC that allows you to communicate with Bud ...
-
按需资源应用程序细化(On Demand Resource App Thinning)[2024-04-11]
您应该检查用户的当前语言: NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0]; 然后选择要下载的标签:(现在默认为英文) NSString *tagString = @"english"; if( [language isEqualToString:@"fr"] ){ tagString = @"france"; } else if( [language isEqualToString:@"it"] ){ ... -
没有@ 3x图像的应用程序稀疏,当某些图像是JPG时(App thinning without @3x images and when some images are JPGs)[2024-02-15]
回答你自己的问题。 归档应用程序。 导出您感兴趣的目标设备的应用程序: 现在查看导出的应用程序内部并查看它包含的资源。 .ipa只是一个.zip文件的另一个名字; 通过更改后缀可以很容易地查看它。 现在您知道iPhone 6 Plus用户将从App Store下载哪些资源。 I performed several additional tests using the procedure proposed by Matt: When minimum deployment target is iOS 6 no ... -
如果您仅为新的iPhone 6分辨率添加启动图像(没有新的启动故事板),您仍将获得“针对iPhone 6优化”。 我选择不在我的应用程序中使用启动故事板场景,因为我仍然支持iOS7,这需要启动图像并且不支持启动故事板(iOS 7将简单地忽略启动故事板)。 我的应用程序都说“此应用程序针对iPhone 5,iPhone 6和iPhone 6 Plus进行了优化。” 如果您决定要求iOS 8,则应考虑仅使用启动故事板并删除旧的启动图像。 然后,当新的分辨率设备出来时,您可能不需要更新。 If you add t ...
-
xcodebuild -exportArchive选项plist值用于细化(xcodebuild -exportArchive options plist values for thinning)[2022-08-01]
它绝对是<none> 在Xcode 7中,以下是所有选项的列表: {, , iPad3,1, iPad3,2, iPad3,3, iPad3,4, iPad3,5, iPad3,6, iPad2,3, iPad2,1, iPad2,4, iPad2,2, iPad4,1, iPad4,2, iPad4,3, iPad5,3, iPad5,4, iPad6,7, iPad6,8, iPad6,3, iPad ...