Giter Site home page Giter Site logo

leomobiledeveloper / qteventbus Goto Github PK

View Code? Open in Web Editor NEW
423.0 10.0 70.0 202 KB

iOS事件总线,支持AppDelegate解耦,支持基于响应链的局部总线

License: MIT License

Ruby 1.27% Objective-C 98.73%
ios objective-c eventbus module appdelegate notification

qteventbus's Introduction

QTEventBus

Build Status Version Platform License

QTEventBus是一个优雅的iOS事件总线,用来实现“发布-订阅”的消息通信模式。

  • 支持强类型/弱类型
  • 自动取消订阅
  • 快速
  • 兼容NSNotification
  • 单元测试覆盖
  • 支持AppDelegate解耦
  • 支持基于响应链的局部总线

文章:

安装

消息总线:

pod QTEventBus

AppDelegate解耦:

pod QTEventBus/AppModule

基于响应链的事件传递:

pod QTEventBus/UIKit

系统要求

  • XCode 9 +
  • iOS 8+

使用

新建一个类作为事件,实现协议QTEvent

@interface QTLoginEvent : NSObject<QTEvent>
@property (copy, nonatomic) NSString * userId; //可以携带任意数据
@property (copy, nonatomic) NSString * userName; //可以携带任意数据
@end

订阅这个事件

QTSub(object,className)宏的作用是在object的生命周期内,订阅className事件,当object释放的时候自动取消订阅。

//注意eventBus会持有这个block,需要弱引用object
[QTSub(self,QTLoginEvent) next:^(QTLoginEvent * event) {
    NSLog(@"%ld",event.userId);
}];

如果需要在主线程订阅,使用宏QTSubMain

发布事件

QTLoginEvent * event;
[QTEventBus.shared dispatch:event];

详细文档

许可证

QTEventBus使用 MIT 许可证,详情见 LICENSE 文件。

qteventbus's People

Contributors

leomobiledeveloper avatar zhwayne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qteventbus's Issues

多次触发事件

if (eventType && isCFNotifiction) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification:) name:eventType object:nil];
}

如果是同一个eventType 这里会进来多次 导致多次触发事件

问题

简单看了一眼代码,思路很好,代码也很牛逼,但是感觉没什么好的应用场景啊,那个APPDelegate解耦 感觉,变得更加复杂了,你觉得呢,不过你这个**很值得学习,还有代码写的很逼格,赞

移除子节点时候, 是否需要移除字典中的子节点?

- (void)removeNodeForId:(NSString *)uniqueId{
    //不存在
    if (![_registeredNodeTable objectForKey:uniqueId]) {
        return;
    }
    _QTEventBusLinkNode * node = [_registeredNodeTable objectForKey:uniqueId];
    if (node == _head) {
        _head = _head.next;
    }
    if (node == _tail) {
        _tail = _tail.previous;
    }
    _QTEventBusLinkNode * previousNode = node.previous;
    _QTEventBusLinkNode * nextNode = node.next;
    node.next = nil;
    node.previous = nil;
    previousNode.next = nextNode;
    nextNode.previous = previousNode;
}

将 node移除时候, 是否需要 [_registeredNodeTable removeObjectForKey:uniqueId]; 操作....

问个问题

我发现 pod QTEventBus 那么uikit的部分没有?应该怎么pod呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.