Last active
December 15, 2015 07:49
-
-
Save joshaber/5226626 to your computer and use it in GitHub Desktop.
ReactivePersistence?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The basics | |
[[self.connection fetch:@"the-answer"] subscribeNext:^(NSNumber *x) { | |
NSLog(@"The answer is %@", x); | |
}]; | |
[[self.connection writeObject:@42 forKey:@"the-answer"] subscribeCompleted:^{ | |
NSLog(@"Wrote it."); | |
}]; | |
// Signal for changes to the object at a key | |
[[self.connection signalForKey:@"the-answer"] subscribeNext:^(NSNumber *x) { | |
NSLog(@"The answer changed to %@", x); | |
}]; | |
// Derived value | |
RACSignal *plusOne = [[self.connection | |
signalForKey:@"the-answer"] | |
map:^(NSNumber *answer) { | |
return @(answer.unsignedIntegerValue + 1); | |
}]; | |
[self.connection rac_liftSelector:@selector(writeObject:forKey:) withObjects:plusOne, @"the-answer-plus-1"]; | |
// Trimming | |
RACSignal *trimmed = [[[self.connection | |
signalForKey:@"some-array"] | |
filter:^ BOOL (NSArray *array) { | |
return array.count > 50; | |
}] | |
map:^(NSArray *array) { | |
return [array subarrayWithRange:NSMakeRange(array.count - 10, 10)]; | |
}]; | |
[self.connection rac_liftSelector:@selector(writeObject:forKey:) withObjects:trimmed, @"some-array"]; | |
// Validation | |
RACSignal *valid = [RACAble(self.someProperty) filter:^(id value) { | |
return ![value isNotCrazy]; | |
}] | |
[self.connection rac_liftSelector:@selector(writeObject:forKey:) withObjects:valid, @"some-stuff"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment