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 中的执行引擎是如何执行任务的,并且在第三篇中也介绍了任务的对象,但是,目前我们看到的都是被动的任务执行,也就是说目前执行的任务都是第三方调用发送过来的.可 ...
随机推荐
- 【网络流24题】No.4 魔术球问题 (二分+最小路径覆盖)
[题意] 假设有 n 根柱子, 现要按下述规则在这 n 根柱子中依次放入编号为 1, 2, 3, ¼的球.( 1)每次只能在某根柱子的最上面放球.( 2)在同一根柱子中,任何 2 个相邻球的编号之和为 ...
- lubuntu安装maven
原文转自:jobar.iteye.com/blog/1776747 1 apt-cache search maven 获取所有可用的maven包 2 sudo apt-get install mave ...
- RTSP
相关博客: RTSP 很详细的英文文档 RTSP交互命令简介及过程参数描述 RTSP协议 http://blog.csdn.net/andyweike/article/details/621071 ...
- Android应用架构
Android开发生态圈的节奏非常之快.每周都会有新的工具诞生,类库的更新,博客的发表以及技术探讨.如果你外出度假一个月,当你回来的时候可能已经发布了新版本的Support Library或者Play ...
- 【Java基础01】Java InputStream的read方法
JDK关于InputStream中的read方法的描述: (1) read() : 从输入流中读取数据的下一个字节,返回0到255范围内的int字节值.如果因为已经到达流末尾而没有可用的字节,则返回 ...
- 在JNI中新开线程遇到问题
08-03 13:39:30.535 1663-20490/system_process E/RfidReaderService﹕ input RDID CARD ID g_data: ...
- 汉企C#面向对象——继承
public class Shengwu { private string _Name; public string Name { get { return _Name; } set { _Name ...
- 代码演示C#中string和StingBuilder内存中的区别
关于 string和StringBuilder的区别参考MSDN.本文用程序演示它们在内存中的区别,及其因此其行为不同. //Demo string memory model namespace C ...
- CH Round #45 能量释放
能量释放 CH Round #45 - alan有一些陷阱 III 题目描述 alan得到一块由个能量晶体构成的矿石,对于矿石中的每一个能量晶体,如果用化学物质刺激某一个能量晶体,就能使它释放能量. ...
- 动态规划(DP计数):HDU 5121 Just A Mistake
As we all know, Matt is an outstanding contestant in ACM-ICPC. Graph problems are his favorite.Once, ...