PureMVC(JS版)源码解析(四):Notifier类
上一篇博客中,我们解析了Observer(观察者)类,这一篇博客我们来讲Notifier(通知着)类。关于Notifier类,源码注释上有这么一段:
* @class puremvc.Notifier
* A Base Notifier implementation.
* {@link puremvc.MacroCommand MacroCommand},
* {@link puremvc.SimpleCommand SimpleCommand},
* {@link puremvc.Mediator Mediator} and
* {@link puremvc.Proxy Proxy}
* all have a need to send Notifications
* The Notifier interface provides a common method called #sendNotification that
* relieves implementation code of the necessity to actually construct
* Notifications.
通过这段注释我们可以看出,Notifier类是MacroCommand类、SimpleCommand类、Mediator类和Proxy类的基类,它通过sendNotification()方法用来发送消息。
那我们首先来看一下sendNotification()方法:
**
* Create and send a Notification.
*
* Keeps us from having to construct new Notification instances in our
* implementation code.
*
* @param {string} notificationName
* A notification name
* @param {Object} [body]
* The body of the notification
* @param {string} [type]
* The notification type
* @return {void}
*/
Notifier.prototype.sendNotification = function(notificationName, body, type)
{
var facade = this.getFacade();
if(facade)
{
facade.sendNotification(notificationName, body, type);
}
};
通过以上代码我们可以看出,Notifier对象发送消息实际上是调用facade对象的sendNotification()方法来发送的,包括三个参数,这三个参数可以实例化一个Notification对象。那这个facade对象是干嘛用的呢?暂时不去讲解,会在以后的博客中针对Facade进行单独讲解?(大家有兴趣的话,可以搜一下Facade设计模式)。我们可以先看一下getFacade()方法,通过这个方法名我们知道这是返回一个facade对象。
/**
* Retrieve the Multiton Facade instance
* @protected
* @return {puremvc.Facade}
*/
Notifier.prototype.getFacade = function()
{
if(this.multitonKey == null)
{
throw new Error(Notifier.MULTITON_MSG);
}; return Facade.getInstance(this.multitonKey);
};
Notifier.prototype.multitonKey = null;
Notifier.prototype.facade;
我们再回过头来看看Notifier类的构造函数:
function Notifier()
{
};
Notifier类的构造函数没有进行任何处理,但我们发现Notifier类有一个初始化方法initializeNotifier()方法:
Notifier.prototype.initializeNotifier = function(key)
{
this.multitonKey = String(key);
this.facade= this.getFacade();
};
这个方法主要用于为multitonkey属性和facade属性赋值。

PureMVC(JS版)源码解析(四):Notifier类的更多相关文章
- Mybatis源码解析(四) —— SqlSession是如何实现数据库操作的?
Mybatis源码解析(四) -- SqlSession是如何实现数据库操作的? 如果拿一次数据库请求操作做比喻,那么前面3篇文章就是在做请求准备,真正执行操作的是本篇文章要讲述的内容.正如标题一 ...
- Sentinel源码解析四(流控策略和流控效果)
引言 在分析Sentinel的上一篇文章中,我们知道了它是基于滑动窗口做的流量统计,那么在当我们能够根据流量统计算法拿到流量的实时数据后,下一步要做的事情自然就是基于这些数据做流控.在介绍Sentin ...
- Dubbo 源码解析四 —— 负载均衡LoadBalance
欢迎来我的 Star Followers 后期后继续更新Dubbo别的文章 Dubbo 源码分析系列之一环境搭建 Dubbo 入门之二 --- 项目结构解析 Dubbo 源码分析系列之三 -- 架构原 ...
- iOS即时通讯之CocoaAsyncSocket源码解析四
原文 前言: 本文为CocoaAsyncSocket源码系列中第二篇:Read篇,将重点涉及该框架是如何利用缓冲区对数据进行读取.以及各种情况下的数据包处理,其中还包括普通的.和基于TLS的不同读取操 ...
- React的React.createContext()源码解析(四)
一.产生context原因 从父组件直接传值到孙子组件,而不必一层一层的通过props进行传值,相比较以前的那种传值更加的方便.简介. 二.context的两种实现方式 1.老版本(React16.x ...
- Mybatis源码解析3——核心类SqlSessionFactory,看完我悟了
这是昨晚的武汉,晚上九点钟拍的,疫情又一次来袭,曾经熙熙攘攘的夜市也变得冷冷清清,但比前几周要好很多了.希望大家都能保护好自己,保护好身边的人,生活不可能像你想象的那么好,但也不会像你想象的那么糟. ...
- AOP源码解析:AspectJAwareAdvisorAutoProxyCreator类的介绍
AspectJAwareAdvisorAutoProxyCreator 的类图 上图中一些 类/接口 的介绍: AspectJAwareAdvisorAutoProxyCreator : 公开了Asp ...
- vuex 源码解析(四) mutation 详解
mutation是更改Vuex的store中的状态的唯一方法,mutation类似于事件注册,每个mutation都可以带两个参数,如下: state ;当前命名空间对应的state payload ...
- AFNetworking2.0源码解析<四>
结构 AFURLResponseSerialization负责解析网络返回数据,检查数据是否合法,把NSData数据转成相应的对象,内置的转换器有json,xml,plist,image,用户可以很方 ...
- Celery 源码解析四: 定时任务的实现
在系列中的第二篇我们已经看过了 Celery 中的执行引擎是如何执行任务的,并且在第三篇中也介绍了任务的对象,但是,目前我们看到的都是被动的任务执行,也就是说目前执行的任务都是第三方调用发送过来的.可 ...
随机推荐
- 修改.htaccess实现子目录绑定示例分享
<IfModule mod_rewrite.c>RewriteEngine On RewriteBase /# 把 www.jb51.net改为你要绑定的域名.# 如果是域名:Rewri ...
- 实现一个JavaScript模块化加载器
对任何程序,都存在一个规模的问题,起初我们使用函数来组织不同的模块,但是随着应用规模的不断变大,简单的重构函数并不能顺利的解决问题.尤其对JavaScript程序而言,模块化有助于解决我们在前端开发中 ...
- hdu 3018
欧拉回路的题: 主要利用的是并查集,为了节省时间,压缩了它的路径: 代码: #include<cstdio> #include<cstring> #define maxn 10 ...
- how to develop mobile web
http://blog.templatemonster.com/2010/05/11/how-make-mobile-website-6-easy-tips/ http://mobile.smashi ...
- Hard Life
poj3155:http://poj.org/problem?id=3155 题意:最大密度子图的模板题. 题解:直接看代码. /* 题意简述一个公司有n个人,给出了一些有冲突的人的对数(u,v),所 ...
- Android软件开发之发送短信与系统短信库解析
今天我和同学们讨论一下Android平台下如何调用系统方法发送短信.接收短信.系统的短信库相关的问题.进入正题,我们先使用Eclipse工具模拟给自己的模拟器发送一条短信.在Eclipse下打开DDM ...
- Linux之sed详解
转载:http://blog.chinaunix.net/u/22677/showart_1076318.html 1.简介 sed是非交互式的编辑器.它不会修改文件,除非使用shell重定向来保 ...
- (原创滴~)STL源码剖析读书总结1——GP和内存管理
读完侯捷先生的<STL源码剖析>,感觉真如他本人所说的"庖丁解牛,恢恢乎游刃有余",STL底层的实现一览无余,给人一种自己的C++水平又提升了一个level的幻觉,呵呵 ...
- replace empty char with new string,unsafe method和native implementation的性能比较
1: class Program 2: { 3: static void Main(string[] args) 4: { 5: string s = File.ReadAllText(@" ...
- parseSdkContent failed Could not initialize class android.graphics.Typeface
Deleting ".android" is temporarily fixing the problem with me as after sometime it begins ...