我有聊天应用程序。我想为我的聊天构建消息管理器,如下图所示。 基本上我有ChatActivity来显示消息。理想情况下,我想按照此顺序向MessageManager提供来自MessageManager的消息。
我知道RxJava对这种类型的结构有好处,但我不知道如何构建它。
答案 0 :(得分:3)
Generally, such app can get quite complicated but here is a simple demonstration how the stream could be assembled:
import unittest
def decorating_meta(decorator):
class DecoratingMetaclass(type):
def __new__(self, class_name, bases, namespace):
for key, value in list(namespace.items()):
if callable(value):
namespace[key] = decorator(value)
return type.__new__(self, class_name, bases, namespace)
return DecoratingMetaclass
def skipUnlessHasattr(obj):
if hasattr(obj, 'StepDebug'):
return lambda func : func
return unittest.skip("{!r} doesn't have {!r}".format(obj, 'StepDebug'))
class Foo(unittest.TestCase):
__metaclass__ = decorating_meta(skipUnlessHasattr)
def test_Sth(self):
self.assertTrue(False)
if __name__ == '__main__':
unittest.main()