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 中的执行引擎是如何执行任务的,并且在第三篇中也介绍了任务的对象,但是,目前我们看到的都是被动的任务执行,也就是说目前执行的任务都是第三方调用发送过来的.可 ...
随机推荐
- jQuery获取屏幕的宽度
Javascript: 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.b ...
- Android 使用XmlSerializer生成xml文件
在Android开发中,我们时常要用到xml文件. xml作为一种数据载体,在数据传输中发挥着重要的作用,而且它可读性比较强. 下面给出在Android开发中使用XmlSerializer类生成一个简 ...
- 【UVA 10369】 Arctic Network (最小生成树)
[题意] 南极有n个科研站, 要把这些站用卫星或者无线电连接起来,使得任意两个都能直接或者间接相连.任意两个都有安装卫星设备的,都可以直接通过卫星通信,不管它们距离有多远. 而安装有无线电设备的两个站 ...
- 解决CAS单点登录出现PKIX path building failed的问题
在一次调试中,出现了这个错误: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderExceptio ...
- 李洪强iOS开发Swift篇—02_变量和常量
李洪强iOS开发Swift篇—02_变量和常量 一.语言的性能 (1)根据WWDC的展示 在进行复杂对象排序时Objective-C的性能是Python的2.8倍,Swift的性能是Python的3. ...
- 【Xamarin 挖墙脚系列:IOS 开发界面的3种方式】
原文:[Xamarin 挖墙脚系列:IOS 开发界面的3种方式] xcode6进行三种基本的界面布局的方法,分别是手写UI,xib和storyboard.手写UI是最早进行UI界面布局的方法,优点是灵 ...
- C# 读取网络txt文件 并写在本地txt文件中
public void WriteStream() { try { stirng ImagesPath = ImagesPath + "\\2013-09-27.txt"; Htt ...
- Oracle 单实例 2个service的问题
[oracle@PD admin]$ ps -ef | grep smon oracle 1917 1 0 Aug21 ? 00:33:51 ora_smon_podinndb oracle 2265 ...
- Android推送通知Notification
参考: 1.http://www.cnblogs.com/anrainie/archive/2012/03/07/2383941.html 总结: 代码:
- UITextView 动态高度计算(iOS7版)
NSDictionary *attrsDictionary = [NSDictionarydictionaryWithObject:[UIFontsystemFontOfSize:kCellConte ...