Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elfenlaid/swirl
Events library inspired by reactive approach
https://github.com/elfenlaid/swirl
Last synced: 5 days ago
JSON representation
Events library inspired by reactive approach
- Host: GitHub
- URL: https://github.com/elfenlaid/swirl
- Owner: elfenlaid
- License: bsd-3-clause
- Created: 2015-03-30T19:50:05.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-04-05T10:39:40.000Z (over 9 years ago)
- Last Synced: 2023-04-22T16:15:57.042Z (over 1 year ago)
- Language: Objective-C
- Size: 184 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/elfenlaid/swirl.svg?branch=master)](https://travis-ci.org/elfenlaid/swirl)
# swirl
Tiny library inspired by reactive approachYou shouldn't use it yet though :(
## What this is all about
Library consists of two interfaces:`Rill` is some sort of events emitter. You create `Rill` like so:
```obj-c
SWLRill *rill = [[SWLRill alloc] initWithBlock:^id {
return @"value";
}];
````Rill`'s block return value is accessible via `value` property. Block executes in thread safe manner. Block can be nil.
With `Rill` you subscribe to object KVO:```obj-c
KVOObject *object = [KVOObject new];
[rill addDependencyWithObject:object keyPath:@"number"];// Trigger rill notification
object.number = @0;
````Rill` retains observable object. `Rill` could have more than one dependency.
Whenever dependency triggers, `Rill` would emit KVO notification, but actual `value` wouldn't be calculated till actual property access.
`Rill` events can also be triggered manually.
And one more thing, `Rill` block in ideal shouldn't have side effects, just grab, transform and return value.
On the other hand there's `Sink`. Basically `Sink` transforms events to side effects. You create `Sink` like this:
```obj-c
SWLSink *sink = [[SWLSink alloc] initWithBlock:^{
data = dataRill.value;
...
[collectionView reloadData];
}];
````Sink`'s block executes in thread safe manner.
`Sink` can depend only on `Rill` objects:
```obj-c
[sink addRillDependency:rill];
```On each dependency notification, `Sink` would execute its block. `Sink` could have more than one dependency.
====
In order to understand how to use `Rill` and `Sink` you may scroll through examples.