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 }
11 }
在B中的Mediator去接收ApplicationFacade.MESSAGE_FROM_A_RECEIVED,這個消息,得到通道傳過來的資料。
資料的流動是:A->A的puremvc中的通知->A,B 的pipes->B 的 puremvc 的通知->B。
參考:http://bbs.9ria.com/thread-101062-1-1.html