//
//  ACBlockJSBridgeBase.m
//  iOSJSBridgeDemo
//
//  Created by 罗坚(EX-LUOJIAN004) on 2018/5/21.
//  Copyright © 2018年 罗坚(EX-LUOJIAN004). All rights reserved.
//

#import "ACBaseBlockJSBridge.h"

@implementation ACBaseBlockJSBridge

- (id)init
{
    if ([super init]) {
        [self initHandles];
    }
    return self;
}

- (void)initHandles
{
    
}

- (void)registerHandler:(NSString *)handlerNameStr handler:(ACBridgeHandler)handler
{
    self.handlesDic[handlerNameStr] = [handler copy];
}

- (ACMessage *)callHandler:(NSString *)handlerNameStr withParam:(ACMessage *)msg
{
    ACBridgeHandler handle = self.handlesDic[handlerNameStr];
    if (handle) {
        return handle(self.webView, msg);
    }
    return msg;
}

#pragma mark - getter and setter

- (NSMutableDictionary *)handlesDic
{
    if (_handlesDic == nil) {
        _handlesDic = [[NSMutableDictionary alloc] init];
    }
    return _handlesDic;
}

@end
