问题标签 [reactive-cocoa]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
212 浏览

ios - Refactoring ReactiveCocoa

I have the following code in a viewmodel:

It is basically binding properties onto a private property. Is this totally the wrong way of going about this or is there a tidier way of writing the above code?

0 投票
1 回答
877 浏览

objective-c - 观察 RACSequence 中的每一项

我在 ParentViewModel 上有一个方法,它返回 ViewModel 对象的 RACSequence,如下所示:

每个 ViewModel 都有一个 state 属性,该属性是一个枚举,并具有 3 个状态:NotStarted、InProgress 和 Completed。当我序列中的所有 ViewModel 都具有 Completed 状态时,我知道 ParentViewModel 是有效的。我在 ParentViewModel 上有一个 validSignal,我想从 viewModels 序列中得出有效的事实。目前我有这个代码:

如果序列中的所有 ViewModel 都有效,这给了我一个指标。然后我怎样才能把它变成一个 RACSignal,它会在每次 ViewModel 上的 state 属性发生变化时更新?

0 投票
1 回答
990 浏览

mvvm - 在视图模型上测试 RACCommand

我正在尝试测试在我的视图模型上执行的 RACCommand 的结果。

我像这样设置我的提交命令:

createSubmitCommand 在我初始化视图模型时被调用,validSignal 在测试上下文中是有效的。

我使用 MagicalRecord 进行核心数据持久性和 Kiwi 进行测试。我需要测试当我调用 [[viewModel submitCommand] execute: nil] 时我的模型正在保存。

我的测试看起来像这样:

问题是 save 是异步的并且不会阻塞,然后测试完成并拆除我的 NSManagedObjectContext 并且测试失败。我觉得我的测试完全错误,或者我正在滥用 RACCommand 但我不知道是哪个......

0 投票
3 回答
3722 浏览

ios - 如何从 ReactiveCocoa 信号中获取当前值?

我有返回 NSNumber 的信号:

然后在代码的某个地方,我想在执行时获取信号的值,例如:

0 投票
2 回答
2015 浏览

objective-c - 您将如何编写以“Reactive Cocoa”方式获取集合?

我正在构建的客户端正在使用带有Octokit的Reactive Cocoa ,到目前为止它进展顺利。但是现在我正处于想要获取存储库集合的地步,并且无法用“RAC方式”来解决这个问题

我最初假设它-subscribeNext:会传递一个NSArray,但现在明白它会发送消息每个返回的“下一个”对象,在这种情况下是一个OCTRepository.

现在我可以做这样的事情:

当然,这行得通,但它似乎没有遵循 RAC 启用的功能原则。我真的很想在这里遵守约定。非常感谢 RAC/Octokit 的任何功能!

0 投票
1 回答
1219 浏览

objective-c - Recursive -flattenMap: with Reactive Cocoa + OctoKit (fetching dynamic object graph from web service)

I'm trying to pre-fetch an object graph of files in a Github repository using Octokit which depends on Reactive Cococa. I'm running into an issue creating a signal that will drill down, recursively, until there are no more directories to be fetched. Here is an example directory graph of a repository of mine (note: files have been omitted to keep the graph simple and clean).

Directory graph of RNGridMenu

As a note: -fetchContents:forRepository: builds a request path and returns a RACSignal that enqueues an HTTP request operation (it tries to follow the semantics OctoKit does).

The problem I'm running into currently is that this setup only executes the fetch for the contents of the repository (i.e. the top-level object in the graph). -flattenMap: is called, the array of signals is appropriately created, and the -merge: is returned. The intention is to create a recursive chain that ends when there are no more directory type children (should probably add a -filter: to check for that).

The intension is to fetch the entire graph of files for a Github repository and be notified when the operation is finished. Here's an example of how I'd like to handle calling this:

Any idea why it only executes the top level? I would have thought that calling -subscribeNext: on -fetchContentTreeForRepository: would be what executes the returned signal for -flattenMap:, but it seems I'm misunderstanding something. This assumption comes from the chaining example in the Reactive Cocoa readme.

edit: I am dumb.

0 投票
2 回答
6918 浏览

ios - 带有 ReactiveCocoa 的 iOS 应用的 ViewModel 模式

我正在努力将 RAC 集成到我的项目中,目标是创建一个 ViewModel 层,该层将允许从网络轻松缓存/预取(以及 MVVM 的所有其他好处)。我对 MVVM 或 FRP 还不是特别熟悉,我正在尝试为 iOS 开发开发一个不错的、可重用的模式。我对此有几个问题。

首先,这是我将 ViewModel 添加到我的一个视图中的一种方式,只是为了尝试一下。(我希望这里稍后参考)。

在 ViewController viewDidLoad 中:

视图模型.h

视图模型.m

我使用信号的方式是否正确?具体来说,必须bioSignal更新数据以及hiddenBioSignal直接绑定到 textView 的隐藏属性是否有意义?

我的主要问题来自于将代表处理的问题转移到 ViewModel 中(希望如此)。代表在 iOS 世界中是如此普遍,以至于我想找出最好的,甚至只是一个适度可行的解决方案。

例如,对于 UITableView,我们需要同时提供委托和数据源。我应该在控制器上有一个属性NSUInteger numberOfRowsInTable并将其绑定到 ViewModel 上的信号吗?而且我真的不清楚如何使用 RAC 为我的 TableView 提供tableView: cellForRowAtIndexPath:. 我是否只需要以“传统”方式进行这些操作,还是可以为细胞提供某种信号提供者?或者最好让它保持原样,因为 ViewModel 不应该真正关心构建视图,而只是修改视图的源?

此外,有没有比我使用主题(fetchDoctorSubject)更好的方法?

任何其他评论也将不胜感激。这项工作的目标是制作一个预取/缓存 ViewModel 层,可以在需要在后台加载数据时发出信号,从而减少设备上的等待时间。如果由此产生任何可重用的东西(除了模式),它当然是开源的。

编辑:还有另一个问题:根据文档,我应该使用 ViewModel 中所有信号的属性而不是方法?我想我应该在init中配置它们?或者我应该保持原样以便吸气剂返回新信号?

我应该active在 ReactiveCocoa 的 github 帐户中拥有 ViewModel 示例中的属性吗?

0 投票
1 回答
2739 浏览

objective-c - RACSignal:如何减少任意大的组合

考虑ReactiveCocoa Introduction中的一个示例(转述),它根据.password.passwordConfirmtext 字段是否匹配来启用:

在这里,我们在编译时知道我们正在组合多少和什么东西,并且将“组合”数组解构/映射为 reduce 块的多个参数很有用。那什么时候行不通。例如,如果你想:

你如何用ReactiveCocoa做到这一点?

更新:接受的答案的评论有助于解释我所缺少的。

0 投票
2 回答
1346 浏览

ios - 如何将 RAC 库添加到 XCode?

我正在尝试将 Reactive Cocoa 库添加到我的 Xcode 项目中,但我不能。我正在尝试查找一些教程,因为我无法理解 Reactive Cocoa 页面中的那个。如何将这个库添加到我的项目中?

0 投票
1 回答
268 浏览

ios - 使用 ReactiveCocoa 的视图之间的通信?

我正在尝试了解 Reactive Cocoa 的工作原理......该框架之上没有太多文档或示例。我需要用它在不同的视图之间发送信号。In my view, I have a table and another viewcontroller, and I need, that when some cell is selected, send a signal to the other viewcontroller... How can I send signals between different views using Reactive Cocoa? 谢谢