Scala ObservableSet Trait 的使用示例
谁能帮我告诉我如何使用scala的ObservableSet特征?
预先非常感谢
Could anyone help me telling me how to use scala's ObservableSet trait?
Thank you very much in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ObservableSet 是一个从Publisher 特征,给出一些基本的发布订阅行为。使用此功能的一个简单示例是:
参阅以下示例(类 S 定义如上):
ObservableSet 执行类似的操作,当使用 += 或 +- 方法添加或删除元素时,它会调用publish 方法,请 通过用 Any 类型定义 S 来变得很懒,但我无法立即正确输入,并且没有花太长时间试图弄清楚它。
ObservableSet is a trait extending from the Publisher trait, giving some basic publish subscribe behaviour. A simple example of using this would be:
ObservableSet does something similar, it calls the publish method when elements are added or removed with the += or +- method, see the following example (with class S defined as above):
I've beem lazy by defining S with types Any, but I couldn't get the typing right immediately, and haven't spend too long trying to figure it out.
所有的输入信息有点碍眼,但这就是我让它工作的方式。我欢迎有关如何使打字更加简洁的建议。 包括类型别名的各种编辑:
打印:
有趣的是,撤消导致发布另一条消息...
It's a bit of an eyesore with all the typing information, but this is how I was able to get it to work. I welcome suggestions on how to make the typing more concise. various edits including type aliases:
That prints:
Interestingly, undo caused another message to be published...