All Projects → ridi → RxBus-Swift

ridi / RxBus-Swift

Licence: MIT license
Event bus framework supports sticky events and subscribers priority based on RxSwift

Programming Languages

swift
15916 projects

Labels

Projects that are alternatives of or similar to RxBus-Swift

HikingClub iOS
매시업산악회11기 iOS팀 열정! 열정! 열정!🔥🔥
Stars: ✭ 12 (-62.5%)
Mutual labels:  rxswift
RxCleanSwift
Example repository of Clean Swift built on ReactiveX
Stars: ✭ 42 (+31.25%)
Mutual labels:  rxswift
RxReusable
Reusable cells and views for RxSwift
Stars: ✭ 23 (-28.12%)
Mutual labels:  rxswift
ReactiveAPI
Write clean, concise and declarative network code relying on URLSession, with the power of RxSwift. Inspired by Retrofit.
Stars: ✭ 79 (+146.88%)
Mutual labels:  rxswift
RxStudy
RxSwift/RxCocoa框架,MVVM模式编写wanandroid客户端
Stars: ✭ 122 (+281.25%)
Mutual labels:  rxswift
WhatFilm
Simple iOS app using TMDb API and RxSwift
Stars: ✭ 35 (+9.38%)
Mutual labels:  rxswift
KDInstagram
Instagram Clone built in Swift. Utilize three design patterns in three major modules.
Stars: ✭ 119 (+271.88%)
Mutual labels:  rxswift
RxDisplayLink
RxDisplayLink reactive wrapper for CADisplayLink
Stars: ✭ 25 (-21.87%)
Mutual labels:  rxswift
RxApolloClient
RxSwift extensions for Apollo Client
Stars: ✭ 46 (+43.75%)
Mutual labels:  rxswift
aboon-ios
aboonは二人から始まるiOSクーポンアプリです。
Stars: ✭ 15 (-53.12%)
Mutual labels:  rxswift
awesome-demo-app
100% programmatically written in Swift. Clearly demonstrating the RxSwift, RxCocoa, RxRealm & SnapKit.
Stars: ✭ 16 (-50%)
Mutual labels:  rxswift
onlyRxSwift
RxSwift範例跟一些學習心得
Stars: ✭ 28 (-12.5%)
Mutual labels:  rxswift
CLE-Architecture-Tools
A library for making view controller presentation and dismissal more functional.
Stars: ✭ 32 (+0%)
Mutual labels:  rxswift
swift-tensorflow
Dockerized Swift for TensorFlow and advanced usage examples.
Stars: ✭ 14 (-56.25%)
Mutual labels:  rxswift
RxCocoa-Texture
RxCocoa Extension Library for Texture.
Stars: ✭ 98 (+206.25%)
Mutual labels:  rxswift
RxSwift-Xcode-Templates
A handful of Xcode file templates for projects that use RXSwift and MVVM
Stars: ✭ 77 (+140.63%)
Mutual labels:  rxswift
Moya-Gloss
Gloss bindings for Moya
Stars: ✭ 37 (+15.63%)
Mutual labels:  rxswift
LXFProtocolTool
由Swift中协议方式实现功能的实用工具库【Refreshable、EmptyDataSetable 支持 Rx 】
Stars: ✭ 101 (+215.63%)
Mutual labels:  rxswift
RxMVC-Swift
Unidirectional MVC with ReactiveX
Stars: ✭ 87 (+171.88%)
Mutual labels:  rxswift
RxAudioVisual
A reactive wrapper built around AVFoundation.
Stars: ✭ 24 (-25%)
Mutual labels:  rxswift

RxBus

Event bus framework supports sticky events and subscribers priority based on RxSwift.

Requirements

  • Xcode 10.2+
  • Swift 5.0+
  • iOS 9.0+
  • macOS 10.10+
  • tvOS 9.0+

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/ridi/RxBus-swift.git", .upToNextMinor(from: "0.1.0"))
]

Usage

Imports

import RxBus
import RxSwift

Defining Events struct

// Defining Events struct
struct Events {
    struct LoggedIn: BusEvent {
        let userId: String
    }
    struct LoggedOut: BusEvent { }
    struct Purchased: BusEvent {
        let tid: Int
    }
}

Event subscription/posting

RxBus.shared.asObservable(event: Events.LoggedIn.self).subscribe { event in
    print("LoggedIn, userId = \(event.element!.userId)")
}.disposed(by: disposeBag)
RxBus.shared.post(event: Events.LoggedIn(userId: "davin.ahn"))
LoggedIn, userId = davin.ahn

Sticky events

RxBus.shared.post(event: Events.LoggedOut(), sticky: true)
RxBus.shared.asObservable(event: Events.LoggedOut.self, sticky: true).subscribe { _ in
    print("LoggedOut")
}.disposed(by: disposeBag)
LoggedOut

Subscription priority

RxBus.shared.asObservable(event: Events.Purchased.self, sticky: false, priority: -1).subscribe { event in
    print("Purchased(priority: -1), tid = \(event.element!.tid)")
}.disposed(by: disposeBag)
RxBus.shared.asObservable(event: Events.Purchased.self, sticky: false, priority: 1).subscribe { event in
    print("Purchased(priority: 1), tid = \(event.element!.tid)")
}.disposed(by: disposeBag)
RxBus.shared.asObservable(event: Events.Purchased.self).subscribe { event in
    print("Purchased(priority: 0 = default), tid = \(event.element!.tid)")
}.disposed(by: disposeBag)
RxBus.shared.post(event: Events.Purchased(tid: 1001))
Purchased(priority: 1), tid = 1001
Purchased(priority: 0 = default), tid = 1001
Purchased(priority: -1), tid = 1001

System Notification subscription

RxBus.shared.asObservable(notificationName: UIResponder.keyboardWillShowNotification).subscribe { event in
    print("\(event.element!.name.rawValue), userInfo: \(event.element!.userInfo)")
}.disposed(by: disposeBag)
textField.becomeFirstResponder()
UIKeyboardWillShowNotification, userInfo: [AnyHashable("UIKeyboardAnimationCurveUserInfoKey"): 7, AnyHashable("UIKeyboardCenterEndUserInfoKey"): NSPoint: {207, 745.5}, AnyHashable("UIKeyboardFrameBeginUserInfoKey"): NSRect: {{0, 896}, {414, 54}}, AnyHashable("UIKeyboardFrameEndUserInfoKey"): NSRect: {{0, 595}, {414, 301}}, AnyHashable("UIKeyboardBoundsUserInfoKey"): NSRect: {{0, 0}, {414, 301}}, AnyHashable("UIKeyboardIsLocalUserInfoKey"): 1, AnyHashable("UIKeyboardAnimationDurationUserInfoKey"): 0.25, AnyHashable("UIKeyboardCenterBeginUserInfoKey"): NSPoint: {207, 923}]

Defining Custom Notification

extension Notification.Name {
    static let Custom = Notification.Name("CustomNotification")
}

Custom Notification subscription/posting

RxBus.shared.asObservable(notificationName: .Custom).subscribe { event in
    print("\(event.element!.name.rawValue), userInfo: \(event.element!.userInfo)")
}.disposed(by: disposeBag)
RxBus.shared.post(notificationName: .Custom, userInfo: ["message": "Hi~"])
Custom, userInfo: [AnyHashable("message"): "Hi~"]

Sticky Notifications

RxBus.shared.post(notificationName: .Custom, userInfo: ["value": 5], sticky: true)
RxBus.shared.asObservable(notificationName: .Custom, sticky: true).subscribe { event in
    print("\(event.element!.name.rawValue), userInfo: \(event.element!.userInfo)")
}.disposed(by: disposeBag)
Custom, userInfo: [AnyHashable("value"): 5]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].