Contents

nalexn/minimalist

Building data-driven UI without `Rx`

Features

Access control

You can restrict the write access from outside of the module using just Swift's access control:

class ViewModel {
    @Property private(set) var value: String = "Minimalist"
    @Signal private(set) var signal: Accepts<Void>
}

// Cannot change property or trigger a signal:
viewModel.value = "abc" // ❌
viewModel.signal.send(()) // ❌

Automatic memory management

Subscription is bound to the lifetime of the supplied object and gets detached automatically. That object is also provided in the callback along with the value, so you don't need to do the [weak self] dance all the time:

class ViewController: UIViewController {
    var tableView: UITableView
    
    func viewDidLoad() {
        ...
        viewModel.$items.observe(with: self) { (vc, items) in
            vc.tableView.reloadData()
        }
    }
}

Filter state updates (Redux)

Data-driven UI works best with unidirectional data flow design, which may involve using a centralized state in the app.

Upon subscription, you can specify the KeyPath to the value inside the state container to receive scoped and filtered updates (like with distinctUntilChanged):

$appState.observe(\.screens.loginScreen, with: self) { (obj, state) in
    ...
}

Pro Tip: \.self is also a valid KeyPath. This way you can discard the same values while observing a primitive type.

Installation

@ Carthage

github "nalexn/minimalist"

@ CocoaPods

pod 'Minimalist'

@ SPM

.package(url: "https://github.com/nalexn/minimalist.git", from: "1.0.0")

[[blog]](https://nalexn.github.io/?utm_source=nalexn_github) [[venmo]](https://venmo.com/nallexn)

Package Metadata

Repository: nalexn/minimalist

Default branch: master

README: README.md