zoukankan      html  css  js  c++  java
  • WeexSDK之注册Handlers

    先看代码:

    + (void)_registerDefaultHandlers
    {
        [self registerHandler:[WXResourceRequestHandlerDefaultImpl new] withProtocol:@protocol(WXResourceRequestHandler)];
        [self registerHandler:[WXNavigationDefaultImpl new] withProtocol:@protocol(WXNavigationProtocol)];
        [self registerHandler:[WXURLRewriteDefaultImpl new] withProtocol:@protocol(WXURLRewriteProtocol)];
        
    }

    WXSDKEngine中默认注册了3个Handler。

    + (void)registerHandler:(id)handler withProtocol:(Protocol *)protocol
    {
        WXAssert(handler && protocol, @"Fail to register the handler, please check if the parameters are correct !");
        
        [WXHandlerFactory registerHandler:handler withProtocol:protocol];
    }

    WXSDKEngine会继续调用WXHandlerFactory的registerHandler:withProtocol:方法。

    @interface WXHandlerFactory : NSObject
    
    @property (nonatomic, strong) WXThreadSafeMutableDictionary *handlers;
    
    + (void)registerHandler:(id)handler withProtocol:(Protocol *)protocol;
    
    + (id)handlerForProtocol:(Protocol *)protocol;
    
    + (NSDictionary *)handlerConfigs;
    
    @end

    WXHandlerFactory也是一个单例,里面有一个线程安全的字典handlers,用来保存实例和Protocol名的映射表。

     

  • 相关阅读:
    gulp备忘
    好文收藏
    妙味H5交互篇备忘
    [CSS3备忘] transform animation 等
    css选择器总结
    flexbox备忘
    函数
    继承2
    在 Swift 中实现单例方法
    浅谈 Swift 中的 Optionals
  • 原文地址:https://www.cnblogs.com/LeeGof/p/9019112.html
Copyright © 2011-2022 走看看