All Projects → yankodimitrov → Signalkit

yankodimitrov / Signalkit

Licence: mit
SignalKit is a reactive Swift framework with focus on clean and readable API.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Signalkit

SwiftObserver
Elegant Reactive Primitives for Clean Swift Architecture #NoRx
Stars: ✭ 14 (-94.29%)
Mutual labels:  reactive, observer
minimalist
Observable Property and Signal for building data-driven UI without Rx
Stars: ✭ 88 (-64.08%)
Mutual labels:  observer, signal
Rxswift
Reactive Programming in Swift
Stars: ✭ 21,163 (+8537.96%)
Mutual labels:  reactive, observer
deep-state-observer
State library for high performance applications.
Stars: ✭ 25 (-89.8%)
Mutual labels:  reactive, observer
react-mobx-router5
React components for routing solution using router5 and mobx
Stars: ✭ 58 (-76.33%)
Mutual labels:  reactive, observer
Observable
The easiest way to observe values in Swift.
Stars: ✭ 346 (+41.22%)
Mutual labels:  reactive, observer
Siesta
The civilized way to write REST API clients for iOS / macOS
Stars: ✭ 2,142 (+774.29%)
Mutual labels:  reactive, observer
Hyperactiv
A super tiny reactive library. ⚡️
Stars: ✭ 208 (-15.1%)
Mutual labels:  reactive
Rxterm
Functional reactive terminals in C++ ⚡⌨️
Stars: ✭ 226 (-7.76%)
Mutual labels:  reactive
Pos
Sample Application DDD, Reactive Microservices, CQRS Event Sourcing Powered by DERMAYON LIBRARY
Stars: ✭ 207 (-15.51%)
Mutual labels:  reactive
Barrel Platform
Distributed database for the modern world
Stars: ✭ 201 (-17.96%)
Mutual labels:  reactive
Helidon
Java libraries for writing microservices
Stars: ✭ 2,554 (+942.45%)
Mutual labels:  reactive
Django Sockpuppet
Build reactive applications with the django tooling you already know and love.
Stars: ✭ 225 (-8.16%)
Mutual labels:  reactive
Recaptcha
[In]visible ReCaptcha v2 for iOS
Stars: ✭ 208 (-15.1%)
Mutual labels:  reactive
Pluto.jl
🎈 Simple reactive notebooks for Julia
Stars: ✭ 3,430 (+1300%)
Mutual labels:  reactive
Store
A beautifully-simple framework-agnostic modern state management library.
Stars: ✭ 204 (-16.73%)
Mutual labels:  reactive
Watermill
Building event-driven applications the easy way in Go.
Stars: ✭ 3,504 (+1330.2%)
Mutual labels:  reactive
Smallrye Mutiny
An Intuitive Event-Driven Reactive Programming Library for Java
Stars: ✭ 231 (-5.71%)
Mutual labels:  reactive
Vue.py
Pythonic Vue.js
Stars: ✭ 223 (-8.98%)
Mutual labels:  reactive
Human Signals
Human-friendly process signals
Stars: ✭ 223 (-8.98%)
Mutual labels:  signal
SignalKit

Carthage compatible

Abstract

SignalKit is a lightweight event and binding framework. The core of SignalKit is the Observable protocol. Each implementation of the Observable protocol defines the type of the observation thus an Observable can sendNext only one type of event. For example an Observable of type String can only sendNext String values.

Another key protocol is SignalType which implements Observable and Disposable. Each SignalType implementation has a property disposableSource: Disposable? which points to a Disposable that comes before the current signal.

Because SignalType implements Disposable we can use the disposableSource property to chain signal operations like map, filter and combineLatest together. Each operation returns either a new SignalType or a Disposable. When we call dispose() on a SignalType it will dispose the whole chain of operations.

To store the chain of operations we can use a stored property or the disposeWith(container: DisposableBag) -> Disposable method on the Disposable protocol. When DisposableBag is deinitialized it will dispose all of its items for us.

let disposableBag = DisposableBag()
let userName = Signal<String>()

userName.next { print("name: \($0)") }
	.disposeWith(disposableBag)

userName.sendNext("John") // prints "name: John"

SignalKit Primary Protocols

Events And Bindings

SignalKit comes with an elegant way to observe for different event sources like KVO, Target Action and NSNotificationCenter via an unified API by simply calling observe() method. The observe method is a protocol extension on the NSObjectProtocol which returns a SignalEvent with sender Self. Then we use Protocol Oriented Programming to add extensions to a SignalEventType protocol where Sender is from a given type.

SignalKit Primary Protocols

Key Value Observing

Let's say we want to observe an instance of class Person: NSObject for it's name property changes with KVO. This is super easy with SignalKit, just call observe() on the instance and it will return the available events for this type. Then choose keyPath(path: String, value: T) where for the value parameter pass the initial value of the property. SignalKit will use this initial value type to perform an optional type cast on the values sent by KVO.

let person = Person(name: "John")

person.observe()
    .keyPath("name", value: person.name)
    .next { print("Hello \($0)") }
    .disposeWith(disposableBag)

Target Action

SignalKit comes with SignalEventType extensions for controls which inherits from UIControl and UIBarButtonItem:

let control = UIControl()
let barButton = UIBarButtonItem()

control.observe().events([.TouchUpInside])
    .next { _ in print("Tap!") }
    .disposeWith(disposableBag)
        
barButton.observe().tapEvent
    .next { _ in print("Tap!") }
    .disposeWith(disposableBag)

NSNotificationCenter

SignalEventType also have a handy extensions for observing an instance of NSNotificationCenter for notifications:

let center = NSNotificationCenter.defaultCenter()

center.observe().notification(UIApplicationWillResignActiveNotification)
    .next{ _ in print("Resign Active") }
    .disposeWith(disposableBag)

Bindings

Bindings in SignalKit are implemented again with protocol extensions. We extend the SignalType where the ObservationType (from the generic Observable protocol) is from a certain type and add method to bind the value to a UI control like UILabel. Here is an example of binding the String value from the signal to the text property of UILabel:

let userName = Signal<String>()
let nameLabel = UILabel()

userName.bindTo(textIn: nameLabel)
    .disposeWith(disposableBag)

Signals

Signal

Signal is the primary object which you can use to send events and it is thread safe.

SignalValue

SignalValue is a signal that stores its last sent/current value. If we add a new observer to it it will send immediately its value to the newly added observer. If we change the value of the signal it will notify its observers for the change. SignalValue is also thread safe.

let name = SignalValue(value: "John")

name.next { print($0) }.disposeWith(bag) // prints "John"

name.value = "Jonathan" // prints "Jonathan"

CollectionEvent

We can use a signal of type Signal<CollectionEvent> to send the changes that occur in our data source. Then we can bind the signal to UITableView or UICollectionView and the changes that we send will be reflected in the table/collection view:

// UsersListViewController
...
viewModel.usersChangeSignal.bindTo(tableView, rowAnimation: .Fade).disposeWith(bag)

// UsersListViewModel
let usersChangeSignal = Signal<CollectionEvent>()
var users = [User]()
...

var event = CollectionEvent()

users.insert(User(name: "John"), atIndex: 0)
event.itemInsertedAt(0, inSection: 0)

usersChangeSignal.sendNext(event)

Operations

SignalKit comes with the following SignalType operations: SignalKit Primary Protocols

Extensions

Currently SignalKit comes with extensions for the the following UIKit components: SignalKit Primary Protocols

Keyboard

You can use the Keyboard structure to observe for keyboard events posted by the system. Then you will get back a structure of type KeyboardState which you can query for the keyboard end/start frame and other data that the system sends with the notification:

Keyboard.observe().willShow
    .next { print($0.endFrame) }
    .disposeWith(disposableBag)

Installation

SignalKit requires Swift 2.0 and Xcode 7

Carthage

Add the following line to your Cartfile

github "yankodimitrov/SignalKit" "master"

CocoaPods

Add the following line to your Podfile

pod SignalKit

##License SignalKit is released under the MIT license. See the LICENSE.txt file for more info.

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].