Reactivecocoa
Reactivecocoa is a function-responsive programming (FRP) framework.
1. Function-type programming: write the operation as much as possible into a series of nested functions or method calls.
2, responsive programming: Do not need to consider the sequence of calls, just need to know the results, similar to the butterfly effect, the occurrence of an event, will affect a lot of things, these events like the flow of the spread out, and then affect the results.
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------
(i) Reactivecocoa Core class racsignal
Racsignal Steps to use:
//1. Create Signal + (racsignal *) createsignal: (racdisposable * (^) (id<racsubscriber> subscriber)) Didsubscribe
//2. The signal is only activated if the signal is subscribed.-(Racdisposable *) Subscribenext: (void (^) (id x)) nextblock
//3. Send signal-(void) Sendnext: (ID) value
//Racsignal Bottom implementation:
//1. To create a signal, first save the didsubscribe to the signal, it will not be triggered.
//2. When the signal is subscribed, that is to call Signal's Subscribenext:nextblock
The subscriber Subscriber is created inside the//2.2 subscribenext, and Nextblock is saved to subscriber.
//2.1 Subscribenext internally calls SIGANL's Didsubscribe
//3.SIGANL in Didsubscribe [subscriber sendnext:@1];
//3.1 sendnext The bottom is actually the implementation of subscriber Nextblock
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------
code example:
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------
//1. Create a signal
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------
Racsignal *siganl = [racsignal createsignal:^racdisposable * (ID<RACSubscriber> subscriber) {
//Block call time: block is called whenever a subscriber subscribes to a signal.
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------
//2. Send Signal
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------
[Subscriber sendnext:@1];
//If the data is not sent, it is best to send the signal to complete, the internal will automatically call [racdisposable disposable] unsubscribe signal.
[Subscriber sendcompleted];
return [racdisposable disposablewithblock:^{
//Block call time: When the signal is sent or the error is sent, the block is automatically executed and the subscription signal is canceled.
//after the block is executed, the current signal is not subscribed.
NSLog(@ "signal is destroyed");
}];
}];
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------
//3. The signal is not activated until the signal is subscribed.
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------
[Siganl subscribenext:^ (ID x) {
//Block call time: block is called whenever a signal is emitted.
NSLog(@ "received data:%@", x);
}];
REACTIVECOCOA Programming Framework Learning (I.)