zepo / reflow Goto Github PK
View Code? Open in Web Editor NEWA unidirectional data flow framework for Objective-C inspired by Flux, Redux and Vue.
License: MIT License
A unidirectional data flow framework for Objective-C inspired by Flux, Redux and Vue.
License: MIT License
Hello, Can I ask you why choose AssociatedObject instead of singleton NSMutableSet in RFAspects.m? Is it for the memory optimization? Thank you
static Class aspect_swizzleClassInPlace(Class klass) {
NSCParameterAssert(klass);
// NSString *className = NSStringFromClass(klass);
//
// _aspect_modifySwizzledClasses(^(NSMutableSet *swizzledClasses) {
// if (![swizzledClasses containsObject:className]) {
// aspect_swizzleForwardInvocation(klass);
// [swizzledClasses addObject:className];
// }
// });
NSNumber *hasBeenHooked = objc_getAssociatedObject(klass, kClassHasBeenHookedKey);
if (!hasBeenHooked.boolValue) {
aspect_swizzleForwardInvocation(klass);
objc_setAssociatedObject(klass, kClassHasBeenHookedKey, @YES, OBJC_ASSOCIATION_RETAIN);
}
return klass;
}
- (void)unsubscribe {
id object = self.object;
if (object) {
@synchronized(object) {
NSPointerArray *listeners = objc_getAssociatedObject(object, kListernersKey);
NSInteger index = 0;
for (RFSubscription *subscription in listeners) {
if (subscription == self) {
break;
}
++index;
}
[listeners removePointerAtIndex:index];
}
}
}
@end
这里这样写好像多次调用改方法会闪退
做了以下修改 希望作者review下
- (void)unsubscribe {
id object = self.object;
if (object) {
@synchronized(object) {
NSPointerArray *listeners = objc_getAssociatedObject(object, kListernersKey);
NSInteger index = -1;
for (int i = 0; i < listeners.count; i++) {
RFSubscription *subscription = [listeners pointerAtIndex:i];
if (subscription == self) {
index = i;
break;
}
}
if (index == -1) {
return;
}
[listeners removePointerAtIndex:index];
}
}
}
[self.todoStore subscribe:^(RFAction *action) {
if (action.selector == @selector(actionSetVisibilityFilter:)) {
self.filterButton.title = [self stringFromVisibilityFilter:[self.todoStore visibilityFilter]];
}
self.todos = [self.todoStore visibleTodos];
[self.tableView reloadData];
}];
I'm very confused about without the subscription
property, why the block can not called.
RT
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.