Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/psharanda/jetpack
Light and bright functional reactive framework
https://github.com/psharanda/jetpack
functional ios observable observer reactive rx swift unidirectional
Last synced: 3 months ago
JSON representation
Light and bright functional reactive framework
- Host: GitHub
- URL: https://github.com/psharanda/jetpack
- Owner: psharanda
- License: mit
- Created: 2017-04-09T20:54:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-04-23T13:51:08.000Z (over 4 years ago)
- Last Synced: 2024-03-14T19:53:39.668Z (10 months ago)
- Topics: functional, ios, observable, observer, reactive, rx, swift, unidirectional
- Language: Swift
- Homepage:
- Size: 342 KB
- Stars: 16
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jetpack
Jetpack is a lightweight reactive programming library for Swift. It provides tools for creating and composing asynchronous and event-based programs using observable sequences.
## Features
- Observable sequences
- Mutable and immutable property wrappers
- Combining and transforming observables
- Threading and concurrency utilities
- Array and 2D array reactive wrappers
- Reactive subjects for broadcasting values## Usage
```swift
import Jetpack// Create an observable sequence
let observable = Observable.just(5)// Subscribe to receive values
observable.subscribe { value in
print(value) // Prints: 5
}// Create a mutable property
let property = MutableProperty(10)// Observe property changes
property.subscribe { value in
print(value)
}property.update(20) // Triggers subscription, prints: 20
// Combine observables
let combined = observable.combineLatest(property.asObservable)
combined.subscribe { (a, b) in
print("Combined: \(a), \(b)")
}// Transform observables
let mapped = observable.map { $0 * 2 }
mapped.subscribe { value in
print(value) // Prints: 10
}
```## Main Components
- `Observable`: Represents a sequence of values over time
- `Property`: Immutable wrapper around a value with reactive capabilities
- `MutableProperty`: Mutable version of Property
- `Subject`: Allows broadcasting values to multiple observers## Threading
Jetpack provides utilities for managing concurrency:
```swift
observable.dispatch(on: .main) // Observe on main thread
observable.delay(timeInterval: 1.0, on: .global()) // Delay events
```## Installation
### Swift Package Manager
Add the following to your `Package.swift` file:
```swift
dependencies: [
.package(url: "https://github.com/username/Jetpack.git", from: "1.0.0")
]
```## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
Jetpack is released under the MIT License. See LICENSE for details.