• 新人补钙系列教程之: 大型 webGame 开发系列之 pipes


    pipeswithchildern.png
    pipes utilities,也就是所谓的通道,为什么要使用通道呢?模块的结构都是一个单独的puremvc结构,模块和模块,shell和模块之间的通信 不能使用puremvc中的消息进行,因为消息是在一个puremvc中使用的,在多个puremvc中消息是不能跨越的。所以引进了pipes utility。在两个puremvc中需要进行数据交互的时候,需要建立两个puremvc之间的通道(pipes)。假如是模块A和模块B之间需要传递一个数据C,首先建立两个之间的pipe,在模块A的view中的A.mediator,发送一个puremvc的消息,如sendNotification( AFacade.SEND_MESSAGE_TO_B, C );模块A的view的A.JunctionMediator,接收AFacade.SEND_MESSAGE_TO_B这个消息,然后将这个消息发向A和B的通道
    1. override public function handleNotification( note:INotification ):void
    2.   {
    3.    
    4.    switch( note.getName() )
    5.    {       
    6.     case ApplicationFacade.SEND_MESSAGE_TO_B:
    7.      junction.sendMessage( PipeAwareModuleConstants.MODULE_TO_B_PIPE,
    8.            new Message( PipeAwareModuleConstants.MODULE_TO_B_MESSAGE,
    9.                null,
    10.                note.getBody() ));
    11.      break;    
    12.     // Let super handle the rest (ACCEPT_OUTPUT_PIPE, ACCEPT_INPUT_PIPE, SEND_TO_LOG)       
    13.     default:
    14.      super.handleNotification(note);     
    15.    } 
    16.   }
    复制代码
    同样在B的view的JunctionMediator中,会有接收他们之间通道的函数
    1. override public function handlePipeMessage( message:IPipeMessage ):void
    2.   {
    3.    switch ( Message(message).getType() )
    4.    {
    5.     case PipeAwareModuleConstants.MODULE_TO_B_PIPE:
    6.      sendNotification( ApplicationFacade.MESSAGE_FROM_A_RECEIVED, 
    7.           Message(message).getBody() );
    8.      break;
    9.    }
    10.   }
    复制代码
    在B中的Mediator去接收ApplicationFacade.MESSAGE_FROM_A_RECEIVED,这个消息,得到通道传过来的数据。

    数据的流动是:A->A的puremvc中的通知->A,B 的pipes->B 的 puremvc 的通知->B
  • 相关阅读:
    webpack-dev-server 源码
    2021前端会有什么新的变化
    父类 超类 基类 子类 派生类
    Java的权限修饰符(public,private,protected,默认friendly)
    class修饰符public、private、protected、static、abstract
    hash和签名 、证书
    前端加密解密crypto
    appid app_key app_secret
    sdk开发 、sdk与插件的区别
    CF76C
  • 原文地址:https://www.cnblogs.com/keng333/p/2299761.html
Copyright © 2020-2023  润新知