glow-inc / glpubsub Goto Github PK
View Code? Open in Web Editor NEWA wrapper of NSNotificationCenter to make pub sub easier
License: MIT License
A wrapper of NSNotificationCenter to make pub sub easier
License: MIT License
id observer = [[NSNotificationCenter defaultCenter] addObserverForName:eventName object:obj queue:_pubSubQueue usingBlock:^(NSNotification *note) {
GLEvent *event = [[GLEvent alloc] initWithName:eventName obj:note.object data:[note.userInfo objectForKey:kGLPubSubDataKey]];
handler(event);
}];
data 只存了 userInfo 里面 key 为 kGLPubSubDataKey
的值,这样会忽略掉一些系统 Notification 的 userInfo,是不是不合理?
在下面的方法中:
- (id)subscribe:(NSString *)eventName obj:(id)obj handler:(GLEventHandler)handler {
使用 NSMutableDictionary 存储了事件对应的 observers, 使用 nsset 存储了observer。
比较好奇的是为什么不直接用 NSMutableDictionary 而套了一层 set ?谢谢
团队里有很多人,总有某些原因,或者没注意到,或是忘记了,或者懒,在 block 里强引用了 self。
所以我修改了 GLEventHandler,在 block 也可以放心使用 self,不必写那些烦人的 weakSelf。
typedef void (^GLEventHandler)(id self, GLEvent *event);
在调用 handler 时,self 弱引用 self(第一个 self 和 第二 self)并不是同一个东西,
那么在 block 的作用域内,self 都是弱引用的了,只是访问属性 要用 getter 和 setter 方法了。
在使用GLPubSub时,如果类A通过block订阅一个通知后,如果不在dealloc方法移除,这个block将会一直存在;这样将会导致对象被释放,当有对应的通知时还是会执行block,那么就必须在dealloc方法中调用,该操作是否可以放在GLPubSub中进行统一处理呢?
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.